2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_urlparse
10 month_by_abbreviation,
15 class YamIE(InfoExtractor):
16 _VALID_URL = r'http://mymedia.yam.com/m/(?P<id>\d+)'
19 # An audio hosted on Yam
20 'url': 'http://mymedia.yam.com/m/2283921',
21 'md5': 'c011b8e262a52d5473d9c2e3c9963b9c',
25 'title': '發現 - 趙薇 京華煙雲主題曲',
26 'uploader_id': 'princekt',
27 'upload_date': '20080807',
31 # An external video hosted on YouTube
32 'url': 'http://mymedia.yam.com/m/3599430',
33 'md5': '03127cf10d8f35d120a9e8e52e3b17c6',
37 'upload_date': '20150306',
38 'uploader': '新莊社大瑜伽社',
39 'description': 'md5:11e2e405311633ace874f2e6226c8b17',
40 'uploader_id': '2323agoy',
41 'title': '20090412陽明山二子坪-1',
43 'skip': 'Video does not exist',
45 'url': 'http://mymedia.yam.com/m/3598173',
50 'skip': 'cause Yam system error',
52 'url': 'http://mymedia.yam.com/m/3599437',
57 'skip': 'invalid YouTube URL',
60 def _real_extract(self, url):
61 video_id = self._match_id(url)
62 page = self._download_webpage(url, video_id)
65 system_msg = self._html_search_regex(
66 r'系統訊息(?:<br>|\n|\r)*([^<>]+)<br>', page, 'system message',
69 raise ExtractorError(system_msg, expected=True)
71 # Is it hosted externally on YouTube?
72 youtube_url = self._html_search_regex(
73 r'<embed src="(http://www.youtube.com/[^"]+)"',
74 page, 'YouTube url', default=None)
76 return self.url_result(youtube_url, 'Youtube')
78 api_page = self._download_webpage(
79 'http://mymedia.yam.com/api/a/?pID=' + video_id, video_id,
80 note='Downloading API page')
81 api_result_obj = compat_urlparse.parse_qs(api_page)
83 uploader_id = self._html_search_regex(
84 r'<!-- 發表作者 -->:[\n ]+<a href="/([a-z]+)"',
85 page, 'uploader id', fatal=False)
86 mobj = re.search(r'<!-- 發表於 -->(?P<mon>[A-Z][a-z]{2}) ' +
87 r'(?P<day>\d{1,2}), (?P<year>\d{4})', page)
89 upload_date = '%s%02d%02d' % (
91 month_by_abbreviation(mobj.group('mon')),
92 int(mobj.group('day')))
95 duration = float_or_none(api_result_obj['totaltime'][0], scale=1000)
99 'url': api_result_obj['mp3file'][0],
100 'title': self._html_search_meta('description', page),
101 'duration': duration,
102 'uploader_id': uploader_id,
103 'upload_date': upload_date,