]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/zingmp3.py
437eecb6737161c9d730bf9a93eaed1bdb541799
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..utils
import ExtractorError
10 class ZingMp3BaseInfoExtractor(InfoExtractor
):
12 def _extract_item(self
, item
, fatal
=True):
13 error_message
= item
.find('./errormessage').text
18 '%s returned error: %s' % (self
.IE_NAME
, error_message
),
21 title
= item
.find('./title').text
.strip()
22 source
= item
.find('./source').text
23 extension
= item
.attrib
['type']
24 thumbnail
= item
.find('./backimage').text
30 'thumbnail': thumbnail
,
33 def _extract_player_xml(self
, player_xml_url
, id, playlist_title
=None):
34 player_xml
= self
._download
_xml
(player_xml_url
, id, 'Downloading Player XML')
35 items
= player_xml
.findall('./item')
39 data
= self
._extract
_item
(items
[0])
47 for i
, item
in enumerate(items
, 1):
48 entry
= self
._extract
_item
(item
, fatal
=False)
51 entry
['id'] = '%s-%d' % (id, i
)
57 'title': playlist_title
,
62 class ZingMp3SongIE(ZingMp3BaseInfoExtractor
):
63 _VALID_URL
= r
'https?://mp3\.zing\.vn/bai-hat/(?P<slug>[^/]+)/(?P<song_id>\w+)\.html'
65 'url': 'http://mp3.zing.vn/bai-hat/Xa-Mai-Xa-Bao-Thy/ZWZB9WAB.html',
66 'md5': 'ead7ae13693b3205cbc89536a077daed',
71 'thumbnail': 're:^https?://.*\.jpg$',
74 IE_NAME
= 'zingmp3:song'
75 IE_DESC
= 'mp3.zing.vn songs'
77 def _real_extract(self
, url
):
78 matched
= re
.match(self
._VALID
_URL
, url
)
79 slug
= matched
.group('slug')
80 song_id
= matched
.group('song_id')
82 webpage
= self
._download
_webpage
(
83 'http://mp3.zing.vn/bai-hat/%s/%s.html' % (slug
, song_id
), song_id
)
85 player_xml_url
= self
._search
_regex
(
86 r
'&xmlURL=(?P<xml_url>[^&]+)&', webpage
, 'player xml url')
88 return self
._extract
_player
_xml
(player_xml_url
, song_id
)
91 class ZingMp3AlbumIE(ZingMp3BaseInfoExtractor
):
92 _VALID_URL
= r
'https?://mp3\.zing\.vn/(?:album|playlist)/(?P<slug>[^/]+)/(?P<album_id>\w+)\.html'
94 'url': 'http://mp3.zing.vn/album/Lau-Dai-Tinh-Ai-Bang-Kieu-Minh-Tuyet/ZWZBWDAF.html',
98 'title': 'Lâu Đài Tình Ái - Bằng Kiều ft. Minh Tuyết | Album 320 lossless',
100 'playlist_count': 10,
102 'url': 'http://mp3.zing.vn/playlist/Duong-Hong-Loan-apollobee/IWCAACCB.html',
103 'only_matching': True,
105 IE_NAME
= 'zingmp3:album'
106 IE_DESC
= 'mp3.zing.vn albums'
108 def _real_extract(self
, url
):
109 matched
= re
.match(self
._VALID
_URL
, url
)
110 slug
= matched
.group('slug')
111 album_id
= matched
.group('album_id')
113 webpage
= self
._download
_webpage
(
114 'http://mp3.zing.vn/album/%s/%s.html' % (slug
, album_id
), album_id
)
115 player_xml_url
= self
._search
_regex
(
116 r
'&xmlURL=(?P<xml_url>[^&]+)&', webpage
, 'player xml url')
118 return self
._extract
_player
_xml
(
119 player_xml_url
, album_id
,
120 playlist_title
=self
._og
_search
_title
(webpage
))