youtube-dl: [twitch.tv][includes workaround + fix] KeyError('redirect',) when downloading with username/password

  • I’ve verified and I assure that I’m running youtube-dl 2017.08.27.1
  • At least skimmed through the README, most notably the FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones
  • Bug report (encountered problems with youtube-dl)
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['--add-metadata', '--write-description', '--write-thumbnail', '--ignore-errors', '--username', 'PRIVATE', '--password', 'PRIVATE', '--cookies', 'cookies.txt', '--verbose', 'https://www.twitch.tv/PRIVATE/videos/all']
[debug] Encodings: locale cp1252, fs mbcs, out cp850, pref cp1252
[debug] youtube-dl version 2017.08.27.1
[debug] Python version 3.4.4 - Windows-7-6.1.7601-SP1
[debug] exe versions: ffmpeg 3.2, ffprobe 3.2
[debug] Proxy map: {}
[twitch:vod] Downloading login page
[twitch:vod] Logging in as PRIVATE
ERROR: An extractor error has occurred. (caused by KeyError('redirect',)); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type  youtube-dl -U  to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
Traceback (most recent call last):
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp_2hklmx2\build\youtube_dl\extractor\common.py", line 433, in extract
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp_2hklmx2\build\youtube_dl\extractor\common.py", line 391, in initialize
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp_2hklmx2\build\youtube_dl\extractor\twitch.py", line 56, in _real_initialize
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp_2hklmx2\build\youtube_dl\extractor\twitch.py", line 106, in _login
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp_2hklmx2\build\youtube_dl\extractor\twitch.py", line 91, in login_step
KeyError: 'redirect'
Traceback (most recent call last):
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp_2hklmx2\build\youtube_dl\extractor\common.py", line 433, in extract
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp_2hklmx2\build\youtube_dl\extractor\common.py", line 391, in initialize
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp_2hklmx2\build\youtube_dl\extractor\twitch.py", line 56, in _real_initialize
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp_2hklmx2\build\youtube_dl\extractor\twitch.py", line 106, in _login
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp_2hklmx2\build\youtube_dl\extractor\twitch.py", line 91, in login_step
KeyError: 'redirect'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp_2hklmx2\build\youtube_dl\YoutubeDL.py", line 776, in extract_info
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp_2hklmx2\build\youtube_dl\extractor\common.py", line 447, in extract
youtube_dl.utils.ExtractorError: An extractor error has occurred. (caused by KeyError('redirect',)); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type  youtube-dl -U  to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

When you try to use login credentials using –username and –password on Twitch.tv now, youtube-dl gets redirected and aborts downloading the video(s).

A workaround is to create a cookies.txt file using –cookies together with –username and –password once (it gets created despite the redirect error) and then invoke youtube-dl a second time without the –username and –password command options but only using –cookies cookies.txt.

Being able to use login credentials or cookies with youtube-dl is important because some streamers make their VODs only available to subscribers.

Also note that this bug is reproducable with any Twitch.tv VOD not just sub-only VODs, all it takes is trying to use –username and –password for the redirect error to occur.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 15

Most upvoted comments

Looks like the response includes ‘redirect_path’ now. Changing the ‘redirect_url = urljoin(…)’ line to this fixed the problem for me:

        if 'redirect_path' in response:
            redirect_url = urljoin(post_url, response['redirect_path'])
        else:
            redirect_url = urljoin(post_url, response['redirect'])

For folks that land here that don’t know exactly what to do to fix this if you have even a tiny bit of git and python knowledge you just need to modify the twitch.py extractor file after cloning the repo.

$ git diff 
diff --git a/youtube_dl/extractor/twitch.py b/youtube_dl/extractor/twitch.py
index f9164af09..69489d40d 100644
--- a/youtube_dl/extractor/twitch.py
+++ b/youtube_dl/extractor/twitch.py
@@ -88,7 +88,11 @@ class TwitchBaseIE(InfoExtractor):
                     fail(response['message'])
                 raise
 
-            redirect_url = urljoin(post_url, response['redirect'])
+            if 'redirect_path' in response:
+                redirect_url = urljoin(post_url, response['redirect_path'])
+            else:
+                redirect_url = urljoin(post_url, response['redirect'])
+
             return self._download_webpage_handle(
                 redirect_url, None, 'Downloading login redirect page',
                 headers=headers)

Then you can download the vid you want by running a command like this from the top level of the repo.

$ python -m youtube_dl -u NAME -p PASS https://www.twitch.tv/videos/217708370

I have the same problem. The described workaround also works for me. Thanks @Gorrrg!

Not a big surprise it gets redirected to a login page:

<!DOCTYPE html>
<html lang="en" data-passport-version="5">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://passport-cdn.ttvnw.net/styles/passport_7d75a70bb2509541dcc0b94c1212304a.css" />
	<link rel="shortcut icon" href="../assets/img/favicon.png" type="image/x-icon"/>
  <title>Login</title>

	
	
	

  
    <base target="_self" />
  
