tubelib/YoutubeUriresolver: add live/<channel> syntax (e.g. yt://live/mycoolchannel...
[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                         watch_url = None
17                         try:
18                                 uri = uri.split("://")[1]
19                                 uri = uri.split("/")
20                                 if uri[0] == "live":
21                                         watch_url = "https://youtube.com/user/%s/live" %(uri[1],)
22                                 else:
23                                         video_id = uri[0]
24                                         watch_url = "https://youtube.com/watch?v=%s" % (video_id,)
25                         except:
26                                 pass
27                         def onUrlReady(uri, format):
28                                 Log.d("%s (%s)" %(uri, format))
29                                 try:
30                                         if not service.ptrValid():
31                                                 Log.w("Service became invalid!")
32                                                 return
33                                         if uri:
34                                                 if VideoUrlRequest.isHls(format):
35                                                         service.setResolvedUri(uri, eServiceReference.idDVB)
36                                                 else:
37                                                         service.setResolvedUri(uri, eServiceReference.idGST)
38                                         else:
39                                                 service.failedToResolveUri()
40                                 except:
41                                         service.failedToResolveUri()
42                         Log.i(watch_url)
43                         if watch_url:
44                                 VideoUrlRequest(watch_url, [onUrlReady], async=True)
45                         else:
46                                 service.failedToResolveUri()
47                         return True
48 except ImportError:
49         pass