translation app worked on
This commit is contained in:
parent
02ed3d75f8
commit
ec225c8a4c
|
@ -21,11 +21,18 @@ def fetchJson(request):
|
|||
else:
|
||||
return HttpResponse("{'error': True}", mimetype="application/javascript")
|
||||
|
||||
def translate(request):
|
||||
return render_to_response("translate.html", {'padma_url': PADMA_URL})
|
||||
|
||||
def fetchSrt(request):
|
||||
if request.GET['id']:
|
||||
padmaId = request.GET['id']
|
||||
track = request.GET['track'] or 'transcript'
|
||||
if 'track' in request.GET:
|
||||
track = request.GET['track']
|
||||
else:
|
||||
track = 'transcripts'
|
||||
url = "%s/%s/export/%s.srt" % (PADMA_URL, padmaId, track,)
|
||||
print url
|
||||
srt = getHtmlFromUrl(url)
|
||||
return HttpResponse(srt)
|
||||
else:
|
||||
|
|
|
@ -22,9 +22,9 @@ INTERNAL_IPS = ('127.0.0.1',)
|
|||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
DATABASE_ENGINE = '' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
||||
DATABASE_NAME = '' # Or path to database file if using sqlite3.
|
||||
DATABASE_USER = '' # Not used with sqlite3.
|
||||
DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
||||
DATABASE_NAME = 'translate' # Or path to database file if using sqlite3.
|
||||
DATABASE_USER = 'root' # Not used with sqlite3.
|
||||
DATABASE_PASSWORD = '' # Not used with sqlite3.
|
||||
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
|
||||
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
|
||||
|
@ -98,4 +98,5 @@ INSTALLED_APPS = (
|
|||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.sites',
|
||||
'translate',
|
||||
)
|
||||
|
|
24
static/js/liveFuncs.js
Normal file
24
static/js/liveFuncs.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
$('.removeClip').live("click", function() {
|
||||
$(this).parents('.padmaClip').slideUp("slow", function() {
|
||||
$(this).remove();
|
||||
});
|
||||
});
|
||||
|
||||
$('.clipView').live("click", function() {
|
||||
var layer = $(this).parents('.padmaClip').data("layer");
|
||||
var html = tmpl("tmpl_playerWindow", {'layer': layer});
|
||||
if (typeof playerWindow != 'undefined') {
|
||||
playerWindow.close();
|
||||
}
|
||||
playerWindow = window.open();
|
||||
playerWindow.document.write(html);
|
||||
});
|
||||
/*
|
||||
$('.clipDownload').live("click", function() {
|
||||
var layer = $(this).parents('.padmaClip').data("layer");
|
||||
console.log(layer);
|
||||
var downloadUrl = layer.downloadUrl;
|
||||
window.open(downloadUrl);
|
||||
});
|
||||
*/
|
||||
|
|
@ -63,7 +63,8 @@ get html of template with tmpl("foo", json)
|
|||
callback(srt);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
(function($) {
|
||||
jQuery.fn.padma = function(id, options) {
|
||||
var that = this;
|
||||
|
|
|
@ -44,7 +44,7 @@ padmaLayer.prototype.addToClipBin = function() {
|
|||
var html = tmpl("tmpl_clip", {'layer': that});
|
||||
this.clipJq = $('<div />').addClass('padmaClip').attr("id", "clip" + that.id).data("layer", that).html(html);
|
||||
var height = Math.ceil(parseInt(that.padmaVideo.meta.stream_width) / that.padmaVideo.meta.aspectratio) + 16;
|
||||
console.log(height);
|
||||
// console.log(height);
|
||||
$('#playBin').append(that.clipJq);
|
||||
this.clipJq.css({'height': height + "px"});
|
||||
}
|
||||
|
|
81
static/js/translate.js
Normal file
81
static/js/translate.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
$(document).ready(function() {
|
||||
$('#fetchVideoData').click(function() {
|
||||
var padmaId = $('#padmaId').val();
|
||||
var srtUrl = "/fetchSrt?id=" + padmaId + "&track=transcripts";
|
||||
// console.log(srtUrl);
|
||||
var videoJs = PADMA_BASE_URL + "/" + padmaId + "/video.js";
|
||||
$.getScript(videoJs, function() {
|
||||
// console.log(video);
|
||||
var thisVideo = video;
|
||||
var videoSrc = video.urls['320'];
|
||||
$('#video').attr("src", videoSrc);
|
||||
document.getElementById("video").load(); //FIXME
|
||||
// $('#srt').html(rawSrt);
|
||||
$('#srt').srt({
|
||||
'url': srtUrl,
|
||||
'id': 'video',
|
||||
'showSubtitle': function(sub, elem) {
|
||||
var html = sub.i + " - " + sub.o;
|
||||
html += "<br />";
|
||||
html += sub.t;
|
||||
elem.html(html);
|
||||
},
|
||||
'subtitlesLoaded': function(subtitles) {
|
||||
// console.log(subtitles);
|
||||
var str = '';
|
||||
var counter = 1;
|
||||
for (var s in subtitles) {
|
||||
if (subtitles.hasOwnProperty(s)) {
|
||||
var thisSubtitle = subtitles[s];
|
||||
var inTime = thisSubtitle.i;
|
||||
var outTime = thisSubtitle.o;
|
||||
str += "" + counter + "\n" + inTime + " --> " + outTime + "\n\n"
|
||||
counter++;
|
||||
// str += inTime + "\n\n" + outTime + "\n\n";
|
||||
}
|
||||
}
|
||||
$('#newSrt').val(str);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#saveSrt').click(function() {
|
||||
var txt = $('#newSrt').val();
|
||||
var language = $('#language').val();
|
||||
$.post("saveSrt", {
|
||||
'txt': txt,
|
||||
'language': language,
|
||||
'padmaId': $('#padmaId').val()
|
||||
}, function(response) {
|
||||
alert(response);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function s2npt(s) {
|
||||
return ms2npt(s * 1000);
|
||||
}
|
||||
|
||||
function ms2npt(pos) {
|
||||
var h = Math.floor(pos / 3600000);
|
||||
var m = Math.floor(pos % 3600000 / 60000);
|
||||
var s = Math.floor(pos % 60000 / 1000);
|
||||
var ms = pos % 1000;
|
||||
return h.toString().pad('0', 2) + ':' + m.toString().pad('0', 2) + ':' + s.toString().pad('0', 2) + '.' + ms.toString().pad('0', 3);
|
||||
// return strpad(h.toString(), '0', 2, 'left') + ':' + strpad(m.toString(), '0', 2, 'left') + ':' + strpad(s.toString(), '0', 2, 'left') + '.' + strpad(ms.toString(), '0', 3, 'left');
|
||||
}
|
||||
|
||||
String.prototype.pad = function(pad, len, dir) {
|
||||
if (typeof(dir) == 'undefined')
|
||||
dir = 'left';
|
||||
var str = this;
|
||||
while (str.length < len) {
|
||||
if (dir == 'left')
|
||||
str = pad + str;
|
||||
else if (dir == 'right')
|
||||
str = str + pad;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
0
translate/__init__.py
Normal file
0
translate/__init__.py
Normal file
8
translate/models.py
Normal file
8
translate/models.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from django.db import models
|
||||
|
||||
class Srt(models.Model):
|
||||
language = models.CharField(max_length=5)
|
||||
txt = models.TextField()
|
||||
padmaId = models.CharField(max_length=20)
|
||||
|
||||
# Create your models here.
|
23
translate/tests.py
Normal file
23
translate/tests.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
"""
|
||||
This file demonstrates two different styles of tests (one doctest and one
|
||||
unittest). These will both pass when you run "manage.py test".
|
||||
|
||||
Replace these with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.failUnlessEqual(1 + 1, 2)
|
||||
|
||||
__test__ = {"doctest": """
|
||||
Another way to test that 1 + 1 is equal to 2.
|
||||
|
||||
>>> 1 + 1 == 2
|
||||
True
|
||||
"""}
|
||||
|
11
translate/views.py
Normal file
11
translate/views.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Create your views here.
|
||||
from models import Srt
|
||||
from django.http import HttpResponse
|
||||
|
||||
def saveSrt(request):
|
||||
txt = request.POST['txt']
|
||||
lang = request.POST['language']
|
||||
padmaId = request.POST['padmaId']
|
||||
srt = Srt(txt=txt, language=lang, padmaId=padmaId)
|
||||
srt.save()
|
||||
return HttpResponse("saved")
|
3
urls.py
3
urls.py
|
@ -10,6 +10,9 @@ urlpatterns = patterns('',
|
|||
# (r'^padmaApi/', include('padmaApi.foo.urls')),
|
||||
(r'jPadma/', 'lists.views.fetchJson'),
|
||||
(r'list/', 'lists.views.listDetail'),
|
||||
(r'^fetchSrt', 'lists.views.fetchSrt'),
|
||||
(r'^translate', 'lists.views.translate'),
|
||||
(r'^saveSrt', 'translate.views.saveSrt'),
|
||||
(r'^$', 'lists.views.index'),
|
||||
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
|
||||
# to INSTALLED_APPS to enable admin documentation:
|
||||
|
|
Loading…
Reference in New Issue
Block a user