</head>

<body class="kraken-page" >
  <div class="container" role="main">
    <div class="authorize">
      <div class="wrap">
        
          

<div class="header clearfix">
  <a id="header_logo">
    <svg class="svg-logo_twitch" version="1.1" viewBox="-2.5 0 100 50" x="0px" y="0px">
      <path clip-rule="evenodd" d="M88,5h-6V0h-9l-6,5h-5.5L59,7.5V5h-5V0H36v5H16l-5-5H0v22l5,5.25L14,32h6v-1.5l3,1.5h12l2-3l1,3h7v-3l3,3h8l0.5-3l2.5,3h10l3-3v3h4l3-3v3h7l7-6V10L88,5z M13,13H8v6h5v6H6l-4-4V2h6v5h5V13z M36,21.5L32.5,25H15V7h6v12h2V7h6v12h2V7h5V21.5z M44,25h-6V7h6V25z M44,5h-6V2h6V5z M57,13h-5v6h5v6h-7l-4-4V2h6v5h5V13z M72,13h-7v6h7v6h-9l-4-4V11l4-4h9V13z M91,25h-6V13h-5v12h-6V2h6v5h7l4,4V25z" fill-rule="evenodd"></path>
    </svg>
  </a>
</div>


        
        <div class="card">
          <div class="text-content">
            
              
                <div class="item">
                  <button class="fb_button button" disabled>
                    <svg width="18" height="18" viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg"><path d="M16.936 0H.99C.442 0 0 .443 0 .99v15.946c0 .547.443.99.99.99h8.585v-6.942H7.24V8.28h2.335V6.282c0-2.315 1.414-3.576 3.48-3.576.99 0 1.84.074 2.087.107v2.42H13.71c-1.124 0-1.342.534-1.342 1.317v1.73h2.68l-.35 2.704h-2.33v6.942h4.568c.547 0 .99-.443.99-.99V.99c0-.547-.443-.99-.99-.99" fill="#FFF" fill-rule="evenodd"/></svg>
                      <span>Connect with Facebook</span>
                  </button>
									<input type="hidden" name="facebook" />
                  <input type="hidden" name="facebook_submit_url" value="/facebook_login/new" />
                </div>
              
              
                
    <div class="item">
      <ul class="tabs">
        <li id="login_tab" class="tab selected"><a target="_self" href="#">Log In</a></li>
        <li id="signup_tab" class="tab "><a target="_self" href="/signup/new?client_id=PRIVATE&amp;embed=0&amp;error_code=&amp;redirect_path=https%3A%2F%2Fwww.twitch.tv%2F&amp;style=&amp;sudo_reason=&amp;username=">Sign Up</a></li>
      </ul>
    </div>

              
            
            <div class="item">
              
              
              <input type="hidden" name="request_id" value="PRIVATE" />
              <input type="hidden" name="origin_uri" value="" />
              <input type="hidden" name="redirect_path" value="https://www.twitch.tv/" />
              <input id="authenticity_token" type="hidden" value="PRIVATE" />
              


  <form method="post" action="/sessions/new" id="loginForm" class="col-md-6">

  

  

<input type="hidden" name="scope" value="" />
<input type="hidden" name="client_id" value="PRIVATE" />
<input type="hidden" name="redirect_uri" value="" />
<input type="hidden" name="response_type" value="" />
<input type="hidden" name="state" value="" />
<input type="hidden" name="nonce" value="" />
<input type="hidden" name="kraken_oidc_nonce" value="" />



  <input type="hidden" name="embed" value="false" />
  <input type="hidden" name="time_to_submit" value="" />
  
    <div class="field item">
        <label for="username">Username</label>
        <input autocapitalize="none" type="text" name="username" id="username" class="text" value="" />
    </div>
  

    <div class="field item" id="password">
        <label for="password">Password</label>
        <input autocapitalize="none" type="password" name="password" class="text" />
        <div class="help sub">
          <a id="reset" href="/password_resets/new?client_id=PRIVATE" target="_blank" class="small" >Trouble logging in?</a>
        </div>
    </div>
  <div class="buttons">
    <button class="primary button js-login-button" type="submit">
      <span class="js-login-text">
        Log In
      </span>
    </button>
  </div>
</form>

            </div>
          </div>
        </div>
      </div>

      
      <div id="fb-root"></div>
    </div>
  </div>

  
<img class="tracking-pixel" src="/client_event/new?client_id=PRIVATE&title=Login"/>

  
	<input type="hidden" name="show_captcha" value="false" />
	<input type="hidden" name="lang" value="en" />
	<script src="https://passport-cdn.ttvnw.net/javascripts/common_08568d77854b5134d262.js"></script>
  <script src="https://passport-cdn.ttvnw.net/javascripts/login_8d4e602fa2b9960106ff.js"></script>
</body>