stream: Make library lookup use stream unwrapping (fixes #1445)
This commit is contained in:
parent
ce81b362dc
commit
2e5cfba710
@ -60,12 +60,17 @@ class StreamLibraryProvider(backend.LibraryProvider):
|
|||||||
logger.debug('URI matched metadata lookup blacklist: %s', uri)
|
logger.debug('URI matched metadata lookup blacklist: %s', uri)
|
||||||
return [Track(uri=uri)]
|
return [Track(uri=uri)]
|
||||||
|
|
||||||
try:
|
result = _unwrap_stream(
|
||||||
result = self.backend._scanner.scan(uri)
|
uri,
|
||||||
|
timeout=self.backend._timeout,
|
||||||
|
scanner=self.backend._scanner,
|
||||||
|
requests_session=self.backend._session)[1]
|
||||||
|
|
||||||
|
if result:
|
||||||
track = tags.convert_tags_to_track(result.tags).replace(
|
track = tags.convert_tags_to_track(result.tags).replace(
|
||||||
uri=uri, length=result.duration)
|
uri=uri, length=result.duration)
|
||||||
except exceptions.ScannerError as e:
|
else:
|
||||||
logger.warning('Problem looking up %s: %s', uri, e)
|
logger.warning('Problem looking up %s: %s', uri)
|
||||||
track = Track(uri=uri)
|
track = Track(uri=uri)
|
||||||
|
|
||||||
return [track]
|
return [track]
|
||||||
@ -85,9 +90,10 @@ class StreamPlaybackProvider(backend.PlaybackProvider):
|
|||||||
uri,
|
uri,
|
||||||
timeout=self.backend._timeout,
|
timeout=self.backend._timeout,
|
||||||
scanner=self.backend._scanner,
|
scanner=self.backend._scanner,
|
||||||
requests_session=self.backend._session)
|
requests_session=self.backend._session)[0]
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: cleanup the return value of this.
|
||||||
def _unwrap_stream(uri, timeout, scanner, requests_session):
|
def _unwrap_stream(uri, timeout, scanner, requests_session):
|
||||||
"""
|
"""
|
||||||
Get a stream URI from a playlist URI, ``uri``.
|
Get a stream URI from a playlist URI, ``uri``.
|
||||||
@ -105,7 +111,7 @@ def _unwrap_stream(uri, timeout, scanner, requests_session):
|
|||||||
logger.info(
|
logger.info(
|
||||||
'Unwrapping stream from URI (%s) failed: '
|
'Unwrapping stream from URI (%s) failed: '
|
||||||
'playlist referenced itself', uri)
|
'playlist referenced itself', uri)
|
||||||
return None
|
return None, None
|
||||||
else:
|
else:
|
||||||
seen_uris.add(uri)
|
seen_uris.add(uri)
|
||||||
|
|
||||||
@ -117,7 +123,7 @@ def _unwrap_stream(uri, timeout, scanner, requests_session):
|
|||||||
logger.info(
|
logger.info(
|
||||||
'Unwrapping stream from URI (%s) failed: '
|
'Unwrapping stream from URI (%s) failed: '
|
||||||
'timed out in %sms', uri, timeout)
|
'timed out in %sms', uri, timeout)
|
||||||
return None
|
return None, None
|
||||||
scan_result = scanner.scan(uri, timeout=scan_timeout)
|
scan_result = scanner.scan(uri, timeout=scan_timeout)
|
||||||
except exceptions.ScannerError as exc:
|
except exceptions.ScannerError as exc:
|
||||||
logger.debug('GStreamer failed scanning URI (%s): %s', uri, exc)
|
logger.debug('GStreamer failed scanning URI (%s): %s', uri, exc)
|
||||||
@ -130,14 +136,14 @@ def _unwrap_stream(uri, timeout, scanner, requests_session):
|
|||||||
):
|
):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Unwrapped potential %s stream: %s', scan_result.mime, uri)
|
'Unwrapped potential %s stream: %s', scan_result.mime, uri)
|
||||||
return uri
|
return uri, scan_result
|
||||||
|
|
||||||
download_timeout = deadline - time.time()
|
download_timeout = deadline - time.time()
|
||||||
if download_timeout < 0:
|
if download_timeout < 0:
|
||||||
logger.info(
|
logger.info(
|
||||||
'Unwrapping stream from URI (%s) failed: timed out in %sms',
|
'Unwrapping stream from URI (%s) failed: timed out in %sms',
|
||||||
uri, timeout)
|
uri, timeout)
|
||||||
return None
|
return None, None
|
||||||
content = http.download(
|
content = http.download(
|
||||||
requests_session, uri, timeout=download_timeout)
|
requests_session, uri, timeout=download_timeout)
|
||||||
|
|
||||||
@ -145,14 +151,14 @@ def _unwrap_stream(uri, timeout, scanner, requests_session):
|
|||||||
logger.info(
|
logger.info(
|
||||||
'Unwrapping stream from URI (%s) failed: '
|
'Unwrapping stream from URI (%s) failed: '
|
||||||
'error downloading URI %s', original_uri, uri)
|
'error downloading URI %s', original_uri, uri)
|
||||||
return None
|
return None, None
|
||||||
|
|
||||||
uris = playlists.parse(content)
|
uris = playlists.parse(content)
|
||||||
if not uris:
|
if not uris:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Failed parsing URI (%s) as playlist; found potential stream.',
|
'Failed parsing URI (%s) as playlist; found potential stream.',
|
||||||
uri)
|
uri)
|
||||||
return uri
|
return uri, None
|
||||||
|
|
||||||
# TODO Test streams and return first that seems to be playable
|
# TODO Test streams and return first that seems to be playable
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user