From 2f703663149eb818696a10710d9f2cade7e84f36 Mon Sep 17 00:00:00 2001 From: Dao Hoang Son Date: Tue, 3 Jan 2017 17:03:15 +0700 Subject: [PATCH 1/3] [zingmp3] Update for new player url --- youtube_dl/extractor/zingmp3.py | 102 +++++++++++++++++--------------- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/youtube_dl/extractor/zingmp3.py b/youtube_dl/extractor/zingmp3.py index adfdcaabf..9f2a5ac9d 100644 --- a/youtube_dl/extractor/zingmp3.py +++ b/youtube_dl/extractor/zingmp3.py @@ -13,75 +13,82 @@ from ..utils import ( class ZingMp3BaseInfoExtractor(InfoExtractor): - def _extract_item(self, item, page_type, fatal=True): - error_message = item.get('msg') - if error_message: - if not fatal: - return - raise ExtractorError( - '%s returned error: %s' % (self.IE_NAME, error_message), - expected=True) + def _extract_item(self, item): + item_id = item.get('id') + if not item_id: + return + + item_title = (item.get('name') or item.get('title')).strip() + if len(item_title) < 1: + return + + item_type = item.get('type') + if not item_type: + return formats = [] - for quality, source_url in zip(item.get('qualities') or item.get('quality', []), item.get('source_list') or item.get('source', [])): - if not source_url or source_url == 'require vip': + for quality, source_url in item.get('source', []).items(): + if not source_url: continue - if not re.match(r'https?://', source_url): - source_url = '//' + source_url source_url = self._proto_relative_url(source_url, 'http:') quality_num = int_or_none(quality) f = { 'format_id': quality, 'url': source_url, } - if page_type == 'video': + if item_type == 'video': f.update({ 'height': quality_num, 'ext': 'mp4', }) - else: + elif item_type == 'audio': f.update({ 'abr': quality_num, 'ext': 'mp3', }) + else: + continue formats.append(f) - cover = item.get('cover') + if len(formats) < 1: + return + + thumbnail = item.get('thumbnail') return { - 'title': (item.get('name') or item.get('title')).strip(), + 'id': item_id, + 'title': item_title, 'formats': formats, - 'thumbnail': 'http:/' + cover if cover else None, + 'thumbnail': thumbnail if thumbnail else None, 'artist': item.get('artist'), } - 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') - items = player_json['data'] - if 'item' in items: - items = items['item'] + def _extract_player_json(self, url, player_json_url, id, title=None): + player_json = self._download_json( + player_json_url, id, 'Downloading Player JSON', + headers={'Referer': url}) + + items = [player_json['data']] + if 'items' in items[0]: + items = items[0]['items'] if len(items) == 1: - # one single song - data = self._extract_item(items[0], page_type) - data['id'] = id - - return data + # audio/video + return self._extract_item(items[0]) else: - # playlist of songs + # album/playlist entries = [] for i, item in enumerate(items, 1): - entry = self._extract_item(item, page_type, fatal=False) + entry = self._extract_item(item) if not entry: continue - entry['id'] = '%s-%d' % (id, i) entries.append(entry) return { '_type': 'playlist', 'id': id, - 'title': playlist_title, + 'title': title, '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', - 'md5': '870295a9cd8045c0e15663565902618d', + 'md5': 'c04f2c8c6400d90b43dd0fa6485e2e32', 'info_dict': { 'id': 'ZW6BAEA0', 'title': 'Let It Go (Frozen OST)', @@ -110,13 +117,17 @@ class ZingMp3IE(ZingMp3BaseInfoExtractor): 'info_dict': { '_type': 'playlist', '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, - 'skip': 'removed at the request of the owner', }, { - 'url': 'http://mp3.zing.vn/playlist/Duong-Hong-Loan-apollobee/IWCAACCB.html', - 'only_matching': True, + 'url': 'http://mp3.zing.vn/playlist/Sofm-s-playlist-louissofm/IWE606EA.html', + 'info_dict': { + '_type': 'playlist', + 'id': 'IWE606EA', + 'title': 'Sofm\'s playlist - | Zing MP3', + }, + 'playlist_count': 98, }] IE_NAME = 'zingmp3' IE_DESC = 'mp3.zing.vn' @@ -126,18 +137,13 @@ class ZingMp3IE(ZingMp3BaseInfoExtractor): webpage = self._download_webpage(url, page_id) - player_json_url = self._search_regex([ + player_url = self._search_regex([ r'data-xml="([^"]+)', - r'&xmlURL=([^&]+)&' - ], webpage, 'player xml url') + r'&xmlURL=([^&]+)&', + r'xmlurl: \'([^\']+)\'' + ], webpage, 'player url') - playlist_title = None - page_type = self._search_regex(r'/(?:html5)?xml/([^/-]+)', player_json_url, 'page type') - 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) + title = self._og_search_title(webpage) + player_url_full = 'https://mp3.zing.vn/xhr' + player_url - 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) From ce05232547afbcaa83b1900c00e58e1f45337e88 Mon Sep 17 00:00:00 2001 From: Dao Hoang Son Date: Tue, 17 Oct 2017 15:21:37 +0700 Subject: [PATCH 2/3] [zingmp3] Change test data at the request of the owner --- youtube_dl/extractor/zingmp3.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/youtube_dl/extractor/zingmp3.py b/youtube_dl/extractor/zingmp3.py index 9f2a5ac9d..0a4f2df55 100644 --- a/youtube_dl/extractor/zingmp3.py +++ b/youtube_dl/extractor/zingmp3.py @@ -113,13 +113,13 @@ class ZingMp3IE(ZingMp3BaseInfoExtractor): 'ext': 'mp4', }, }, { - 'url': 'http://mp3.zing.vn/album/Lau-Dai-Tinh-Ai-Bang-Kieu-Minh-Tuyet/ZWZBWDAF.html', + 'url': 'https://mp3.zing.vn/album/Nhung-Bai-Hat-Hay-Nhat-Cua-Bang-Kieu-Bang-Kieu/ZWZ9DAEI.html', 'info_dict': { '_type': 'playlist', - 'id': 'ZWZBWDAF', - 'title': 'Lâu Đài Tình Ái - Bằng Kiều | Zing MP3', + 'id': 'ZWZ9DAEI', + 'title': 'Những Bài Hát Hay Nhất Của Bằng Kiều - Bằng Kiều | Zing MP3', }, - 'playlist_count': 10, + 'playlist_count': 39, }, { 'url': 'http://mp3.zing.vn/playlist/Sofm-s-playlist-louissofm/IWE606EA.html', 'info_dict': { From cd6e56697a216785229727b728e66d50daf09497 Mon Sep 17 00:00:00 2001 From: Dao Hoang Son Date: Tue, 17 Oct 2017 15:39:56 +0700 Subject: [PATCH 3/3] [zingmp3] Fix for flake8 --- youtube_dl/extractor/zingmp3.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/youtube_dl/extractor/zingmp3.py b/youtube_dl/extractor/zingmp3.py index 0a4f2df55..4eafbf3a0 100644 --- a/youtube_dl/extractor/zingmp3.py +++ b/youtube_dl/extractor/zingmp3.py @@ -1,13 +1,9 @@ # coding: utf-8 from __future__ import unicode_literals -import re - from .common import InfoExtractor from ..utils import ( - ExtractorError, int_or_none, - update_url_query, )