2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_urlparse
10 month_by_abbreviation,
12 get_element_by_attribute,
16 class YamIE(InfoExtractor):
17 IE_DESC = '蕃薯藤yam天空部落'
18 _VALID_URL = r'https?://mymedia.yam.com/m/(?P<id>\d+)'
21 # An audio hosted on Yam
22 'url': 'http://mymedia.yam.com/m/2283921',
23 'md5': 'c011b8e262a52d5473d9c2e3c9963b9c',
27 'title': '發現 - 趙薇 京華煙雲主題曲',
28 'description': '發現 - 趙薇 京華煙雲主題曲',
29 'uploader_id': 'princekt',
30 'upload_date': '20080807',
34 # An external video hosted on YouTube
35 'url': 'http://mymedia.yam.com/m/3599430',
36 'md5': '03127cf10d8f35d120a9e8e52e3b17c6',
40 'upload_date': '20150306',
41 'uploader': '新莊社大瑜伽社',
42 'description': 'md5:11e2e405311633ace874f2e6226c8b17',
43 'uploader_id': '2323agoy',
44 'title': '20090412陽明山二子坪-1',
46 'skip': 'Video does not exist',
48 'url': 'http://mymedia.yam.com/m/3598173',
53 'skip': 'cause Yam system error',
55 'url': 'http://mymedia.yam.com/m/3599437',
60 'skip': 'invalid YouTube URL',
62 'url': 'http://mymedia.yam.com/m/2373534',
63 'md5': '7ff74b91b7a817269d83796f8c5890b1',
67 'title': '林俊傑&蔡卓妍-小酒窩',
68 'description': 'md5:904003395a0fcce6cfb25028ff468420',
69 'upload_date': '20080928',
70 'uploader_id': 'onliner2',
74 def _real_extract(self, url):
75 video_id = self._match_id(url)
76 page = self._download_webpage(url, video_id)
79 system_msg = self._html_search_regex(
80 r'系統訊息(?:<br>|\n|\r)*([^<>]+)<br>', page, 'system message',
83 raise ExtractorError(system_msg, expected=True)
85 # Is it hosted externally on YouTube?
86 youtube_url = self._html_search_regex(
87 r'<embed src="(http://www.youtube.com/[^"]+)"',
88 page, 'YouTube url', default=None)
90 return self.url_result(youtube_url, 'Youtube')
92 title = self._html_search_regex(
93 r'<h1[^>]+class="heading"[^>]*>\s*(.+)\s*</h1>', page, 'title')
95 api_page = self._download_webpage(
96 'http://mymedia.yam.com/api/a/?pID=' + video_id, video_id,
97 note='Downloading API page')
98 api_result_obj = compat_urlparse.parse_qs(api_page)
100 info_table = get_element_by_attribute('class', 'info', page)
101 uploader_id = self._html_search_regex(
102 r'<!-- 發表作者 -->:[\n ]+<a href="/([a-z0-9]+)"',
103 info_table, 'uploader id', fatal=False)
104 mobj = re.search(r'<!-- 發表於 -->(?P<mon>[A-Z][a-z]{2})\s+' +
105 r'(?P<day>\d{1,2}), (?P<year>\d{4})', page)
107 upload_date = '%s%02d%02d' % (
109 month_by_abbreviation(mobj.group('mon')),
110 int(mobj.group('day')))
113 duration = float_or_none(api_result_obj['totaltime'][0], scale=1000)
117 'url': api_result_obj['mp3file'][0],
119 'description': self._html_search_meta('description', page),
120 'duration': duration,
121 'uploader_id': uploader_id,
122 'upload_date': upload_date,