Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.16b3 #5031

Closed
1 change: 0 additions & 1 deletion kalite/distributed/features/steps/learn_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def impl(context):
def impl(context):
context.browser.get(build_url(context, reverse("learn") + context.video.path))
wait_for_video_player_ready(context)
context.browser.execute_script('$("video").trigger("loadedmetadata");')


@then(u'the video player is aware of the subtitles')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from kalite.contentload import settings as content_settings
from kalite.i18n.base import lcode_to_django_lang, get_po_filepath, get_locale_path, \
download_content_pack, update_jsi18n_file, get_srt_path as get_subtitle_path, \
download_content_pack, update_jsi18n_file, get_subtitle_file_path as get_subtitle_path, \
extract_content_db
from kalite.updates.management.commands.classes import UpdatesStaticCommand

Expand Down
Binary file not shown.
21 changes: 19 additions & 2 deletions kalite/distributed/static/js/distributed/video/views.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
var _ = require("underscore");
var BaseView = require("base/baseview");
var Handlebars = require("base/handlebars");

var vtt = require("videojs-vtt.js"); // Must precede video.js
global.WebVTT = vtt.WebVTT; // Required to be in the global scope by video.js

var _V_ = require("video.js");
global.videojs = _V_;
require("../../../css/distributed/video-js-override.less");
Expand All @@ -20,6 +24,12 @@ var VideoPlayerView = ContentBaseView.extend({

template: require("./hbtemplates/video-player.handlebars"),

initialize: function(options) {
ContentBaseView.prototype.initialize.call(this, options);
this.flash_only = options.flash_only;
},


render: function() {

_.bindAll(this, "on_resize");
Expand Down Expand Up @@ -48,8 +58,6 @@ var VideoPlayerView = ContentBaseView.extend({
that.initialize_player(width, height);

});

window._kalite_debug.video_player_initialized = true;
},

initialize_player: function(width, height) {
Expand All @@ -60,6 +68,8 @@ var VideoPlayerView = ContentBaseView.extend({
}
this._loaded = true;

var self = this;

var player_id = this.$(".video-js").attr("id");

if (player_id) {
Expand All @@ -68,12 +78,19 @@ var VideoPlayerView = ContentBaseView.extend({
"playbackRates": [0.5, 1, 1.25, 1.5, 2],
"html5": {
nativeTextTracks: false
},
"techOrder": this.flash_only ? ["flash"] : ["html5", "flash"],
flash: {
swf: window.sessionModel.get("STATIC_URL") + "js/distributed/video/video-js.swf"
}
};
if( this.data_model.get("content_urls").thumbnail ) {
video_player_options['poster'] = this.data_model.get("content_urls").thumbnail;
}
this.player = window.player = _V_(player_id, video_player_options);
this.player.ready(function() {
window._kalite_debug.video_player_initialized = true;
});
this.initialize_listeners();
} else {
console.warn("Warning: Could not find Video.JS player!");
Expand Down
10 changes: 5 additions & 5 deletions kalite/i18n/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def get_langcode_map(lang_name=None, force=False):
return LANG2CODE_MAP.get(lang_name) if lang_name else LANG2CODE_MAP


def get_srt_url(youtube_id, code):
return settings.STATIC_URL + "srt/%s/subtitles/%s.srt" % (code, youtube_id)
def get_subtitle_url(youtube_id, code):
return settings.STATIC_URL + "srt/%s/subtitles/%s.vtt" % (code, youtube_id)


def get_srt_path(lang_code=None, youtube_id=None):
def get_subtitle_file_path(lang_code=None, youtube_id=None):
"""Both central and distributed servers must make these available
at a web-accessible location.

Expand All @@ -89,7 +89,7 @@ def get_srt_path(lang_code=None, youtube_id=None):
if lang_code:
srt_path = os.path.join(srt_path, lcode_to_django_dir(lang_code), "subtitles")
if youtube_id:
srt_path = os.path.join(srt_path, youtube_id + ".srt")
srt_path = os.path.join(srt_path, youtube_id + ".vtt")

return srt_path

Expand Down Expand Up @@ -322,7 +322,7 @@ def select_best_available_language(target_code, available_codes=None):

def delete_language(lang_code):

langpack_resource_paths = [ get_localized_exercise_dirpath(lang_code), get_srt_path(lang_code), get_locale_path(lang_code) ]
langpack_resource_paths = [ get_localized_exercise_dirpath(lang_code), get_subtitle_file_path(lang_code), get_locale_path(lang_code) ]

for langpack_resource_path in langpack_resource_paths:
try:
Expand Down
6 changes: 3 additions & 3 deletions kalite/testing/base_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from django.db.transaction import TransactionManagementError
from peewee import Using

from kalite.i18n.base import get_srt_path, get_srt_url
from kalite.i18n.base import get_subtitle_file_path, get_subtitle_url
from kalite.testing.base import KALiteTestCase
from kalite.testing.behave_helpers import login_as_admin, login_as_coach, logout, login_as_learner
from kalite.topic_tools.content_models import Item, set_database, annotate_content_models, create, get, \
Expand Down Expand Up @@ -270,7 +270,7 @@ def _make_video(context):
"slug": "video_with_subtitles",
"path": "khan/video_with_subtitles",
"extra_fields": {
"subtitle_urls": [{"url": get_srt_url(youtube_id=youtube_id, code=lang_code),
"subtitle_urls": [{"url": get_subtitle_url(youtube_id=youtube_id, code=lang_code),
"code": lang_code,
"name": "English"}],
"content_urls": {"stream": "/foo", "stream_type": "video/mp4"},
Expand All @@ -282,7 +282,7 @@ def _make_video(context):
delete_instances(ids=[item_dict["id"]])
context.video = create(item_dict)

subtitle_path = get_srt_path(lang_code=lang_code, youtube_id=youtube_id)
subtitle_path = get_subtitle_file_path(lang_code=lang_code, youtube_id=youtube_id)
with open(subtitle_path, "w") as f:
f.write("foo")
context._subtitle_file_path = subtitle_path
Expand Down
4 changes: 4 additions & 0 deletions kalite/testing/behave_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ def __init__(self):

context_wm = ContextWithMixin()

context_wm.browser_wait_for_js_object_exists("$")
context_wm.browser_wait_for_js_object_exists('$("video")')
context.browser.execute_script('$("video").trigger("loadedmetadata");')

try:
context_wm.browser_wait_for_js_condition("window._kalite_debug.video_player_initialized",
max_wait_time=wait_time)
Expand Down
6 changes: 3 additions & 3 deletions kalite/topic_tools/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.conf import settings as django_settings

from kalite.i18n.base import get_srt_path, get_language_name
from kalite.i18n.base import get_subtitle_file_path, get_language_name
from kalite.updates.videos import get_local_video_size


Expand Down Expand Up @@ -36,8 +36,8 @@ def update_content_availability(content_list, language="en", channel="khan"):

subtitle_langs = {}

if os.path.exists(get_srt_path()):
for (dirpath, dirnames, filenames) in os.walk(get_srt_path()):
if os.path.exists(get_subtitle_file_path()):
for (dirpath, dirnames, filenames) in os.walk(get_subtitle_file_path()):
# Only both looking at files that are inside a 'subtitles' directory
if os.path.basename(dirpath) == "subtitles":
lc = os.path.basename(os.path.dirname(dirpath))
Expand Down
26 changes: 21 additions & 5 deletions kalite/topic_tools/content_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
All functions return the model data as a dictionary, in order to prevent external functions from having to know
implementation details about the model class used in this module.
"""
import json

import itertools
import json
import os

from peewee import Model, SqliteDatabase, CharField, TextField, BooleanField, ForeignKeyField, PrimaryKeyField, Using,\
DoesNotExist, fn, IntegerField, OperationalError, FloatField
Expand Down Expand Up @@ -395,13 +395,16 @@ def get_topic_contents(kinds=None, topic_id=None, **kwargs):


@set_database
def get_download_youtube_ids(paths=None, **kwargs):
def get_download_youtube_ids(paths=None, downloaded=False, **kwargs):
"""
Convenience function for taking a list of content ids and returning
all associated youtube_ids for downloads, regardless of whether the input
paths are paths for content nodes or topic nodes

:param paths: A list of paths to nodes - used to ensure uniqueness.
:return: A unique list of youtube_ids as strings.
:param downloaded: If False, returns videos that have not been downloaded. If True, returns videos that *have*
been downloaded.
:return: A dictionary mapping youtube_ids to video titles.
"""
if paths:
youtube_ids = dict()
Expand All @@ -410,7 +413,20 @@ def get_download_youtube_ids(paths=None, **kwargs):

youtube_ids.update(dict([item for item in Item.select(Item.youtube_id, Item.title).where(selector).tuples() if item[0]]))

return youtube_ids
if downloaded:
return {k: v for (k, v) in youtube_ids.iteritems() if _video_downloaded(k)}
else:
return {k: v for (k, v) in youtube_ids.iteritems() if not _video_downloaded(k)}


def _video_downloaded(youtube_id):
"""
Checks whether the given video file has been downloaded already.

:param youtube_id: The youtube id, a string
:return: True or False
"""
return os.path.isfile(os.path.join(settings.CONTENT_ROOT, "{}.mp4".format(youtube_id)))


def get_video_from_youtube_id(youtube_id):
Expand Down
4 changes: 2 additions & 2 deletions kalite/updates/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def start_video_download(request):

lang = json.loads(request.body or "{}").get("lang", "en")

youtube_ids = get_download_youtube_ids(paths, language=lang)
youtube_ids = get_download_youtube_ids(paths, language=lang, downloaded=False)

queue = VideoQueue()

Expand All @@ -150,7 +150,7 @@ def delete_videos(request):

lang = json.loads(request.body or "{}").get("lang", "en")

youtube_ids = get_download_youtube_ids(paths, language=lang)
youtube_ids = get_download_youtube_ids(paths, language=lang, downloaded=True)

num_deleted = 0

Expand Down
1 change: 0 additions & 1 deletion kalitectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,6 @@ def diagnose():
diag("content root", settings.CONTENT_ROOT)
diag("content size", filesizeformat(get_size(settings.CONTENT_ROOT)))
diag("user database", settings.DATABASES['default']['NAME'])
diag("assessment database", settings.DATABASES['assessment_items']['NAME'])
try:
from securesync.models import Device
device = Device.get_own_device()
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"underscore": "~1.8.3",
"url": "^0.10.3",
"video.js": "^5.7.1",
"videojs-vtt.js": "^0.12.1",
"watchify": "^3.3.1"
}
}