Repository: ytdl-org/youtube-dl

Issue:
KeyError: 'k'
i was hoping you could help me out with this:

[debug] System config: []
[debug] User config: []
[debug] Command-line args: ['http://www.tudou.com/programs/view/ajX3gyhL0pc/', '
-v']
[debug] Encodings: locale cp1252, fs mbcs, out cp850, pref cp1252
[debug] youtube-dl version 2014.08.29
[debug] Python version 2.7.8 - Windows-7-6.1.7601-SP1
[debug] Proxy map: {}
[Tudou] ajX3gyhL0pc: Downloading webpage
Traceback (most recent call last):
  File "**main**.py", line 18, in <module>
  File "youtube_dl__init__.pyo", line 911, in main
  File "youtube_dl__init__.pyo", line 901, in _real_main
  File "youtube_dl\YoutubeDL.pyo", line 1063, in download
  File "youtube_dl\YoutubeDL.pyo", line 521, in extract_info
  File "youtube_dl\extractor\common.pyo", line 178, in extract
  File "youtube_dl\extractor\tudou.pyo", line 67, in _real_extract
KeyError: 'k'

thanks!

KeyError: 'k'
i was hoping you could help me out with this:

[debug] System config: []
[debug] User config: []
[debug] Command-line args: ['http://www.tudou.com/programs/view/ajX3gyhL0pc/', '
-v']
[debug] Encodings: locale cp1252, fs mbcs, out cp850, pref cp1252
[debug] youtube-dl version 2014.08.29
[debug] Python version 2.7.8 - Windows-7-6.1.7601-SP1
[debug] Proxy map: {}
[Tudou] ajX3gyhL0pc: Downloading webpage
Traceback (most recent call last):
  File "**main**.py", line 18, in <module>
  File "youtube_dl__init__.pyo", line 911, in main
  File "youtube_dl__init__.pyo", line 901, in _real_main
  File "youtube_dl\YoutubeDL.pyo", line 1063, in download
  File "youtube_dl\YoutubeDL.pyo", line 521, in extract_info
  File "youtube_dl\extractor\common.pyo", line 178, in extract
  File "youtube_dl\extractor\tudou.pyo", line 67, in _real_extract
KeyError: 'k'

thanks!

KeyError: 'k'
i was hoping you could help me out with this:

[debug] System config: []
[debug] User config: []
[debug] Command-line args: ['http://www.tudou.com/programs/view/ajX3gyhL0pc/', '
-v']
[debug] Encodings: locale cp1252, fs mbcs, out cp850, pref cp1252
[debug] youtube-dl version 2014.08.29
[debug] Python version 2.7.8 - Windows-7-6.1.7601-SP1
[debug] Proxy map: {}
[Tudou] ajX3gyhL0pc: Downloading webpage
Traceback (most recent call last):
  File "**main**.py", line 18, in <module>
  File "youtube_dl__init__.pyo", line 911, in main
  File "youtube_dl__init__.pyo", line 901, in _real_main
  File "youtube_dl\YoutubeDL.pyo", line 1063, in download
  File "youtube_dl\YoutubeDL.pyo", line 521, in extract_info
  File "youtube_dl\extractor\common.pyo", line 178, in extract
  File "youtube_dl\extractor\tudou.pyo", line 67, in _real_extract
KeyError: 'k'

thanks!



Discussion:
For this particular video the [`segments`](https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/tudou.py#L57) dict includes an additional key-value pair `LgWt': [{'lg': 0, 'wt': 0}]` which is then selected after sorting.

For this particular video the [`segments`](https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/tudou.py#L57) dict includes an additional key-value pair `LgWt': [{'lg': 0, 'wt': 0}]` which is then selected after sorting.

For this particular video the [`segments`](https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/tudou.py#L57) dict includes an additional key-value pair `LgWt': [{'lg': 0, 'wt': 0}]` which is then selected after sorting.


Resolving patch:
diff --git a/youtube_dl/extractor/tudou.py b/youtube_dl/extractor/tudou.py
--- a/youtube_dl/extractor/tudou.py
+++ b/youtube_dl/extractor/tudou.py
@@ -57,7 +57,9 @@ def _real_extract(self, url):
         segments = json.loads(segs_json)
         # It looks like the keys are the arguments that have to be passed as
         # the hd field in the request url, we pick the higher
-        quality = sorted(segments.keys())[-1]
+        # Also, filter non-number qualities (see issue #3643).
+        quality = sorted(filter(lambda k: k.isdigit(), segments.keys()),
+                         key=lambda k: int(k))[-1]
         parts = segments[quality]
         result = []
         len_parts = len(parts)


Test patch: