Repository: ytdl-org/youtube-dl

Issue:
Unable to Download Video
justin@FUSION:~$ youtube-dl https://www.youtube.com/watch?v=xdeFB7I0YH4 --verbose
[debug] System config: []
[debug] User config: []
[debug] Command-line args: ['https://www.youtube.com/watch?v=xdeFB7I0YH4', '--verbose']
[debug] youtube-dl version 2013.08.14
[debug] Python version 2.7.3 - Linux-3.2.0-4-686-pae-i686-with-debian-7.1
[debug] Proxy map: {}
[youtube] Setting language
[youtube] xdeFB7I0YH4: Downloading video webpage
[youtube] xdeFB7I0YH4: Downloading video info webpage
[youtube] xdeFB7I0YH4: Extracting video information
[youtube] xdeFB7I0YH4: Encrypted signatures detected.
[youtube] encrypted signature length 87 (46.40), itag 46, html5 player vflkn6DAl
[youtube] encrypted signature length 87 (46.40), itag 37, html5 player vflkn6DAl
[youtube] encrypted signature length 87 (46.40), itag 45, html5 player vflkn6DAl
[youtube] encrypted signature length 87 (46.40), itag 22, html5 player vflkn6DAl
[youtube] encrypted signature length 87 (46.40), itag 44, html5 player vflkn6DAl
[youtube] encrypted signature length 87 (46.40), itag 35, html5 player vflkn6DAl
[youtube] encrypted signature length 87 (46.40), itag 43, html5 player vflkn6DAl
[youtube] encrypted signature length 87 (46.40), itag 34, html5 player vflkn6DAl
[youtube] encrypted signature length 87 (46.40), itag 18, html5 player vflkn6DAl
[youtube] encrypted signature length 87 (46.40), itag 5, html5 player vflkn6DAl
[youtube] encrypted signature length 87 (46.40), itag 36, html5 player vflkn6DAl
[youtube] encrypted signature length 87 (46.40), itag 17, html5 player vflkn6DAl
ERROR: unable to download video
Traceback (most recent call last):
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 573, in download
    videos = self.extract_info(url)
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 327, in extract_info
    return self.process_ie_result(ie_result, download=download)
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 410, in process_ie_result
    for r in ie_result['entries']
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 357, in process_ie_result
    self.process_info(ie_result)
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 550, in process_info
    raise UnavailableVideoError(err)
UnavailableVideoError: HTTP Error 403: Forbidden



Discussion:
Updated signature function:

```
function lj(a) {
    a = a.split("");
    a = mj(a, 39);
    a = a.slice(2);
    a = mj(a, 57);
    a = a.slice(2);
    a = mj(a, 23);
    a = mj(a, 35);
    a = a.slice(2);
    return a.join("")
}

function mj(a, b) {
    var c = a[0];
    a[0] = a[b % a.length];
    a[b] = c;
    return a
};
```

new sig len 87 algo:

1121311115F8E878F14D005AE6F3AA2BC174C7924C69FB.9E16C4F2256D35202151C3A70180A02D0E18113D
1115F8E878F14D005AE6F3AA2BC174C7934C69FB.9E16C4F2256D25202151C3A70180A02D0E18113D

57573757BD0DE5A6262EA1937E79ABDE2760EAB5AAAB4D.26AA649DA7F036AE2919921CDFC48231E44294AB
57BD0DE5A6262EA1937E73ABDE2760EAB9AAAB4D.26AA649DA7F056AE2919921CDFC48231E44294AB

python:
s[6:27] + s[4] + s[28:39] + s[27] + s[40:59] + s[2] + s[60:]

javascript:
s.slice(6, 27).join('') + s[4] + s.slice(28, 39).join('') + s[27] + s.slice(40, 59).join('') + s[2] + s.slice(60).join('')


Resolving patch:
diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py
--- a/youtube_dl/extractor/youtube.py
+++ b/youtube_dl/extractor/youtube.py
@@ -340,7 +340,7 @@ def _decrypt_signature(self, s):
         elif len(s) == 88:
             return s[48] + s[81:67:-1] + s[82] + s[66:62:-1] + s[85] + s[61:48:-1] + s[67] + s[47:12:-1] + s[3] + s[11:3:-1] + s[2] + s[12]
         elif len(s) == 87:
-            return s[83:53:-1] + s[3] + s[52:40:-1] + s[86] + s[39:10:-1] + s[0] + s[9:3:-1] + s[53]
+            return s[6:27] + s[4] + s[28:39] + s[27] + s[40:59] + s[2] + s[60:]
         elif len(s) == 86:
             return s[5:20] + s[2] + s[21:]
         elif len(s) == 85:


Test patch: