spaam / svtplay-dl

Small command-line program to download videos from some streaming sites.
https://svtplay-dl.se
MIT License
724 stars 122 forks source link

Twitch: KeyError: 'token' with VOD downloading #560

Open MikeLund opened 7 years ago

MikeLund commented 7 years ago
~$ svtplay-dl https://www.twitch.tv/playhearthstone/videos/all --verbose
DEBUG [1486977118.84] /usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/utils/__init__.py/request: HTTP getting 'https://www.twitch.tv/playhearthstone/videos/all'
DEBUG [1486977118.95] /usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/utils/__init__.py/request: HTTP getting 'https://api.twitch.tv//api/channels/playhearthstone/access_token'
ERROR [1486977119.74] /usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/__init__.py/get_one_media: version: 1.9.2
Traceback (most recent call last):
  File "/usr/local/bin/svtplay-dl", line 7, in <module>
    svtplay_dl.main()
  File "/usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/__init__.py", line 461, in main
    get_media(urls[0], options)
  File "/usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/__init__.py", line 192, in get_media
    get_one_media(stream, copy.copy(options))
  File "/usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/__init__.py", line 239, in get_one_media
    for i in streams:
  File "/usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/service/twitch.py", line 68, in get
    for i in data:
  File "/usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/service/twitch.py", line 153, in _get_channel
    hls_url = self._get_hls_url(channel)
  File "/usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/service/twitch.py", line 140, in _get_hls_url
    query = "token=%s&sig=%s&allow_source=true&allow_spectre=true" % (quote_plus(access['token']), access['sig'])
KeyError: 'token'

Get the same thing if trying to download a specific VOD:

~$ svtplay-dl https://www.twitch.tv/videos/99292393 --verbose
DEBUG [1486977178.94] /usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/utils/__init__.py/request: HTTP getting 'https://www.twitch.tv/videos/99292393'
DEBUG [1486977179.36] /usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/utils/__init__.py/request: HTTP getting 'https://api.twitch.tv//api/channels/videos/access_token'
ERROR [1486977180.15] /usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/__init__.py/get_one_media: version: 1.9.2
Traceback (most recent call last):
  File "/usr/local/bin/svtplay-dl", line 7, in <module>
    svtplay_dl.main()
  File "/usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/__init__.py", line 461, in main
    get_media(urls[0], options)
  File "/usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/__init__.py", line 192, in get_media
    get_one_media(stream, copy.copy(options))
  File "/usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/__init__.py", line 239, in get_one_media
    for i in streams:
  File "/usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/service/twitch.py", line 68, in get
    for i in data:
  File "/usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/service/twitch.py", line 153, in _get_channel
    hls_url = self._get_hls_url(channel)
  File "/usr/local/Cellar/svtplay-dl/1.9.2/libexec/lib/python2.7/site-packages/svtplay_dl/service/twitch.py", line 140, in _get_hls_url
    query = "token=%s&sig=%s&allow_source=true&allow_spectre=true" % (quote_plus(access['token']), access['sig'])
KeyError: 'token'

Am I doing it wrong, or is this a bug? Thanks!

qnorsten commented 7 years ago

I think Twitch has changed their API. I think you need to use oath2 to get a token now. I am not sure how to do that in svtplay-dl, perhaps @spaam has some idea?

Edit: I think svtplay-dl need to get a client ID and pass it as a header in all api calls as stated here : https://blog.twitch.tv/client-id-required-for-kraken-api-calls-afbb8e95f843#.m078q2ys2

Edit2: Turns out they also changed the format of some of the links, but that was an easy fix.

qnorsten commented 7 years ago

I have a fix for this it is mostly a matter of parsing the correct header with a CLIENT-ID. What do you think @spaam should each user get their own ID and pass it with something such as --twitch-client id ? Or should svtplay use a hard coded one similar to how youtube-dl does it?

drejjmit commented 7 years ago

Status on this fix? Will you generate a client-id for svtplay-dl or will we be able to use our own client-id?