[zingmp3] Update for new player url
This commit is contained in:
parent
83fcf19e2d
commit
2f70366314
@ -13,75 +13,82 @@ from ..utils import (
|
|||||||
|
|
||||||
class ZingMp3BaseInfoExtractor(InfoExtractor):
|
class ZingMp3BaseInfoExtractor(InfoExtractor):
|
||||||
|
|
||||||
def _extract_item(self, item, page_type, fatal=True):
|
def _extract_item(self, item):
|
||||||
error_message = item.get('msg')
|
item_id = item.get('id')
|
||||||
if error_message:
|
if not item_id:
|
||||||
if not fatal:
|
return
|
||||||
return
|
|
||||||
raise ExtractorError(
|
item_title = (item.get('name') or item.get('title')).strip()
|
||||||
'%s returned error: %s' % (self.IE_NAME, error_message),
|
if len(item_title) < 1:
|
||||||
expected=True)
|
return
|
||||||
|
|
||||||
|
item_type = item.get('type')
|
||||||
|
if not item_type:
|
||||||
|
return
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
for quality, source_url in zip(item.get('qualities') or item.get('quality', []), item.get('source_list') or item.get('source', [])):
|
for quality, source_url in item.get('source', []).items():
|
||||||
if not source_url or source_url == 'require vip':
|
if not source_url:
|
||||||
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 = {
|
||||||
'format_id': quality,
|
'format_id': quality,
|
||||||
'url': source_url,
|
'url': source_url,
|
||||||
}
|
}
|
||||||
if page_type == 'video':
|
if item_type == 'video':
|
||||||
f.update({
|
f.update({
|
||||||
'height': quality_num,
|
'height': quality_num,
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
})
|
})
|
||||||
else:
|
elif item_type == 'audio':
|
||||||
f.update({
|
f.update({
|
||||||
'abr': quality_num,
|
'abr': quality_num,
|
||||||
'ext': 'mp3',
|
'ext': 'mp3',
|
||||||
})
|
})
|
||||||
|
else:
|
||||||
|
continue
|
||||||
formats.append(f)
|
formats.append(f)
|
||||||
|
|
||||||
cover = item.get('cover')
|
if len(formats) < 1:
|
||||||
|
return
|
||||||
|
|
||||||
|
thumbnail = item.get('thumbnail')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'title': (item.get('name') or item.get('title')).strip(),
|
'id': item_id,
|
||||||
|
'title': item_title,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'thumbnail': 'http:/' + cover if cover else None,
|
'thumbnail': thumbnail if thumbnail else None,
|
||||||
'artist': item.get('artist'),
|
'artist': item.get('artist'),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _extract_player_json(self, player_json_url, id, page_type, playlist_title=None):
|
def _extract_player_json(self, url, player_json_url, id, title=None):
|
||||||
player_json = self._download_json(player_json_url, id, 'Downloading Player JSON')
|
player_json = self._download_json(
|
||||||
items = player_json['data']
|
player_json_url, id, 'Downloading Player JSON',
|
||||||
if 'item' in items:
|
headers={'Referer': url})
|
||||||
items = items['item']
|
|
||||||
|
items = [player_json['data']]
|
||||||
|
if 'items' in items[0]:
|
||||||
|
items = items[0]['items']
|
||||||
|
|
||||||
if len(items) == 1:
|
if len(items) == 1:
|
||||||
# one single song
|
# audio/video
|
||||||
data = self._extract_item(items[0], page_type)
|
return self._extract_item(items[0])
|
||||||
data['id'] = id
|
|
||||||
|
|
||||||
return data
|
|
||||||
else:
|
else:
|
||||||
# playlist of songs
|
# album/playlist
|
||||||
entries = []
|
entries = []
|
||||||
|
|
||||||
for i, item in enumerate(items, 1):
|
for i, item in enumerate(items, 1):
|
||||||
entry = self._extract_item(item, page_type, fatal=False)
|
entry = self._extract_item(item)
|
||||||
if not entry:
|
if not entry:
|
||||||
continue
|
continue
|
||||||
entry['id'] = '%s-%d' % (id, i)
|
|
||||||
entries.append(entry)
|
entries.append(entry)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'_type': 'playlist',
|
'_type': 'playlist',
|
||||||
'id': id,
|
'id': id,
|
||||||
'title': playlist_title,
|
'title': title,
|
||||||
'entries': entries,
|
'entries': entries,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +106,7 @@ class ZingMp3IE(ZingMp3BaseInfoExtractor):
|
|||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
'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': 'c04f2c8c6400d90b43dd0fa6485e2e32',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'ZW6BAEA0',
|
'id': 'ZW6BAEA0',
|
||||||
'title': 'Let It Go (Frozen OST)',
|
'title': 'Let It Go (Frozen OST)',
|
||||||
@ -110,13 +117,17 @@ class ZingMp3IE(ZingMp3BaseInfoExtractor):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'_type': 'playlist',
|
'_type': 'playlist',
|
||||||
'id': 'ZWZBWDAF',
|
'id': 'ZWZBWDAF',
|
||||||
'title': 'Lâu Đài Tình Ái - Bằng Kiều,Minh Tuyết | Album 320 lossless',
|
'title': 'Lâu Đài Tình Ái - Bằng Kiều | Zing MP3',
|
||||||
},
|
},
|
||||||
'playlist_count': 10,
|
'playlist_count': 10,
|
||||||
'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/Sofm-s-playlist-louissofm/IWE606EA.html',
|
||||||
'only_matching': True,
|
'info_dict': {
|
||||||
|
'_type': 'playlist',
|
||||||
|
'id': 'IWE606EA',
|
||||||
|
'title': 'Sofm\'s playlist - | Zing MP3',
|
||||||
|
},
|
||||||
|
'playlist_count': 98,
|
||||||
}]
|
}]
|
||||||
IE_NAME = 'zingmp3'
|
IE_NAME = 'zingmp3'
|
||||||
IE_DESC = 'mp3.zing.vn'
|
IE_DESC = 'mp3.zing.vn'
|
||||||
@ -126,18 +137,13 @@ class ZingMp3IE(ZingMp3BaseInfoExtractor):
|
|||||||
|
|
||||||
webpage = self._download_webpage(url, page_id)
|
webpage = self._download_webpage(url, page_id)
|
||||||
|
|
||||||
player_json_url = self._search_regex([
|
player_url = self._search_regex([
|
||||||
r'data-xml="([^"]+)',
|
r'data-xml="([^"]+)',
|
||||||
r'&xmlURL=([^&]+)&'
|
r'&xmlURL=([^&]+)&',
|
||||||
], webpage, 'player xml url')
|
r'xmlurl: \'([^\']+)\''
|
||||||
|
], webpage, 'player url')
|
||||||
|
|
||||||
playlist_title = None
|
title = self._og_search_title(webpage)
|
||||||
page_type = self._search_regex(r'/(?:html5)?xml/([^/-]+)', player_json_url, 'page type')
|
player_url_full = 'https://mp3.zing.vn/xhr' + player_url
|
||||||
if page_type == 'video':
|
|
||||||
player_json_url = update_url_query(player_json_url, {'format': 'json'})
|
|
||||||
else:
|
|
||||||
player_json_url = player_json_url.replace('/xml/', '/html5xml/')
|
|
||||||
if page_type == 'album':
|
|
||||||
playlist_title = self._og_search_title(webpage)
|
|
||||||
|
|
||||||
return self._extract_player_json(player_json_url, page_id, page_type, playlist_title)
|
return self._extract_player_json(url, player_url_full, page_id, title)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user