當前位置: 首頁>>代碼示例>>Python>>正文


Python Playlist.all方法代碼示例

本文整理匯總了Python中models.Playlist.all方法的典型用法代碼示例。如果您正苦於以下問題:Python Playlist.all方法的具體用法?Python Playlist.all怎麽用?Python Playlist.all使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Playlist的用法示例。


在下文中一共展示了Playlist.all方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: playlist_title_dicts

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
def playlist_title_dicts():
    return map(lambda playlist: {
        "title": playlist.title,
        "key": str(playlist.key()),
        "ka_url": playlist.relative_url, # remove once js clients update
        "url": playlist.relative_url
    }, Playlist.all())
開發者ID:KhanWorld,項目名稱:KhanAcademy,代碼行數:9,代碼來源:autocomplete.py

示例2: playlist_content_html

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
def playlist_content_html():
    """" Returns the HTML for the structure of the playlists as they will be
    populated ont he homepage. Does not actually contain the list of video
    names as those are filled in later asynchronously via the cache.
    
    """
    
    # No cache found -- regenerate HTML
    smart_history = getSmartHistoryContent()

    dict_playlists_by_title = {}
    all_playlists = []

    for playlist in Playlist.all():
        if playlist.title in topics_list:
            dict_playlists_by_title[playlist.title] = playlist

    for topic in topics_list:
        if topic in dict_playlists_by_title:
            playlist = dict_playlists_by_title[topic]
            video_count = playlist.get_video_count() 
            # 3 columns, 18px per row. This must be updated in conjunction
            # with code in homepage.js
            height = math.ceil(video_count / 3) * 18

            playlist_data = {
                             'title': topic,
                             'topic': topic,
                             'playlist': playlist,
                             'list_height': height,
                             'next': None,
                             }

            all_playlists.append(playlist_data)

    playlist_data_prev = None
    for playlist_data in all_playlists:
        if playlist_data_prev:
            playlist_data_prev['next'] = playlist_data
        playlist_data_prev = playlist_data

    timestamp = time.time()
    template_values = {
        'App' : App,
        'all_playlists': all_playlists,
        'smart_history': smart_history,
        
        # convert timestamp to a nice integer for the JS
        'timestamp': int(round(timestamp * 1000)),
        }

    html = shared_jinja.get().render_template("library_playlist_template.html",
                                              **template_values)
    Setting.cached_playlist_content_date(
            str(datetime.datetime.fromtimestamp(timestamp)))
    return html
開發者ID:KhanWorld,項目名稱:KhanAcademy,代碼行數:58,代碼來源:library.py

示例3: load_videos

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
def load_videos(version, title=None):
    root = Topic.get_by_id("root", version)
                    
    if title is None:
        playlist = Playlist.all().order('title').get()
    else:
        playlist = Playlist.all().filter('title = ', title).get()
    
    title = playlist.title
    
    nextplaylist = Playlist.all().filter('title >', title).order('title').get()
    if nextplaylist:
        next_title = nextplaylist.title

    playlists = [playlist]
    # playlists = Playlist.all().order('title').fetch(100000)
    for i, p in enumerate(playlists):
        videos = p.get_videos()
        content_keys = [v.key() for v in videos]
        added = 0
        for i, v in enumerate(videos):
            for e in v.related_exercises():
                if e.key() not in content_keys:
                    content_keys.insert(i + added, e.key())
                    added += 1

        topic = Topic.insert(title=p.title,
                     parent=root,
                     description=p.description,
                     tags=p.tags,
                     child_keys=content_keys)
    
    logging.info("loading " + title)
    
    if nextplaylist:
        deferred.defer(load_videos, version, next_title)
    else:
        deferred.defer(hide_topics, version)
開發者ID:di445,項目名稱:server,代碼行數:40,代碼來源:topics.py

示例4: get_playlists

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
def get_playlists():
    playlists = []   
    for playlist_title in all_topics_list:            
        query = Playlist.all()
        query.filter('title =', playlist_title)
        playlist = query.get()
        playlist_dict = {'youtube_id':  playlist.youtube_id,
                         'youtube_url': playlist.url,
                         'title': playlist.title, 
                         'description': playlist.description,
                         'api_url': "http://www.khanacademy.org/api/playlistvideos?playlist=%s" % (urllib.quote_plus(playlist_title)),
                        } 
        playlists.append(playlist_dict) 
    return json.dumps(playlists, indent=4)
