Ejemplo n.º 1
0
def topic_context(topic):
    """
    Given a topic node, create all context related to showing that topic
    in a template.
    """
    videos    = topic_tools.get_videos(topic)
    exercises = topic_tools.get_exercises(topic)
    topics    = topic_tools.get_live_topics(topic)

    # Get video counts if they'll be used, on-demand only.
    #
    # Check in this order so that the initial counts are always updated
    if video_counts_need_update() or not 'nvideos_local' in topic:
        (topic,_,_) = get_video_counts(topic=topic, videos_path=settings.CONTENT_ROOT)

    my_topics = [dict((k, t[k]) for k in ('title', 'path', 'nvideos_local', 'nvideos_known')) for t in topics]

    context = {
        "topic": topic,
        "title": topic["title"],
        "description": re.sub(r'<[^>]*?>', '', topic["description"] or ""),
        "videos": videos,
        "exercises": exercises,
        "topics": my_topics,
        "backup_vids_available": bool(settings.BACKUP_VIDEO_SOURCE),
    }
    return context
Ejemplo n.º 2
0
 def recount_videos_and_invalidate_parents(node, force=False):
     """
     Call get_video_counts (if necessary); if a change has been detected,
     then check parents to see if their counts should be invalidated.
     """
     do_it = force
     do_it = do_it or "nvideos_local" not in node
     do_it = do_it or any(["nvideos_local" not in child for child in node.get("children", [])])
     if do_it:
         logging.debug("Adding video counts to topic (and all descendants) %s" % node["path"])
         changed = get_video_counts(topic=node, force=force)
         if changed and node.get("parent") and "nvideos_local" in node["parent"]:
             strip_counts_from_ancestors(node)
     return node
Ejemplo n.º 3
0
import json
import os

import settings
from shared import topic_tools
from shared.videos import get_video_urls, get_video_counts


TOPICS          = topic_tools.get_topic_tree()
NODE_CACHE      = topic_tools.get_node_cache()
ID2SLUG_MAP     = topic_tools.get_id2slug_map()

# Add initial video counts
get_video_counts(topic=TOPICS, videos_path=settings.CONTENT_ROOT)

# Compute video URLs.  Must use videos from topics, as the NODE_CACHE doesn't contain all video objects. :-/
for video in topic_tools.get_topic_videos(path="/"):
    video["available"] = video["on_disk"] or bool(settings.BACKUP_VIDEO_SOURCE)
    (video["stream_url"], video["thumbnail_url"], video["subtitles_url"]) = get_video_urls(video["youtube_id"], "mp4", video["on_disk"])