We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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!


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `youtube_dl/extractor/tudou.py`
Content:
```
1 # coding: utf-8
2 
3 import re
4 import json
5 
6 from .common import InfoExtractor
7 
8 
9 class TudouIE(InfoExtractor):
10     _VALID_URL = r'(?:http://)?(?:www\.)?tudou\.com/(?:listplay|programs|albumplay)/(?:view|(.+?))/(?:([^/]+)|([^/]+))(?:\.html)?'
11     _TESTS = [{
12         u'url': u'http://www.tudou.com/listplay/zzdE77v6Mmo/2xN2duXMxmw.html',
13         u'file': u'159448201.f4v',
14         u'md5': u'140a49ed444bd22f93330985d8475fcb',
15         u'info_dict': {
16             u"title": u"卡马乔国足开大脚长传冲吊集锦"
17         }
18     },
19     {
20         u'url': u'http://www.tudou.com/albumplay/TenTw_JgiPM/PzsAs5usU9A.html',
21         u'file': u'todo.mp4',
22         u'md5': u'todo.mp4',
23         u'info_dict': {
24             u'title': u'todo.mp4',
25         },
26         u'add_ie': [u'Youku'],
27         u'skip': u'Only works from China'
28     }]
29 
30     def _url_for_id(self, id, quality = None):
31         info_url = "http://v2.tudou.com/f?id="+str(id)
32         if quality:
33             info_url += '&hd' + quality
34         webpage = self._download_webpage(info_url, id, "Opening the info webpage")
35         final_url = self._html_search_regex('>(.+?)</f>',webpage, 'video url')
36         return final_url
37 
38     def _real_extract(self, url):
39         mobj = re.match(self._VALID_URL, url)
40         video_id = mobj.group(2)
41         webpage = self._download_webpage(url, video_id)
42 
43         m = re.search(r'vcode:\s*[\'"](.+?)[\'"]', webpage)
44         if m and m.group(1):
45             return {
46                 '_type': 'url',
47                 'url': u'youku:' + m.group(1),
48                 'ie_key': 'Youku'
49             }
50 
51         title = self._search_regex(
52             r",kw:\s*['\"](.+?)[\"']", webpage, u'title')
53         thumbnail_url = self._search_regex(
54             r",pic:\s*[\"'](.+?)[\"']", webpage, u'thumbnail URL', fatal=False)
55 
56         segs_json = self._search_regex(r'segs: \'(.*)\'', webpage, 'segments')
57         segments = json.loads(segs_json)
58         # It looks like the keys are the arguments that have to be passed as
59         # the hd field in the request url, we pick the higher
60         quality = sorted(segments.keys())[-1]
61         parts = segments[quality]
62         result = []
63         len_parts = len(parts)
64         if len_parts > 1:
65             self.to_screen(u'%s: found %s parts' % (video_id, len_parts))
66         for part in parts:
67             part_id = part['k']
68             final_url = self._url_for_id(part_id, quality)
69             ext = (final_url.split('?')[0]).split('.')[-1]
70             part_info = {'id': part_id,
71                           'url': final_url,
72                           'ext': ext,
73                           'title': title,
74                           'thumbnail': thumbnail_url,
75                           }
76             result.append(part_info)
77 
78         return result
79
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
         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)

{"golden_diff": "diff --git a/youtube_dl/extractor/tudou.py b/youtube_dl/extractor/tudou.py\n--- a/youtube_dl/extractor/tudou.py\n+++ b/youtube_dl/extractor/tudou.py\n@@ -57,7 +57,9 @@\n         segments = json.loads(segs_json)\n         # It looks like the keys are the arguments that have to be passed as\n         # the hd field in the request url, we pick the higher\n-        quality = sorted(segments.keys())[-1]\n+        # Also, filter non-number qualities (see issue #3643).\n+        quality = sorted(filter(lambda k: k.isdigit(), segments.keys()),\n+                         key=lambda k: int(k))[-1]\n         parts = segments[quality]\n         result = []\n         len_parts = len(parts)\n", "issue": "KeyError: 'k'\ni was hoping you could help me out with this:\n\n[debug] System config: []\n[debug] User config: []\n[debug] Command-line args: ['http://www.tudou.com/programs/view/ajX3gyhL0pc/', '\n-v']\n[debug] Encodings: locale cp1252, fs mbcs, out cp850, pref cp1252\n[debug] youtube-dl version 2014.08.29\n[debug] Python version 2.7.8 - Windows-7-6.1.7601-SP1\n[debug] Proxy map: {}\n[Tudou] ajX3gyhL0pc: Downloading webpage\nTraceback (most recent call last):\n  File \"**main**.py\", line 18, in <module>\n  File \"youtube_dl__init__.pyo\", line 911, in main\n  File \"youtube_dl__init__.pyo\", line 901, in _real_main\n  File \"youtube_dl\\YoutubeDL.pyo\", line 1063, in download\n  File \"youtube_dl\\YoutubeDL.pyo\", line 521, in extract_info\n  File \"youtube_dl\\extractor\\common.pyo\", line 178, in extract\n  File \"youtube_dl\\extractor\\tudou.pyo\", line 67, in _real_extract\nKeyError: 'k'\n\nthanks!\n\nKeyError: 'k'\ni was hoping you could help me out with this:\n\n[debug] System config: []\n[debug] User config: []\n[debug] Command-line args: ['http://www.tudou.com/programs/view/ajX3gyhL0pc/', '\n-v']\n[debug] Encodings: locale cp1252, fs mbcs, out cp850, pref cp1252\n[debug] youtube-dl version 2014.08.29\n[debug] Python version 2.7.8 - Windows-7-6.1.7601-SP1\n[debug] Proxy map: {}\n[Tudou] ajX3gyhL0pc: Downloading webpage\nTraceback (most recent call last):\n  File \"**main**.py\", line 18, in <module>\n  File \"youtube_dl__init__.pyo\", line 911, in main\n  File \"youtube_dl__init__.pyo\", line 901, in _real_main\n  File \"youtube_dl\\YoutubeDL.pyo\", line 1063, in download\n  File \"youtube_dl\\YoutubeDL.pyo\", line 521, in extract_info\n  File \"youtube_dl\\extractor\\common.pyo\", line 178, in extract\n  File \"youtube_dl\\extractor\\tudou.pyo\", line 67, in _real_extract\nKeyError: 'k'\n\nthanks!\n\nKeyError: 'k'\ni was hoping you could help me out with this:\n\n[debug] System config: []\n[debug] User config: []\n[debug] Command-line args: ['http://www.tudou.com/programs/view/ajX3gyhL0pc/', '\n-v']\n[debug] Encodings: locale cp1252, fs mbcs, out cp850, pref cp1252\n[debug] youtube-dl version 2014.08.29\n[debug] Python version 2.7.8 - Windows-7-6.1.7601-SP1\n[debug] Proxy map: {}\n[Tudou] ajX3gyhL0pc: Downloading webpage\nTraceback (most recent call last):\n  File \"**main**.py\", line 18, in <module>\n  File \"youtube_dl__init__.pyo\", line 911, in main\n  File \"youtube_dl__init__.pyo\", line 901, in _real_main\n  File \"youtube_dl\\YoutubeDL.pyo\", line 1063, in download\n  File \"youtube_dl\\YoutubeDL.pyo\", line 521, in extract_info\n  File \"youtube_dl\\extractor\\common.pyo\", line 178, in extract\n  File \"youtube_dl\\extractor\\tudou.pyo\", line 67, in _real_extract\nKeyError: 'k'\n\nthanks!\n\n", "before_files": [{"content": "# coding: utf-8\n\nimport re\nimport json\n\nfrom .common import InfoExtractor\n\n\nclass TudouIE(InfoExtractor):\n    _VALID_URL = r'(?:http://)?(?:www\\.)?tudou\\.com/(?:listplay|programs|albumplay)/(?:view|(.+?))/(?:([^/]+)|([^/]+))(?:\\.html)?'\n    _TESTS = [{\n        u'url': u'http://www.tudou.com/listplay/zzdE77v6Mmo/2xN2duXMxmw.html',\n        u'file': u'159448201.f4v',\n        u'md5': u'140a49ed444bd22f93330985d8475fcb',\n        u'info_dict': {\n            u\"title\": u\"\u5361\u9a6c\u4e54\u56fd\u8db3\u5f00\u5927\u811a\u957f\u4f20\u51b2\u540a\u96c6\u9526\"\n        }\n    },\n    {\n        u'url': u'http://www.tudou.com/albumplay/TenTw_JgiPM/PzsAs5usU9A.html',\n        u'file': u'todo.mp4',\n        u'md5': u'todo.mp4',\n        u'info_dict': {\n            u'title': u'todo.mp4',\n        },\n        u'add_ie': [u'Youku'],\n        u'skip': u'Only works from China'\n    }]\n\n    def _url_for_id(self, id, quality = None):\n        info_url = \"http://v2.tudou.com/f?id=\"+str(id)\n        if quality:\n            info_url += '&hd' + quality\n        webpage = self._download_webpage(info_url, id, \"Opening the info webpage\")\n        final_url = self._html_search_regex('>(.+?)</f>',webpage, 'video url')\n        return final_url\n\n    def _real_extract(self, url):\n        mobj = re.match(self._VALID_URL, url)\n        video_id = mobj.group(2)\n        webpage = self._download_webpage(url, video_id)\n\n        m = re.search(r'vcode:\\s*[\\'\"](.+?)[\\'\"]', webpage)\n        if m and m.group(1):\n            return {\n                '_type': 'url',\n                'url': u'youku:' + m.group(1),\n                'ie_key': 'Youku'\n            }\n\n        title = self._search_regex(\n            r\",kw:\\s*['\\\"](.+?)[\\\"']\", webpage, u'title')\n        thumbnail_url = self._search_regex(\n            r\",pic:\\s*[\\\"'](.+?)[\\\"']\", webpage, u'thumbnail URL', fatal=False)\n\n        segs_json = self._search_regex(r'segs: \\'(.*)\\'', webpage, 'segments')\n        segments = json.loads(segs_json)\n        # It looks like the keys are the arguments that have to be passed as\n        # the hd field in the request url, we pick the higher\n        quality = sorted(segments.keys())[-1]\n        parts = segments[quality]\n        result = []\n        len_parts = len(parts)\n        if len_parts > 1:\n            self.to_screen(u'%s: found %s parts' % (video_id, len_parts))\n        for part in parts:\n            part_id = part['k']\n            final_url = self._url_for_id(part_id, quality)\n            ext = (final_url.split('?')[0]).split('.')[-1]\n            part_info = {'id': part_id,\n                          'url': final_url,\n                          'ext': ext,\n                          'title': title,\n                          'thumbnail': thumbnail_url,\n                          }\n            result.append(part_info)\n\n        return result\n", "path": "youtube_dl/extractor/tudou.py"}], "after_files": [{"content": "# coding: utf-8\n\nimport re\nimport json\n\nfrom .common import InfoExtractor\n\n\nclass TudouIE(InfoExtractor):\n    _VALID_URL = r'(?:http://)?(?:www\\.)?tudou\\.com/(?:listplay|programs|albumplay)/(?:view|(.+?))/(?:([^/]+)|([^/]+))(?:\\.html)?'\n    _TESTS = [{\n        u'url': u'http://www.tudou.com/listplay/zzdE77v6Mmo/2xN2duXMxmw.html',\n        u'file': u'159448201.f4v',\n        u'md5': u'140a49ed444bd22f93330985d8475fcb',\n        u'info_dict': {\n            u\"title\": u\"\u5361\u9a6c\u4e54\u56fd\u8db3\u5f00\u5927\u811a\u957f\u4f20\u51b2\u540a\u96c6\u9526\"\n        }\n    },\n    {\n        u'url': u'http://www.tudou.com/albumplay/TenTw_JgiPM/PzsAs5usU9A.html',\n        u'file': u'todo.mp4',\n        u'md5': u'todo.mp4',\n        u'info_dict': {\n            u'title': u'todo.mp4',\n        },\n        u'add_ie': [u'Youku'],\n        u'skip': u'Only works from China'\n    }]\n\n    def _url_for_id(self, id, quality = None):\n        info_url = \"http://v2.tudou.com/f?id=\"+str(id)\n        if quality:\n            info_url += '&hd' + quality\n        webpage = self._download_webpage(info_url, id, \"Opening the info webpage\")\n        final_url = self._html_search_regex('>(.+?)</f>',webpage, 'video url')\n        return final_url\n\n    def _real_extract(self, url):\n        mobj = re.match(self._VALID_URL, url)\n        video_id = mobj.group(2)\n        webpage = self._download_webpage(url, video_id)\n\n        m = re.search(r'vcode:\\s*[\\'\"](.+?)[\\'\"]', webpage)\n        if m and m.group(1):\n            return {\n                '_type': 'url',\n                'url': u'youku:' + m.group(1),\n                'ie_key': 'Youku'\n            }\n\n        title = self._search_regex(\n            r\",kw:\\s*['\\\"](.+?)[\\\"']\", webpage, u'title')\n        thumbnail_url = self._search_regex(\n            r\",pic:\\s*[\\\"'](.+?)[\\\"']\", webpage, u'thumbnail URL', fatal=False)\n\n        segs_json = self._search_regex(r'segs: \\'(.*)\\'', webpage, 'segments')\n        segments = json.loads(segs_json)\n        # It looks like the keys are the arguments that have to be passed as\n        # the hd field in the request url, we pick the higher\n        # Also, filter non-number qualities (see issue #3643).\n        quality = sorted(filter(lambda k: k.isdigit(), segments.keys()),\n                         key=lambda k: int(k))[-1]\n        parts = segments[quality]\n        result = []\n        len_parts = len(parts)\n        if len_parts > 1:\n            self.to_screen(u'%s: found %s parts' % (video_id, len_parts))\n        for part in parts:\n            part_id = part['k']\n            final_url = self._url_for_id(part_id, quality)\n            ext = (final_url.split('?')[0]).split('.')[-1]\n            part_info = {'id': part_id,\n                          'url': final_url,\n                          'ext': ext,\n                          'title': title,\n                          'thumbnail': thumbnail_url,\n                          }\n            result.append(part_info)\n\n        return result\n", "path": "youtube_dl/extractor/tudou.py"}]}