2 from __future__ import unicode_literals
4 from .common import InfoExtractor
11 class ZingMp3BaseIE(InfoExtractor):
12 _VALID_URL_TMPL = r'https?://(?:mp3\.zing|zingmp3)\.vn/(?:%s)/[^/]+/(?P<id>\w+)\.html'
13 _GEO_COUNTRIES = ['VN']
15 def _extract_item(self, item, fatal):
17 title = item.get('name') or item['title']
20 for k, v in (item.get('source') or {}).items():
23 if k in ('mp4', 'hls'):
24 for res, video_url in v.items():
28 formats.extend(self._extract_m3u8_formats(
29 video_url, item_id, 'mp4',
30 'm3u8_native', m3u8_id=k, fatal=False))
33 'format_id': 'mp4-' + res,
35 'height': int_or_none(self._search_regex(
36 r'^(\d+)p', res, 'resolution', default=None)),
42 'tbr': int_or_none(k),
43 'url': self._proto_relative_url(v),
50 if msg == 'Sorry, this content is not available in your country.':
51 self.raise_geo_restricted(countries=self._GEO_COUNTRIES)
52 raise ExtractorError(msg, expected=True)
53 self._sort_formats(formats)
56 lyric = item.get('lyric')
64 album = item.get('album') or {}
70 'thumbnail': item.get('thumbnail'),
71 'subtitles': subtitles,
72 'duration': int_or_none(item.get('duration')),
74 'artist': item.get('artists_names'),
75 'album': album.get('name') or album.get('title'),
76 'album_artist': album.get('artists_names'),
79 def _real_extract(self, url):
80 page_id = self._match_id(url)
81 webpage = self._download_webpage(
82 url.replace('://zingmp3.vn/', '://mp3.zing.vn/'),
83 page_id, query={'play_song': 1})
84 data_path = self._search_regex(
85 r'data-xml="([^"]+)', webpage, 'data path')
86 return self._process_data(self._download_json(
87 'https://mp3.zing.vn/xhr' + data_path, page_id)['data'])
90 class ZingMp3IE(ZingMp3BaseIE):
91 _VALID_URL = ZingMp3BaseIE._VALID_URL_TMPL % 'bai-hat|video-clip'
93 'url': 'http://mp3.zing.vn/bai-hat/Xa-Mai-Xa-Bao-Thy/ZWZB9WAB.html',
94 'md5': 'ead7ae13693b3205cbc89536a077daed',
99 'thumbnail': r're:^https?://.+\.jpg',
106 'track': 'Xa Mãi Xa',
108 'album': 'Special Album',
109 'album_artist': 'Bảo Thy',
112 'url': 'https://mp3.zing.vn/video-clip/Suong-Hoa-Dua-Loi-K-ICM-RYO/ZO8ZF7C7.html',
113 'md5': 'e9c972b693aa88301ef981c8151c4343',
116 'title': 'Sương Hoa Đưa Lối',
118 'thumbnail': r're:^https?://.+\.jpg',
120 'track': 'Sương Hoa Đưa Lối',
121 'artist': 'K-ICM, RYO',
124 'url': 'https://zingmp3.vn/bai-hat/Xa-Mai-Xa-Bao-Thy/ZWZB9WAB.html',
125 'only_matching': True,
128 IE_DESC = 'mp3.zing.vn'
130 def _process_data(self, data):
131 return self._extract_item(data, True)
134 class ZingMp3AlbumIE(ZingMp3BaseIE):
135 _VALID_URL = ZingMp3BaseIE._VALID_URL_TMPL % 'album|playlist'
137 'url': 'http://mp3.zing.vn/album/Lau-Dai-Tinh-Ai-Bang-Kieu-Minh-Tuyet/ZWZBWDAF.html',
141 'title': 'Lâu Đài Tình Ái',
143 'playlist_count': 10,
145 'url': 'http://mp3.zing.vn/playlist/Duong-Hong-Loan-apollobee/IWCAACCB.html',
146 'only_matching': True,
148 'url': 'https://zingmp3.vn/album/Lau-Dai-Tinh-Ai-Bang-Kieu-Minh-Tuyet/ZWZBWDAF.html',
149 'only_matching': True,
151 IE_NAME = 'zingmp3:album'
153 def _process_data(self, data):
155 for item in (data.get('items') or []):
156 entry = self._extract_item(item, False)
159 info = data.get('info') or {}
160 return self.playlist_result(
161 entries(), info.get('id'), info.get('name') or info.get('title'))