]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/zingmp3.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
9 class ZingMp3BaseInfoExtractor(InfoExtractor
):
12 def _extract_item(item
):
13 title
= item
.find('./title').text
.strip()
14 source
= item
.find('./source').text
15 extension
= item
.attrib
['type']
16 thumbnail
= item
.find('./backimage').text
22 'thumbnail': thumbnail
,
25 def _extract_player_xml(self
, player_xml_url
, id, playlist_title
=None):
26 player_xml
= self
._download
_xml
(player_xml_url
, id, 'Downloading Player XML')
27 items
= player_xml
.findall('./item')
31 data
= self
._extract
_item
(items
[0])
39 for i
, item
in enumerate(items
, 1):
40 entry
= self
._extract
_item
(item
)
41 entry
['id'] = '%s-%d' % (id, i
)
47 'title': playlist_title
,
52 class ZingMp3SongIE(ZingMp3BaseInfoExtractor
):
53 _VALID_URL
= r
'https?://mp3\.zing\.vn/bai-hat/(?P<slug>[^/]+)/(?P<song_id>\w+)\.html'
55 'url': 'http://mp3.zing.vn/bai-hat/Xa-Mai-Xa-Bao-Thy/ZWZB9WAB.html',
56 'md5': 'ead7ae13693b3205cbc89536a077daed',
61 'thumbnail': 're:^https?://.*\.jpg$',
64 IE_NAME
= 'zingmp3:song'
65 IE_DESC
= 'mp3.zing.vn songs'
67 def _real_extract(self
, url
):
68 matched
= re
.match(self
._VALID
_URL
, url
)
69 slug
= matched
.group('slug')
70 song_id
= matched
.group('song_id')
72 webpage
= self
._download
_webpage
(
73 'http://mp3.zing.vn/bai-hat/%s/%s.html' % (slug
, song_id
), song_id
)
75 player_xml_url
= self
._search
_regex
(
76 r
'&xmlURL=(?P<xml_url>[^&]+)&', webpage
, 'player xml url')
78 return self
._extract
_player
_xml
(player_xml_url
, song_id
)
81 class ZingMp3AlbumIE(ZingMp3BaseInfoExtractor
):
82 _VALID_URL
= r
'https?://mp3\.zing\.vn/album/(?P<slug>[^/]+)/(?P<album_id>\w+)\.html'
84 'url': 'http://mp3.zing.vn/album/Lau-Dai-Tinh-Ai-Bang-Kieu-Minh-Tuyet/ZWZBWDAF.html',
88 'title': 'Lâu Đài Tình Ái - Bằng Kiều ft. Minh Tuyết | Album 320 lossless',
92 IE_NAME
= 'zingmp3:album'
93 IE_DESC
= 'mp3.zing.vn albums'
95 def _real_extract(self
, url
):
96 matched
= re
.match(self
._VALID
_URL
, url
)
97 slug
= matched
.group('slug')
98 album_id
= matched
.group('album_id')
100 webpage
= self
._download
_webpage
(
101 'http://mp3.zing.vn/album/%s/%s.html' % (slug
, album_id
), album_id
)
102 player_xml_url
= self
._search
_regex
(
103 r
'&xmlURL=(?P<xml_url>[^&]+)&', webpage
, 'player xml url')
105 return self
._extract
_player
_xml
(
106 player_xml_url
, album_id
,
107 playlist_title
=self
._og
_search
_title
(webpage
))