開發者ID:adamwulf,項目名稱:old-khan,代碼行數:16,代碼來源:api.py

示例5: get

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
    def get(self):
        playlist_title = "SAT Preparation"
        query = Playlist.all()
        query.filter('title =', playlist_title)
        playlist = query.get()
        query = VideoPlaylist.all()
        query.filter('playlist =', playlist)
        query.filter('live_association = ', True) #need to change this to true once I'm done with all of my hacks
        query.order('video_position')
        playlist_videos = query.fetch(500)

        template_values = {
                'videos': playlist_videos,
        }

        self.render_jinja2_template('sat.html', template_values)
開發者ID:KhanWorld,項目名稱:KhanAcademy,代碼行數:18,代碼來源:main.py

示例6: getalltracks

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
def getalltracks():
    playlists = Playlist.all()

    response = {}

    for playlist in playlists:
        pl = {}
        tracks = {}
        i = 1
        for track in playlist.tracks:
            trackobj = Track.get(track)
            tracks[i] = {'url':trackobj.url, 'type':'sc'} #FIXME 'sc' for now, change to track.type
            i += 1
        pl['tracks'] = tracks
        response[playlist.name] = pl

    return jsonify(response)
開發者ID:martingms,項目名稱:cloudlist,代碼行數:19,代碼來源:views.py

示例7: copyTopicsToPlaylist

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
    def copyTopicsToPlaylist(self):
        topic_list = Topic.get_content_topics()

        for topic in topic_list:
            playlist = Playlist.all().filter("title =", topic.standalone_title).get()
            if playlist:
                logging.info("Copying topic " + topic.standalone_title + " to playlist.")
                child_keys = topic.child_keys
                vps = VideoPlaylist.all().filter("playlist =", playlist).order("video_position").fetch(10000)

                playlist_keys = []
                for vp in vps:
                    try:
                        playlist_keys.append(vp.video.key())
                    except db.ReferencePropertyResolveError:
                        logging.info("Found reference to missing video in VideoPlaylist!")

                topic_keys = [key for key in topic.child_keys if key.kind() == "Video"]

                if playlist_keys == topic_keys:
                    logging.info("Child keys identical. No changes will be made.")
                else:
#                    logging.info("PLAYLIST: " + repr([str(key) for key in playlist_keys]))
#                    logging.info("TOPIC:    " + repr([str(key) for key in topic_keys]))

                    logging.info("Deleting old VideoPlaylists...")
                    db.delete(vps)

                    vps = []
                    for i, child_key in enumerate(topic.child_keys):
                        if child_key.kind() == "Video":
                            vps.append(VideoPlaylist(
                                video=child_key,
                                playlist=playlist,
                                video_position=i,
                                live_association = True
                                ))

                    logging.info("Creating new VideoPlaylists...")
                    db.put(vps)
            else:
                logging.info("Playlist matching topic " + topic.standalone_title + " not found.")
開發者ID:johnfelipe,項目名稱:server,代碼行數:44,代碼來源:youtube_sync.py

示例8: get_playlist_videos

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
def get_playlist_videos(playlist_title):
    query = Playlist.all()
    query.filter('title =', playlist_title)
    playlist = query.get()
    query = VideoPlaylist.all()
    query.filter('playlist =', playlist)
    query.filter('live_association = ', True)
    query.order('video_position')
    videos = []
    for pv in query.fetch(500):
        v = pv.video
        video_dict = {'youtube_id':  v.youtube_id,
                      'youtube_url': v.url,
                      'title': v.title, 
                      'description': v.description,
                      'keywords': v.keywords,                         
                      'readable_id': v.readable_id,
                      'ka_url': "http://www.khanacademy.org/video/%s?playlist=%s" % (v.readable_id, urllib.quote_plus(playlist_title)),
                      'video_position': pv.video_position,
                      'views': v.views,
                     }                         
        videos.append(video_dict)                        
    return json.dumps(videos, indent=4)
開發者ID:adamwulf,項目名稱:old-khan,代碼行數:25,代碼來源:api.py

示例9: playlist_title_dicts

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
def playlist_title_dicts():
    return map(lambda playlist: {"title": playlist.title, "url": "/#%s" % playlist.title}, Playlist.all())
