Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DASHStream: can't use headers for DASHStreamReader/Worker/Writer #2291

Closed
1 task done
back-to opened this issue Feb 1, 2019 · 1 comment · Fixed by #2545
Closed
1 task done

DASHStream: can't use headers for DASHStreamReader/Worker/Writer #2291

back-to opened this issue Feb 1, 2019 · 1 comment · Fixed by #2545
Labels

Comments

@back-to
Copy link
Collaborator

back-to commented Feb 1, 2019

Bug Report

  • This is a bug report and I have read the contribution guidelines.

Description

could be related to #2270
but there is no 403 Client Error so lets use a different issue here

headers (User-Agent) used with DASHStream.parse_manifest will only work here

res = session.http.get(url, **args)

stream = DASHStream(session, mpd, vid, aud, **args)

not in DASHStreamReader/Worker/Writer

Expected / Actual behavior

allow headers in reload ... , same as hls

HLS with request_params

class HLSStreamReader(SegmentedStreamReader):
__worker__ = HLSStreamWorker
__writer__ = HLSStreamWriter
def __init__(self, stream, *args, **kwargs):
SegmentedStreamReader.__init__(self, stream, *args, **kwargs)
self.request_params = dict(stream.args)

**self.reader.request_params)

DASH does not have request_params

class DASHStreamReader(SegmentedStreamReader):
__worker__ = DASHStreamWorker
__writer__ = DASHStreamWriter
def __init__(self, stream, representation_id, mime_type, *args, **kwargs):
SegmentedStreamReader.__init__(self, stream, *args, **kwargs)
self.mime_type = mime_type
self.representation_id = representation_id
log.debug("Opening DASH reader for: {0} ({1})".format(self.representation_id, self.mime_type))

res = self.session.http.get(self.mpd.url, exception=StreamError)

Reproduction steps / Explicit stream URLs to test

  1. streamlink https://www.tf1.fr/lci/direct 576p_dash

for s in DASHStream.parse_manifest(self.session, url, headers={"User-Agent": useragents.CHROME}).items():

Log output

$ streamlink https://www.tf1.fr/lci/direct 576p_dash
[cli][debug] OS:         Linux
[cli][debug] Python:     3.6.7
[cli][debug] Streamlink: 1.0.0+3.g4100688.dirty
[cli][debug] Requests(2.21.0), Socks(1.6.7), Websocket(0.54.0)
[cli][info] Found matching plugin tf1 for URL https://www.tf1.fr/lci/direct
[plugin.tf1][debug] Found channel lci
[plugin.tf1][debug] Got dash stream https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_2000000.mpd?e=&st=
[utils.l10n][debug] Language code: en_US
[stream.dash][debug] Available languages for DASH audio streams: NONE (using: n/a)
[plugin.tf1][debug] Got hls stream https://lci-hls-live-ssl.tf1.fr/lci/1/hls/master_4000000.m3u8?e=&st=
[utils.l10n][debug] Language code: en_US
[cli][info] Available streams: 234p_dash, 360p_dash, 576p_dash, 234p (worst), 360p, 576p_alt, 576p, 720p (best)
[cli][info] Opening stream: 576p_dash (dash)
[stream.dash][debug] Opening DASH reader for: live_1828_H264 (video/mp4)
[stream.dash_manifest][debug] Generating segment timeline for dynamic playlist (id=live_1828_H264))
[stream.dash][debug] Reloading manifest (live_1828_H264:video/mp4)
[stream.dash][debug] Opening DASH reader for: live_2328_AAC (audio/mp4)
[stream.dash_manifest][debug] Generating segment timeline for dynamic playlist (id=live_2328_AAC))
[stream.dash][debug] Reloading manifest (live_2328_AAC:audio/mp4)
[stream.mp4mux-ffmpeg][debug] ffmpeg command: /usr/bin/ffmpeg -nostats -y -i /tmp/ffmpeg-2811-460 -i /tmp/ffmpeg-2811-532 -c:v copy -c:a copy -copyts -f matroska pipe:1
[stream.ffmpegmux][debug] Starting copy to pipe: /tmp/ffmpeg-2811-460
[stream.ffmpegmux][debug] Starting copy to pipe: /tmp/ffmpeg-2811-532
[cli][debug] Pre-buffering 8192 bytes
[stream.dash][debug] Download of segment: https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_1828/init.m4v complete
Exception in thread Thread-DASHStreamWorker:
Traceback (most recent call last):
  File "src/streamlink/plugin/api/http_session.py", line 166, in request
    res.raise_for_status()
  File "env/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_2000000.mpd?e=&st=

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "src/streamlink/stream/segmented.py", line 59, in run
    for segment in self.iter_segments():
  File "src/streamlink/stream/dash.py", line 97, in iter_segments
    if not self.reload():
  File "src/streamlink/stream/dash.py", line 111, in reload
    res = self.session.http.get(self.mpd.url, exception=StreamError)
  File "env/lib/python3.6/site-packages/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "src/streamlink/plugin/api/http_session.py", line 175, in request
    raise err
streamlink.exceptions.StreamError: Unable to open URL: https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_2000000.mpd?e=&st=
(403 Client Error: Forbidden for url: https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_2000000.mpd?e=&st=)
Exception in thread Thread-DASHStreamWorker:
Traceback (most recent call last):
  File "src/streamlink/plugin/api/http_session.py", line 166, in request
    res.raise_for_status()
  File "env/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_2000000.mpd?e=&st=

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "src/streamlink/stream/segmented.py", line 59, in run
    for segment in self.iter_segments():
  File "src/streamlink/stream/dash.py", line 97, in iter_segments
    if not self.reload():
  File "src/streamlink/stream/dash.py", line 111, in reload
    res = self.session.http.get(self.mpd.url, exception=StreamError)
  File "env/lib/python3.6/site-packages/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "src/streamlink/plugin/api/http_session.py", line 175, in request
    raise err
streamlink.exceptions.StreamError: Unable to open URL: https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_2000000.mpd?e=&st=
(403 Client Error: Forbidden for url: https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_2000000.mpd?e=&st=)

[stream.dash][debug] Download of segment: https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_2328/init.m4a complete
[stream.dash][debug] Download of segment: https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_2328/65796000.m4a complete
[stream.dash][debug] Download of segment: https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_2328/65800000.m4a complete
[stream.dash][debug] Download of segment: https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_2328/65804000.m4a complete
[stream.dash][debug] Download of segment: https://lci-das-live-ssl.tf1.fr/lci/1/dash/live_1828/65792000.m4v complete

Additional comments, screenshots, etc.

used with a global User-Agent fixed it

@Billy2011
Copy link
Contributor

You need to update the session headers, either in the tf1 plugin or dash.py:
self.session.http.headers.update (...)
otherwise the headers only work in the corresponding http.get () call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment