Commit 65547a04 authored by Gerion Entrup's avatar Gerion Entrup
Browse files

backend: drop different uri schemes

parent 7d001597
......@@ -41,10 +41,7 @@ class YouTubeBackend(pykka.ThreadingActor, backend.Backend):
self.library = YouTubeLibraryProvider(backend=self)
self.playback = YouTubePlaybackProvider(audio=audio, backend=self)
self.uri_schemes_yt = ('youtube', 'yt')
self.uri_schemas_all = ('ytdl')
# casting can be dropped if python 3 only
self.uri_schemes = tuple(list(self.uri_schemes_yt) + list(self.uri_schemas_all))
self.uri_schemes = ('youtube', 'yt', 'ytdl')
class YouTubeLibraryProvider(backend.LibraryProvider):
......@@ -83,7 +80,7 @@ class YouTubeLibraryProvider(backend.LibraryProvider):
name=result['id'],
images=[result['snippet']['thumbnails']['high']['url']]
),
uri=self.backend.uri_schemes_yt[0] + ':' + result['id']
uri=self.backend.uri_schemes[0] + ':' + result['id']
)
tracks.append(track)
return tracks
......@@ -157,24 +154,20 @@ class YouTubeLibraryProvider(backend.LibraryProvider):
def lookup(self, uri):
"""Process any uri supported by ytdl and return tracks"""
logger.info("Looking up Internet for '%s'", uri)
# modify this once python 3 is there
# scheme, *uri = uri.split(':')
# uri = ':'.join(uri)
uri = uri.split(':')
scheme = uri[0]
uri = ':'.join(uri[1:])
if scheme.startswith(self.backend.uri_schemes_yt):
# drop scheme from uri
uri = ':'.join(uri.split(':')[1:])
if 'youtube.com' in uri:
logger.info("Detected YouTube URL")
if 'youtube.com' in uri:
url = urlparse(uri)
req = parse_qs(url.query)
if 'list' in req:
return self._get_playlist(req.get('list')[0])
if 'v' in req:
return self._get_tracks([req.get('v')[0]])
else:
return self._get_tracks([uri])
url = urlparse(uri)
req = parse_qs(url.query)
if 'list' in req:
return self._get_playlist(req.get('list')[0])
if 'v' in req:
return self._get_tracks([req.get('v')[0]])
elif 'http' not in uri:
logger.info("Detected Youtube-ID")
return self._get_tracks([uri])
else:
logger.info("Invoke youtube-dl")
return self._get_ytdl_tracks(uri)
......@@ -205,14 +198,10 @@ class YouTubePlaybackProvider(backend.PlaybackProvider):
If already translated do nothing.
"""
logger.info("Playing YouTube id: %s", uri)
# modify this once python 3 is there
# scheme, *uri = uri.split(':')
# uri = ':'.join(uri)
uri = uri.split(':')
scheme = uri[0]
uri = ':'.join(uri[1:])
if scheme.startswith(self.backend.uri_schemes_yt):
# drop scheme from uri
uri = ':'.join(uri.split(':')[1:])
if 'http' not in uri:
uri = self._resolve_url(uri)
return uri
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment