]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/yam.py
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 _VALID_URL
= r
'http://mymedia.yam.com/m/(?P<id>\d+)'
20 # An audio hosted on Yam
21 'url': 'http://mymedia.yam.com/m/2283921',
22 'md5': 'c011b8e262a52d5473d9c2e3c9963b9c',
26 'title': '發現 - 趙薇 京華煙雲主題曲',
27 'description': '發現 - 趙薇 京華煙雲主題曲',
28 'uploader_id': 'princekt',
29 'upload_date': '20080807',
33 # An external video hosted on YouTube
34 'url': 'http://mymedia.yam.com/m/3599430',
35 'md5': '03127cf10d8f35d120a9e8e52e3b17c6',
39 'upload_date': '20150306',
40 'uploader': '新莊社大瑜伽社',
41 'description': 'md5:11e2e405311633ace874f2e6226c8b17',
42 'uploader_id': '2323agoy',
43 'title': '20090412陽明山二子坪-1',
45 'skip': 'Video does not exist',
47 'url': 'http://mymedia.yam.com/m/3598173',
52 'skip': 'cause Yam system error',
54 'url': 'http://mymedia.yam.com/m/3599437',
59 'skip': 'invalid YouTube URL',
61 'url': 'http://mymedia.yam.com/m/2373534',
62 'md5': '7ff74b91b7a817269d83796f8c5890b1',
66 'title': '林俊傑&蔡卓妍-小酒窩',
67 'description': 'md5:904003395a0fcce6cfb25028ff468420',
68 'upload_date': '20080928',
69 'uploader_id': 'onliner2',
73 def _real_extract(self
, url
):
74 video_id
= self
._match
_id
(url
)
75 page
= self
._download
_webpage
(url
, video_id
)
78 system_msg
= self
._html
_search
_regex
(
79 r
'系統訊息(?:<br>|\n|\r)*([^<>]+)<br>', page
, 'system message',
82 raise ExtractorError(system_msg
, expected
=True)
84 # Is it hosted externally on YouTube?
85 youtube_url
= self
._html
_search
_regex
(
86 r
'<embed src="(http://www.youtube.com/[^"]+)"',
87 page
, 'YouTube url', default
=None)
89 return self
.url_result(youtube_url
, 'Youtube')
91 title
= self
._html
_search
_regex
(
92 r
'<h1[^>]+class="heading"[^>]*>\s*(.+)\s*</h1>', page
, 'title')
94 api_page
= self
._download
_webpage
(
95 'http://mymedia.yam.com/api/a/?pID=' + video_id
, video_id
,
96 note
='Downloading API page')
97 api_result_obj
= compat_urlparse
.parse_qs(api_page
)
99 info_table
= get_element_by_attribute('class', 'info', page
)
100 uploader_id
= self
._html
_search
_regex
(
101 r
'<!-- 發表作者 -->:[\n ]+<a href="/([a-z0-9]+)"',
102 info_table
, 'uploader id', fatal
=False)
103 mobj
= re
.search(r
'<!-- 發表於 -->(?P<mon>[A-Z][a-z]{2})\s+' +
104 r
'(?P<day>\d{1,2}), (?P<year>\d{4})', page
)
106 upload_date
= '%s%02d%02d' % (
108 month_by_abbreviation(mobj
.group('mon')),
109 int(mobj
.group('day')))
112 duration
= float_or_none(api_result_obj
['totaltime'][0], scale
=1000)
116 'url': api_result_obj
['mp3file'][0],
118 'description': self
._html
_search
_meta
('description', page
),
119 'duration': duration
,
120 'uploader_id': uploader_id
,
121 'upload_date': upload_date
,