開發者ID:adamwulf,項目名稱:old-khan,代碼行數:4,代碼來源:autocomplete.py

示例10: updateVideoAndPlaylistData

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
    def updateVideoAndPlaylistData(self):
        yt_service = gdata.youtube.service.YouTubeService()

        # Now that we run these queries from the App Engine servers, we need to 
        # explicitly specify our developer_key to avoid being lumped together w/ rest of GAE and
        # throttled by YouTube's "Too many request" quota
        yt_service.developer_key = "AI39si6ctKTnSR_Vx7o7GpkpeSZAKa6xjbZz6WySzTvKVYRDAO7NHBVwofphk82oP-OSUwIZd0pOJyNuWK8bbOlqzJc9OFozrQ"
        yt_service.client_id = "n/a"

        video_youtube_id_dict = Video.get_dict(Video.all(), lambda video: video.youtube_id)
        video_playlist_key_dict = VideoPlaylist.get_key_dict(VideoPlaylist.all())

        association_generation = int(Setting.last_youtube_sync_generation_start())

        logging.info("Fetching playlists")
        playlist_start_index = 1
        playlist_feed = yt_service.GetYouTubePlaylistFeed(uri='http://gdata.youtube.com/feeds/api/users/KhanAcademyHebrew/playlists?start-index=%s&max-results=50' % playlist_start_index)

        while len(playlist_feed.entry) > 0:

            for playlist in playlist_feed.entry:
                logging.info("Playlist: %s", playlist.id.text)

                playlist_id = playlist.id.text.replace('http://gdata.youtube.com/feeds/api/users/KhanAcademyHebrew/playlists/', '')
                playlist_uri = playlist.id.text.replace('users/KhanAcademyHebrew/', '')
                query = Playlist.all()
                query.filter('youtube_id =', playlist_id)
                playlist_data = query.get()
                if not playlist_data:
                    playlist_data = Playlist(youtube_id=playlist_id)
                    logging.info('Creating Playlist: %s', playlist.title.text)
                playlist_data.url = playlist_uri
                playlist_data.title = playlist.title.text.decode("utf-8")
                playlist_data.description = playlist.description.text.decode("utf-8")

                playlist_data.tags = []
                for category in playlist.category:
                    if "tags.cat" in category.scheme:
                        playlist_data.tags.append(category.term)

                playlist_data.put()
                
                for i in range(0, 10):
                    start_index = i * 50 + 1
                    video_feed = yt_service.GetYouTubePlaylistVideoFeed(uri=playlist_uri + '?start-index=' + str(start_index) + '&max-results=50')
                    video_data_list = []

                    if len(video_feed.entry) <= 0:
                        # No more videos in playlist
                        break

                    for video in video_feed.entry:
                        if not video.media.player:
                            logging.warning("Could not parse video - skipping... (%s, %s)", video, video.media)
                            continue

                        video_id = cgi.parse_qs(urlparse(video.media.player.url).query)['v'][0].decode('utf-8')

                        video_data = None
                        if video_youtube_id_dict.has_key(video_id):
                            video_data = video_youtube_id_dict[video_id]
                            logging.info('Found Video: %s (%s)', video.media.title.text.decode('utf-8'), video_id)
                        
                        if not video_data:
                            video_data = Video(youtube_id=video_id)
                            logging.info('Creating Video: %s (%s)', video.media.title.text.decode('utf-8'), video_id)

                        video_data.title = video.media.title.text.decode('utf-8')
                        video_data.url = video.media.player.url.decode('utf-8')
                        video_data.duration = int(video.media.duration.seconds)

                        if video.statistics:
                            video_data.views = int(video.statistics.view_count)

                        if video.media.description.text is not None:
                            video_data.description = video.media.description.text.decode('utf-8')
                        else:
                            video_data.decription = ' '

                        if video.media.keywords.text:
                            video_data.keywords = video.media.keywords.text.decode('utf-8')
                        else:
                            video_data.keywords = ''

                        video_data.position = video.position
                        video_data_list.append(video_data)
                    db.put(video_data_list)

                    playlist_videos = []
                    for video_data in video_data_list:                
                        playlist_video = None
                        if video_playlist_key_dict.has_key(playlist_data.key()):
                            if video_playlist_key_dict[playlist_data.key()].has_key(video_data.key()):
                                playlist_video = video_playlist_key_dict[playlist_data.key()][video_data.key()]

                        if not playlist_video:
                            playlist_video = VideoPlaylist(playlist=playlist_data.key(), video=video_data.key())
                            logging.info('Creating VideoPlaylist: %s, %s', playlist_data.title, video_data.title)
                        else:
                            logging.info('Updating VideoPlaylist: %s, %s', playlist_video.playlist.title, playlist_video.video.title)
