[tudou] Modernize

pull/8/head
Philipp Hagemeister 10 years ago
parent 36d65b61d4
commit 8bdfddf641

@ -1,5 +1,7 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals
import re import re
import json import json
@ -9,22 +11,21 @@ from .common import InfoExtractor
class TudouIE(InfoExtractor): class TudouIE(InfoExtractor):
_VALID_URL = r'(?:http://)?(?:www\.)?tudou\.com/(?:listplay|programs|albumplay)/(?:view|(.+?))/(?:([^/]+)|([^/]+))(?:\.html)?' _VALID_URL = r'(?:http://)?(?:www\.)?tudou\.com/(?:listplay|programs|albumplay)/(?:view|(.+?))/(?:([^/]+)|([^/]+))(?:\.html)?'
_TESTS = [{ _TESTS = [{
u'url': u'http://www.tudou.com/listplay/zzdE77v6Mmo/2xN2duXMxmw.html', 'url': 'http://www.tudou.com/listplay/zzdE77v6Mmo/2xN2duXMxmw.html',
u'file': u'159448201.f4v', 'md5': '140a49ed444bd22f93330985d8475fcb',
u'md5': u'140a49ed444bd22f93330985d8475fcb', 'info_dict': {
u'info_dict': { 'id': '159448201',
u"title": u"卡马乔国足开大脚长传冲吊集锦" 'ext': 'f4v',
'title': '卡马乔国足开大脚长传冲吊集锦',
'thumbnail': 're:^https?://.*\.jpg$',
} }
}, {
'url': 'http://www.tudou.com/albumplay/TenTw_JgiPM/PzsAs5usU9A.html',
'info_dict': {
'title': 'todo.mp4',
}, },
{ 'add_ie': ['Youku'],
u'url': u'http://www.tudou.com/albumplay/TenTw_JgiPM/PzsAs5usU9A.html', 'skip': 'Only works from China'
u'file': u'todo.mp4',
u'md5': u'todo.mp4',
u'info_dict': {
u'title': u'todo.mp4',
},
u'add_ie': [u'Youku'],
u'skip': u'Only works from China'
}] }]
def _url_for_id(self, id, quality = None): def _url_for_id(self, id, quality = None):
@ -44,14 +45,14 @@ class TudouIE(InfoExtractor):
if m and m.group(1): if m and m.group(1):
return { return {
'_type': 'url', '_type': 'url',
'url': u'youku:' + m.group(1), 'url': 'youku:' + m.group(1),
'ie_key': 'Youku' 'ie_key': 'Youku'
} }
title = self._search_regex( title = self._search_regex(
r",kw:\s*['\"](.+?)[\"']", webpage, u'title') r",kw:\s*['\"](.+?)[\"']", webpage, 'title')
thumbnail_url = self._search_regex( thumbnail_url = self._search_regex(
r",pic:\s*[\"'](.+?)[\"']", webpage, u'thumbnail URL', fatal=False) r",pic:\s*[\"'](.+?)[\"']", webpage, 'thumbnail URL', fatal=False)
segs_json = self._search_regex(r'segs: \'(.*)\'', webpage, 'segments') segs_json = self._search_regex(r'segs: \'(.*)\'', webpage, 'segments')
segments = json.loads(segs_json) segments = json.loads(segs_json)
@ -67,7 +68,8 @@ class TudouIE(InfoExtractor):
part_id = part['k'] part_id = part['k']
final_url = self._url_for_id(part_id, quality) final_url = self._url_for_id(part_id, quality)
ext = (final_url.split('?')[0]).split('.')[-1] ext = (final_url.split('?')[0]).split('.')[-1]
part_info = {'id': part_id, part_info = {
'id': '%s' % part_id,
'url': final_url, 'url': final_url,
'ext': ext, 'ext': ext,
'title': title, 'title': title,

Loading…
Cancel
Save