tubelib: implement eUriResolver for youtube:// and yt://
[enigma2-plugins.git] / tubelib / src / youtube / YoutubeUriResolver.py
1 try:
2         from enigma import eServiceReference, eUriResolver, StringList
3         from Videos import VideoUrlRequest
4
5         from Tools.Log import Log
6
7         class YoutubeUriResolver(eUriResolver):
8                 _schemas = ("youtube", "yt")
9                 instance = None
10                 def __init__(self):
11                         eUriResolver.__init__(self, StringList(self._schemas))
12                         Log.i(self._schemas)
13
14                 def resolve(self, service, uri):
15                         Log.i(uri)
16                         video_id = uri.split("://")[1]
17                         watch_url = "http://youtube.com/watch?v=%s" % (video_id,)
18                         def onUrlReady(uri, format):
19                                 Log.d("%s (%s)" %(uri, format))
20                                 try:
21                                         if not service.ptrValid():
22                                                 Log.w("Service became invalid!")
23                                                 return
24                                         if uri:
25                                                 if VideoUrlRequest.isHls(format):
26                                                         service.setResolvedUri(uri, eServiceReference.idDVB)
27                                                 else:
28                                                         service.setResolvedUri(uri, eServiceReference.idGST)
29                                         else:
30                                                 service.failedToResolveUri()
31                                 except:
32                                         service.failedToResolveUri()
33
34                         VideoUrlRequest(watch_url, [onUrlReady], async=True)
35                         return True
36 except ImportError:
37         pass