Home | Trees | Indices | Help |
---|
|
1 # -*- coding: utf-8 -*- 2 # Elisa - Home multimedia server 3 # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 4 # All rights reserved. 5 # 6 # This file is available under one of two license agreements. 7 # 8 # This file is licensed under the GPL version 3. 9 # See "LICENSE.GPL" in the root of this distribution including a special 10 # exception to use Elisa with Fluendo's plugins. 11 # 12 # The GPL part of Elisa is also available under a commercial licensing 13 # agreement from Fluendo. 14 # See "LICENSE.Elisa" in the root directory of this distribution package 15 # for details on that license. 16 17 __maintainer__ = 'Philippe Normand <philippe@fluendo.com>' 18 19 from elisa.base_components.media_provider import MediaProvider, UriNotMonitorable 20 from elisa.base_components.media_provider import NotifyEvent 21 from elisa.core.component import InitializeFailure 22 from elisa.core.media_uri import MediaUri 23 from elisa.core import common 24 from elisa.core.bus import bus_message 25 from elisa.core.observers.dict import DictObservable 26 from twisted.internet import defer, threads 27 28 from elisa.extern.translation import gettexter, N_ 29 T_ = gettexter('elisa-youtube') 30 31 32 from youtube_client import YouTubeClient 33 34 import os, gst 3537 """ 38 This class implements local filesystem support 39 """ 40 default_config = {'user': ''} 41 42 config_doc = {'user': 'Your Youtube username, optional' 43 } 4420246 #FIXME : works only on Linux 47 registry = gst.registry_get_default() 48 registry.scan_path(self.plugin.directory) 49 try: 50 gst.element_factory_make('flvdemux') 51 except gst.PluginNotFoundError: 52 msg = "Can't initialize flvdemux CVS version of gst-plugins-bad" 53 raise InitializeFailure(self.name, msg) 54 55 self._client = YouTubeClient() 56 57 uri = "youtube:///" 58 action_type = bus_message.MediaLocation.ActionType.LOCATION_ADDED 59 msg = bus_message.InternetLocation(action_type, "YouTube", 'youtube', uri, 60 media_types=['video',], 61 theme_icon='youtube') 62 common.application.bus.send_message(msg) 63 self.debug("Initialize done")64 67 7072 dfr = defer.Deferred() 73 if self._is_directory(uri): 74 dfr.callback({'file_type': 'directory', 'mime_type': ''}) 75 else: 76 dfr.callback({'file_type': 'video', 'mime_type': 'video/x-flv'}) 77 return dfr78 83 8688 real_uri = None 89 video_id = uri.path[1:] 90 video_url = "http://www.youtube.com/watch?v=%s" % video_id 91 real = self._client.get_flv_video_url(video_url) 92 if real: 93 real_uri = MediaUri(real) 94 return real_uri9597 dfr = defer.Deferred() 98 99 has_children = False 100 if self._is_directory(uri): 101 if 'video' in media_types: 102 has_children = True 103 104 dfr.callback(has_children) 105 return dfr106 138 139141 videos = [] 142 users = [] 143 tags = {} 144 145 host = uri.host 146 if host == '': 147 children = self._build_main_menu(children) 148 elif host == 'contacts': 149 username = uri.path[1:] # strip / from path 150 users = self._client.get_contacts(username) 151 elif host == 'recently_featured': 152 videos = self._client.recently_featured() 153 elif host == 'top_rated': 154 videos = self._client.top_rated() 155 elif host == 'most_viewed': 156 videos = self._client.most_viewed() 157 elif host == 'tags': 158 tags = self._client.get_categories() 159 elif host == 'tag': 160 tagname = uri.path[1:] # strip / from path 161 videos = self._client.get_category(tagname) 162 163 elif host == 'favorite_videos': 164 username = uri.path[1:] # strip / from path 165 videos = self._client.favorite_videos(username) 166 elif host == 'user': 167 username = uri.path[1:] # strip / from path 168 videos = self._client.videos_upload_by(username) 169 170 for tag, label in tags.iteritems(): 171 child_uri = MediaUri('youtube://tag/%s' % tag) 172 child_uri.label = label 173 children.append((child_uri, {})) 174 175 for video in videos: 176 video_id = video.id.text.split("/")[-1] 177 child_uri = MediaUri('youtube://video/%s' % video_id) 178 child_uri.label = video.title.text 179 thumbnail_url = self._client.get_largest_thumbnail(video) 180 metadata = DictObservable() 181 metadata['default_image'] = MediaUri(thumbnail_url) 182 children.append((child_uri, metadata)) 183 184 if users is not None: 185 for user in users: 186 child_uri = MediaUri('youtube://user/%s' % user) 187 child_uri.label = user 188 children.append((child_uri, {})) 189 190 return children191 192 196 199
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0beta1 on Wed Jan 16 19:11:05 2008 | http://epydoc.sourceforge.net |