mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-12-04 14:27:53 +01:00
[zingmp3] Update extractor
This commit is contained in:
parent
79367a9820
commit
dd114e5e8e
@ -23,11 +23,11 @@ class ZingMp3BaseInfoExtractor(InfoExtractor):
|
|||||||
expected=True)
|
expected=True)
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
for quality, source_url in zip(item.get('qualities') or item.get('quality', []), item.get('source_list') or item.get('source', [])):
|
sources = item.get('source', {})
|
||||||
|
for (quality, source_url) in sources.items():
|
||||||
if not source_url or source_url == 'require vip':
|
if not source_url or source_url == 'require vip':
|
||||||
continue
|
continue
|
||||||
if not re.match(r'https?://', source_url):
|
|
||||||
source_url = '//' + source_url
|
|
||||||
source_url = self._proto_relative_url(source_url, 'http:')
|
source_url = self._proto_relative_url(source_url, 'http:')
|
||||||
quality_num = int_or_none(quality)
|
quality_num = int_or_none(quality)
|
||||||
f = {
|
f = {
|
||||||
@ -46,36 +46,46 @@ class ZingMp3BaseInfoExtractor(InfoExtractor):
|
|||||||
})
|
})
|
||||||
formats.append(f)
|
formats.append(f)
|
||||||
|
|
||||||
cover = item.get('cover')
|
artist = None
|
||||||
|
try:
|
||||||
|
artist = item['artist']['name']
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if page_type == 'album':
|
||||||
|
return {
|
||||||
|
'id': item.get('id'),
|
||||||
|
'track_id': item.get('id'),
|
||||||
|
'artist': artist,
|
||||||
|
'title': (item.get('name') or item.get('title')).strip(),
|
||||||
|
'track': (item.get('name') or item.get('title')).strip(),
|
||||||
|
'track_number': int_or_none(item.get('order')),
|
||||||
|
'formats': formats,
|
||||||
|
'thumbnail': item.get('thumbnail'),
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
'id': item.get('id'),
|
||||||
|
'artist': artist,
|
||||||
'title': (item.get('name') or item.get('title')).strip(),
|
'title': (item.get('name') or item.get('title')).strip(),
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'thumbnail': 'http:/' + cover if cover else None,
|
'thumbnail': item.get('thumbnail'),
|
||||||
'artist': item.get('artist'),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def _extract_player_json(self, player_json_url, id, page_type, playlist_title=None):
|
def _extract_player_json(self, player_json_url, id, page_type, playlist_title=None):
|
||||||
player_json = self._download_json(player_json_url, id, 'Downloading Player JSON')
|
player_json = self._download_json(player_json_url, id, 'Downloading Player JSON')
|
||||||
items = player_json['data']
|
if 'items' not in player_json['data']:
|
||||||
if 'item' in items:
|
item = player_json['data']
|
||||||
items = items['item']
|
data = self._extract_item(item, page_type)
|
||||||
|
|
||||||
if len(items) == 1:
|
|
||||||
# one single song
|
|
||||||
data = self._extract_item(items[0], page_type)
|
|
||||||
data['id'] = id
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# playlist of songs
|
# playlist of songs
|
||||||
entries = []
|
entries = []
|
||||||
|
for i, item in enumerate(player_json['data']['items'], 1):
|
||||||
for i, item in enumerate(items, 1):
|
|
||||||
entry = self._extract_item(item, page_type, fatal=False)
|
entry = self._extract_item(item, page_type, fatal=False)
|
||||||
if not entry:
|
if not entry:
|
||||||
continue
|
continue
|
||||||
entry['id'] = '%s-%d' % (id, i)
|
|
||||||
entries.append(entry)
|
entries.append(entry)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -88,16 +98,19 @@ class ZingMp3BaseInfoExtractor(InfoExtractor):
|
|||||||
|
|
||||||
class ZingMp3IE(ZingMp3BaseInfoExtractor):
|
class ZingMp3IE(ZingMp3BaseInfoExtractor):
|
||||||
_VALID_URL = r'https?://mp3\.zing\.vn/(?:bai-hat|album|playlist|video-clip)/[^/]+/(?P<id>\w+)\.html'
|
_VALID_URL = r'https?://mp3\.zing\.vn/(?:bai-hat|album|playlist|video-clip)/[^/]+/(?P<id>\w+)\.html'
|
||||||
_TESTS = [{
|
_TESTS = [
|
||||||
|
{
|
||||||
'url': 'http://mp3.zing.vn/bai-hat/Xa-Mai-Xa-Bao-Thy/ZWZB9WAB.html',
|
'url': 'http://mp3.zing.vn/bai-hat/Xa-Mai-Xa-Bao-Thy/ZWZB9WAB.html',
|
||||||
'md5': 'ead7ae13693b3205cbc89536a077daed',
|
'md5': 'ead7ae13693b3205cbc89536a077daed',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'ZWZB9WAB',
|
'id': 'ZWZB9WAB',
|
||||||
'title': 'Xa Mãi Xa',
|
'title': 'Xa Mãi Xa',
|
||||||
|
'artist': 'Bảo Thy',
|
||||||
'ext': 'mp3',
|
'ext': 'mp3',
|
||||||
'thumbnail': r're:^https?://.*\.jpg$',
|
'thumbnail': r're:^https?://.*\.jpg$',
|
||||||
},
|
},
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
'url': 'http://mp3.zing.vn/video-clip/Let-It-Go-Frozen-OST-Sungha-Jung/ZW6BAEA0.html',
|
'url': 'http://mp3.zing.vn/video-clip/Let-It-Go-Frozen-OST-Sungha-Jung/ZW6BAEA0.html',
|
||||||
'md5': '870295a9cd8045c0e15663565902618d',
|
'md5': '870295a9cd8045c0e15663565902618d',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
@ -105,19 +118,21 @@ class ZingMp3IE(ZingMp3BaseInfoExtractor):
|
|||||||
'title': 'Let It Go (Frozen OST)',
|
'title': 'Let It Go (Frozen OST)',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
},
|
},
|
||||||
}, {
|
},
|
||||||
'url': 'http://mp3.zing.vn/album/Lau-Dai-Tinh-Ai-Bang-Kieu-Minh-Tuyet/ZWZBWDAF.html',
|
{
|
||||||
|
'url': 'https://mp3.zing.vn/album/Con-Trong-Ky-Niem-Le-Quyen/ZWZCO9UW.html',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'_type': 'playlist',
|
'_type': 'playlist',
|
||||||
'id': 'ZWZBWDAF',
|
'id': 'ZWZCO9UW',
|
||||||
'title': 'Lâu Đài Tình Ái - Bằng Kiều,Minh Tuyết | Album 320 lossless',
|
'title': 'Còn Trong Kỷ Niệm - Lệ Quyên | Zing MP3',
|
||||||
},
|
},
|
||||||
'playlist_count': 10,
|
'playlist_count': 9,
|
||||||
'skip': 'removed at the request of the owner',
|
},
|
||||||
}, {
|
{
|
||||||
'url': 'http://mp3.zing.vn/playlist/Duong-Hong-Loan-apollobee/IWCAACCB.html',
|
'url': 'http://mp3.zing.vn/playlist/Duong-Hong-Loan-apollobee/IWCAACCB.html',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
}]
|
},
|
||||||
|
]
|
||||||
IE_NAME = 'zingmp3'
|
IE_NAME = 'zingmp3'
|
||||||
IE_DESC = 'mp3.zing.vn'
|
IE_DESC = 'mp3.zing.vn'
|
||||||
|
|
||||||
@ -130,9 +145,10 @@ class ZingMp3IE(ZingMp3BaseInfoExtractor):
|
|||||||
r'data-xml="([^"]+)',
|
r'data-xml="([^"]+)',
|
||||||
r'&xmlURL=([^&]+)&'
|
r'&xmlURL=([^&]+)&'
|
||||||
], webpage, 'player xml url')
|
], webpage, 'player xml url')
|
||||||
|
player_json_url = "https://mp3.zing.vn/xhr" + player_json_url
|
||||||
|
|
||||||
playlist_title = None
|
playlist_title = None
|
||||||
page_type = self._search_regex(r'/(?:html5)?xml/([^/-]+)', player_json_url, 'page type')
|
page_type = self._search_regex(r'type=([\w]+)', player_json_url, 'page type')
|
||||||
if page_type == 'video':
|
if page_type == 'video':
|
||||||
player_json_url = update_url_query(player_json_url, {'format': 'json'})
|
player_json_url = update_url_query(player_json_url, {'format': 'json'})
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user