]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/zingmp3.py
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
):
13 error_message
= item
.find('./errormessage').text
16 '%s returned error: %s' % (self
.IE_NAME
, error_message
),
19 title
= item
.find('./title').text
.strip()
20 source
= item
.find('./source').text
21 extension
= item
.attrib
['type']
22 thumbnail
= item
.find('./backimage').text
28 'thumbnail': thumbnail
,
31 def _extract_player_xml(self
, player_xml_url
, id, playlist_title
=None):
32 player_xml
= self
._download
_xml
(player_xml_url
, id, 'Downloading Player XML')
33 items
= player_xml
.findall('./item')
37 data
= self
._extract
_item
(items
[0])
45 for i
, item
in enumerate(items
, 1):
46 entry
= self
._extract
_item
(item
)
47 entry
['id'] = '%s-%d' % (id, i
)
53 'title': playlist_title
,
58 class ZingMp3SongIE(ZingMp3BaseInfoExtractor
):
59 _VALID_URL
= r
'https?://mp3\.zing\.vn/bai-hat/(?P<slug>[^/]+)/(?P<song_id>\w+)\.html'
61 'url': 'http://mp3.zing.vn/bai-hat/Xa-Mai-Xa-Bao-Thy/ZWZB9WAB.html',
62 'md5': 'ead7ae13693b3205cbc89536a077daed',
67 'thumbnail': 're:^https?://.*\.jpg$',
70 IE_NAME
= 'zingmp3:song'
71 IE_DESC
= 'mp3.zing.vn songs'
73 def _real_extract(self
, url
):
74 matched
= re
.match(self
._VALID
_URL
, url
)
75 slug
= matched
.group('slug')
76 song_id
= matched
.group('song_id')
78 webpage
= self
._download
_webpage
(
79 'http://mp3.zing.vn/bai-hat/%s/%s.html' % (slug
, song_id
), song_id
)
81 player_xml_url
= self
._search
_regex
(
82 r
'&xmlURL=(?P<xml_url>[^&]+)&', webpage
, 'player xml url')
84 return self
._extract
_player
_xml
(player_xml_url
, song_id
)
87 class ZingMp3AlbumIE(ZingMp3BaseInfoExtractor
):
88 _VALID_URL
= r
'https?://mp3\.zing\.vn/album/(?P<slug>[^/]+)/(?P<album_id>\w+)\.html'
90 'url': 'http://mp3.zing.vn/album/Lau-Dai-Tinh-Ai-Bang-Kieu-Minh-Tuyet/ZWZBWDAF.html',
94 'title': 'Lâu Đài Tình Ái - Bằng Kiều ft. Minh Tuyết | Album 320 lossless',
98 IE_NAME
= 'zingmp3:album'
99 IE_DESC
= 'mp3.zing.vn albums'
101 def _real_extract(self
, url
):
102 matched
= re
.match(self
._VALID
_URL
, url
)
103 slug
= matched
.group('slug')
104 album_id
= matched
.group('album_id')
106 webpage
= self
._download
_webpage
(
107 'http://mp3.zing.vn/album/%s/%s.html' % (slug
, album_id
), album_id
)
108 player_xml_url
= self
._search
_regex
(
109 r
'&xmlURL=(?P<xml_url>[^&]+)&', webpage
, 'player xml url')
111 return self
._extract
_player
_xml
(
112 player_xml_url
, album_id
,
113 playlist_title
=self
._og
_search
_title
(webpage
))