#.........這裏部分代碼省略.........
開發者ID:johnfelipe,項目名稱:server,代碼行數:103,代碼來源:youtube_sync.py

示例11: x

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
def x():
    playlist = Playlist.all().filter('name =', 'Godlista').get()
    trackkeys = [i.key() for i in Track.all()]
    playlist.tracks = trackkeys
    playlist.put()
    return str(playlist.tracks)
開發者ID:martingms,項目名稱:cloudlist,代碼行數:8,代碼來源:views.py

示例12: indexPlaylistData

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
 def indexPlaylistData(self):
     playlists = Playlist.all().fetch(10000)
     for playlist in playlists:
         playlist.index()
         playlist.indexed_title_changed()
開發者ID:johnfelipe,項目名稱:server,代碼行數:7,代碼來源:youtube_sync.py

示例13: library_content_html

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
def library_content_html():
    # No cache found -- regenerate HTML
    smart_history = getSmartHistoryContent()

    all_playlists = []

    dict_videos = {}
    dict_videos_counted = {}
    dict_playlists = {}
    dict_playlists_by_title = {}
    dict_video_playlists = {}

    async_queries = [
        Video.all(),
        Playlist.all(),
        VideoPlaylist.all().filter('live_association = ', True).order('video_position'),
    ]

    results = util.async_queries(async_queries)

    for video in results[0].get_result():
        dict_videos[video.key()] = video

    for playlist in results[1].get_result():
        dict_playlists[playlist.key()] = playlist
        if playlist.title in topics_list:
            dict_playlists_by_title[playlist.title] = playlist

    for video_playlist in results[2].get_result():
        playlist_key = VideoPlaylist.playlist.get_value_for_datastore(video_playlist)
        video_key = VideoPlaylist.video.get_value_for_datastore(video_playlist)

        if dict_videos.has_key(video_key) and dict_playlists.has_key(playlist_key):
            video = dict_videos[video_key]
            playlist = dict_playlists[playlist_key]
            fast_video_playlist_dict = {"video":video, "playlist":playlist}

            if dict_video_playlists.has_key(playlist_key):
                dict_video_playlists[playlist_key].append(fast_video_playlist_dict)
            else:
                dict_video_playlists[playlist_key] = [fast_video_playlist_dict]

            if dict_playlists_by_title.has_key(playlist.title):
                # Only count videos in topics_list
                dict_videos_counted[video.youtube_id] = True

    # Update count of all distinct videos associated w/ a live playlist
    Setting.count_videos(len(dict_videos_counted.keys()))

    for topic in topics_list:
        if topic in dict_playlists_by_title:
            playlist = dict_playlists_by_title[topic]
            playlist_key = playlist.key()
            playlist_videos = dict_video_playlists.get(playlist_key) or []

            if not playlist_videos:
                logging.error('Playlist %s has no videos!', playlist.title)

            playlist_data = {
                     'title': topic,
                     'topic': topic,
                     'playlist': playlist,
                     'videos': playlist_videos,
                     'next': None
                     }

            all_playlists.append(playlist_data)

    playlist_data_prev = None
    for playlist_data in all_playlists:
        if playlist_data_prev:
            playlist_data_prev['next'] = playlist_data
        playlist_data_prev = playlist_data

    # Separating out the columns because the formatting is a little different on each column
    template_values = {
        'App' : App,
        'all_playlists': all_playlists,
        'smart_history': smart_history,
        }

    html = shared_jinja.get().render_template("library_content_template.html", **template_values)

    # Set shared date of last generated content
    Setting.cached_library_content_date(str(datetime.datetime.now()))

    return html
開發者ID:KhanWorld,項目名稱:KhanAcademy,代碼行數:89,代碼來源:library.py

示例14: updateVideoAndPlaylistData

