]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/zingmp3.py
0f0e9d0eb9b1ac945934b11a134d143d82b19fb0
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
14 class ZingMp3BaseInfoExtractor(InfoExtractor
):
16 def _extract_item(self
, item
, page_type
, fatal
=True):
17 error_message
= item
.get('msg')
22 '%s returned error: %s' % (self
.IE_NAME
, error_message
),
26 for quality
, source_url
in zip(item
.get('qualities') or item
.get('quality', []), item
.get('source_list') or item
.get('source', [])):
27 if not source_url
or source_url
== 'require vip':
29 if not re
.match(r
'https?://', source_url
):
30 source_url
= '//' + source_url
31 source_url
= self
._proto
_relative
_url
(source_url
, 'http:')
32 quality_num
= int_or_none(quality
)
37 if page_type
== 'video':
39 'height': quality_num
,
49 cover
= item
.get('cover')
52 'title': (item
.get('name') or item
.get('title')).strip(),
54 'thumbnail': 'http:/' + cover
if cover
else None,
55 'artist': item
.get('artist'),
58 def _extract_player_json(self
, player_json_url
, id, page_type
, playlist_title
=None):
59 player_json
= self
._download
_json
(player_json_url
, id, 'Downloading Player JSON')
60 items
= player_json
['data']
66 data
= self
._extract
_item
(items
[0], page_type
)
74 for i
, item
in enumerate(items
, 1):
75 entry
= self
._extract
_item
(item
, page_type
, fatal
=False)
78 entry
['id'] = '%s-%d' % (id, i
)
84 'title': playlist_title
,
89 class ZingMp3IE(ZingMp3BaseInfoExtractor
):
90 _VALID_URL
= r
'https?://mp3\.zing\.vn/(?:bai-hat|album|playlist|video-clip)/[^/]+/(?P<id>\w+)\.html'
92 'url': 'http://mp3.zing.vn/bai-hat/Xa-Mai-Xa-Bao-Thy/ZWZB9WAB.html',
93 'md5': 'ead7ae13693b3205cbc89536a077daed',
98 'thumbnail': 're:^https?://.*\.jpg$',
101 'url': 'http://mp3.zing.vn/video-clip/Let-It-Go-Frozen-OST-Sungha-Jung/ZW6BAEA0.html',
102 'md5': '870295a9cd8045c0e15663565902618d',
105 'title': 'Let It Go (Frozen OST)',
109 'url': 'http://mp3.zing.vn/album/Lau-Dai-Tinh-Ai-Bang-Kieu-Minh-Tuyet/ZWZBWDAF.html',
113 'title': 'Lâu Đài Tình Ái - Bằng Kiều,Minh Tuyết | Album 320 lossless',
115 'playlist_count': 10,
116 'skip': 'removed at the request of the owner',
118 'url': 'http://mp3.zing.vn/playlist/Duong-Hong-Loan-apollobee/IWCAACCB.html',
119 'only_matching': True,
122 IE_DESC
= 'mp3.zing.vn'
124 def _real_extract(self
, url
):
125 page_id
= self
._match
_id
(url
)
127 webpage
= self
._download
_webpage
(url
, page_id
)
129 player_json_url
= self
._search
_regex
([
130 r
'data-xml="([^"]+)',
131 r
'&xmlURL=([^&]+)&'
132 ], webpage
, 'player xml url')
134 playlist_title
= None
135 page_type
= self
._search
_regex
(r
'/(?:html5)?xml/([^/-]+)', player_json_url
, 'page type')
136 if page_type
== 'video':
137 player_json_url
= update_url_query(player_json_url
, {'format': 'json'})
139 player_json_url
= player_json_url
.replace('/xml/', '/html5xml/')
140 if page_type
== 'album':
141 playlist_title
= self
._og
_search
_title
(webpage
)
143 return self
._extract
_player
_json
(player_json_url
, page_id
, page_type
, playlist_title
)