# 需要導入模塊: from models import Playlist [as 別名]
# 或者: from models.Playlist import all [as 別名]
    def updateVideoAndPlaylistData(self):
        yt_service = YouTubeService()

        video_youtube_id_dict = Video.get_dict(Video.all(), lambda video: video.youtube_id)
        video_playlist_key_dict = VideoPlaylist.get_key_dict(VideoPlaylist.all())

        association_generation = int(Setting.last_youtube_sync_generation_start())

        logging.info("Fetching playlists")
        playlist_start_index = 1
        playlist_feed = yt_service.GetYouTubePlaylistFeed(
            uri="http://gdata.youtube.com/feeds/api/users/KhanAcademyHebrew/playlists?start-index=%s&max-results=50"
            % playlist_start_index
        )

        while len(playlist_feed.entry) > 0:

            for playlist in playlist_feed.entry:
                logging.info("Playlist: %s", playlist.id.text)

                playlist_id = playlist.id.text.replace(
                    "http://gdata.youtube.com/feeds/api/users/KhanAcademyHebrew/playlists/", ""
                )
                playlist_uri = playlist.id.text.replace("users/KhanAcademyHebrew/", "")
                query = Playlist.all()
                query.filter("youtube_id =", playlist_id)
                playlist_data = query.get()
                if not playlist_data:
                    playlist_data = Playlist(youtube_id=playlist_id)
                    logging.info("Creating Playlist: %s", playlist.title.text)
                playlist_data.url = playlist_uri
                playlist_data.title = playlist.title.text.decode("utf-8")
                playlist_data.description = playlist.description.text.decode("utf-8")

                playlist_data.tags = []
                for category in playlist.category:
                    if "tags.cat" in category.scheme:
                        playlist_data.tags.append(category.term)

                playlist_data.put()

                for i in range(0, 10):
                    start_index = i * 50 + 1
                    video_feed = yt_service.GetYouTubePlaylistVideoFeed(
                        uri=playlist_uri + "?start-index=" + str(start_index) + "&max-results=50"
                    )
                    video_data_list = []

                    if len(video_feed.entry) <= 0:
                        # No more videos in playlist
                        break

                    for video in video_feed.entry:
                        if not video.media.player:
                            logging.warning("Could not parse video - skipping... (%s, %s)", video, video.media)
                            continue

                        video_id = cgi.parse_qs(urlparse(video.media.player.url).query)["v"][0].decode("utf-8")

                        video_data = None
                        if video_youtube_id_dict.has_key(video_id):
                            video_data = video_youtube_id_dict[video_id]
                            logging.info("Found Video: %s (%s)", video.media.title.text.decode("utf-8"), video_id)

                        if not video_data:
                            video_data = Video(youtube_id=video_id)
                            logging.info("Creating Video: %s (%s)", video.media.title.text.decode("utf-8"), video_id)

                        video_data.title = video.media.title.text.decode("utf-8")
                        video_data.url = video.media.player.url.decode("utf-8")
                        video_data.duration = int(video.media.duration.seconds)

                        if video.statistics:
                            video_data.views = int(video.statistics.view_count)

                        if video.media.description.text is not None:
                            video_data.description = video.media.description.text.decode("utf-8")
                        else:
                            video_data.decription = " "

                        if video.media.keywords.text:
                            video_data.keywords = video.media.keywords.text.decode("utf-8")
                        else:
                            video_data.keywords = ""

                        video_data.position = video.position
                        video_data_list.append(video_data)
                    db.put(video_data_list)

                    playlist_videos = []
                    for video_data in video_data_list:
                        playlist_video = None
                        if video_playlist_key_dict.has_key(playlist_data.key()):
                            if video_playlist_key_dict[playlist_data.key()].has_key(video_data.key()):
                                playlist_video = video_playlist_key_dict[playlist_data.key()][video_data.key()]

                        if not playlist_video:
                            playlist_video = VideoPlaylist(playlist=playlist_data.key(), video=video_data.key())
                            logging.info("Creating VideoPlaylist: %s, %s", playlist_data.title, video_data.title)
                        else:
#.........這裏部分代碼省略.........
開發者ID:hebkhan,項目名稱:server,代碼行數:103,代碼來源:youtube_sync.py


注:本文中的models.Playlist.all方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。