mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-13 14:37:43 +01:00
Merge branch 'deezer' of https://github.com/LucBerge/youtube-dl into LucBerge-deezer
This commit is contained in:
commit
51f8793699
@ -11,28 +11,15 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DeezerPlaylistIE(InfoExtractor):
|
class DeezerBaseInfoExtractor(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?deezer\.com/playlist/(?P<id>[0-9]+)'
|
def get_data(self, url):
|
||||||
_TEST = {
|
if not self._downloader.params.get('test'):
|
||||||
'url': 'http://www.deezer.com/playlist/176747451',
|
|
||||||
'info_dict': {
|
|
||||||
'id': '176747451',
|
|
||||||
'title': 'Best!',
|
|
||||||
'uploader': 'Anonymous',
|
|
||||||
'thumbnail': r're:^https?://cdn-images\.deezer\.com/images/cover/.*\.jpg$',
|
|
||||||
},
|
|
||||||
'playlist_count': 30,
|
|
||||||
'skip': 'Only available in .de',
|
|
||||||
}
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
|
||||||
if 'test' not in self._downloader.params:
|
|
||||||
self._downloader.report_warning('For now, this extractor only supports the 30 second previews. Patches welcome!')
|
self._downloader.report_warning('For now, this extractor only supports the 30 second previews. Patches welcome!')
|
||||||
|
|
||||||
mobj = re.match(self._VALID_URL, url)
|
mobj = re.match(self._VALID_URL, url)
|
||||||
playlist_id = mobj.group('id')
|
data_id = mobj.group('id')
|
||||||
|
|
||||||
webpage = self._download_webpage(url, playlist_id)
|
webpage = self._download_webpage(url, data_id)
|
||||||
geoblocking_msg = self._html_search_regex(
|
geoblocking_msg = self._html_search_regex(
|
||||||
r'<p class="soon-txt">(.*?)</p>', webpage, 'geoblocking message',
|
r'<p class="soon-txt">(.*?)</p>', webpage, 'geoblocking message',
|
||||||
default=None)
|
default=None)
|
||||||
@ -45,6 +32,24 @@ def _real_extract(self, url):
|
|||||||
r'naboo\.display\(\'[^\']+\',\s*(.*?)\);\n'),
|
r'naboo\.display\(\'[^\']+\',\s*(.*?)\);\n'),
|
||||||
webpage, 'data JSON')
|
webpage, 'data JSON')
|
||||||
data = json.loads(data_json)
|
data = json.loads(data_json)
|
||||||
|
return data_id, webpage, data
|
||||||
|
|
||||||
|
|
||||||
|
class DeezerPlaylistIE(DeezerBaseInfoExtractor):
|
||||||
|
_VALID_URL = r'https?://(?:www\.)?deezer\.com/(../)?playlist/(?P<id>[0-9]+)'
|
||||||
|
_TEST = {
|
||||||
|
'url': 'http://www.deezer.com/playlist/176747451',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '176747451',
|
||||||
|
'title': 'Best!',
|
||||||
|
'uploader': 'anonymous',
|
||||||
|
'thumbnail': r're:^https?://(e-)?cdns-images\.dzcdn\.net/images/cover/.*\.jpg$',
|
||||||
|
},
|
||||||
|
'playlist_count': 29,
|
||||||
|
}
|
||||||
|
|
||||||
|
def _real_extract(self, url):
|
||||||
|
playlist_id, webpage, data = self.get_data(url)
|
||||||
|
|
||||||
playlist_title = data.get('DATA', {}).get('TITLE')
|
playlist_title = data.get('DATA', {}).get('TITLE')
|
||||||
playlist_uploader = data.get('DATA', {}).get('PARENT_USERNAME')
|
playlist_uploader = data.get('DATA', {}).get('PARENT_USERNAME')
|
||||||
@ -52,31 +57,23 @@ def _real_extract(self, url):
|
|||||||
r'<img id="naboo_playlist_image".*?src="([^"]+)"', webpage,
|
r'<img id="naboo_playlist_image".*?src="([^"]+)"', webpage,
|
||||||
'playlist thumbnail')
|
'playlist thumbnail')
|
||||||
|
|
||||||
preview_pattern = self._search_regex(
|
|
||||||
r"var SOUND_PREVIEW_GATEWAY\s*=\s*'([^']+)';", webpage,
|
|
||||||
'preview URL pattern', fatal=False)
|
|
||||||
entries = []
|
entries = []
|
||||||
for s in data['SONGS']['data']:
|
for s in data.get('SONGS', {}).get('data'):
|
||||||
puid = s['MD5_ORIGIN']
|
|
||||||
preview_video_url = preview_pattern.\
|
|
||||||
replace('{0}', puid[0]).\
|
|
||||||
replace('{1}', puid).\
|
|
||||||
replace('{2}', s['MEDIA_VERSION'])
|
|
||||||
formats = [{
|
formats = [{
|
||||||
'format_id': 'preview',
|
'format_id': 'preview',
|
||||||
'url': preview_video_url,
|
'url': s.get('MEDIA', [{}])[0].get('HREF'),
|
||||||
'preference': -100, # Only the first 30 seconds
|
'preference': -100, # Only the first 30 seconds
|
||||||
'ext': 'mp3',
|
'ext': 'mp3',
|
||||||
}]
|
}]
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
artists = ', '.join(
|
artists = ', '.join(
|
||||||
orderedSet(a['ART_NAME'] for a in s['ARTISTS']))
|
orderedSet(a.get('ART_NAME') for a in s.get('ARTISTS')))
|
||||||
entries.append({
|
entries.append({
|
||||||
'id': s['SNG_ID'],
|
'id': s.get('SNG_ID'),
|
||||||
'duration': int_or_none(s.get('DURATION')),
|
'duration': int_or_none(s.get('DURATION')),
|
||||||
'title': '%s - %s' % (artists, s['SNG_TITLE']),
|
'title': '%s - %s' % (artists, s.get('SNG_TITLE')),
|
||||||
'uploader': s['ART_NAME'],
|
'uploader': s.get('ART_NAME'),
|
||||||
'uploader_id': s['ART_ID'],
|
'uploader_id': s.get('ART_ID'),
|
||||||
'age_limit': 16 if s.get('EXPLICIT_LYRICS') == '1' else 0,
|
'age_limit': 16 if s.get('EXPLICIT_LYRICS') == '1' else 0,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
})
|
})
|
||||||
@ -89,3 +86,62 @@ def _real_extract(self, url):
|
|||||||
'thumbnail': playlist_thumbnail,
|
'thumbnail': playlist_thumbnail,
|
||||||
'entries': entries,
|
'entries': entries,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class DeezerAlbumIE(DeezerBaseInfoExtractor):
|
||||||
|
_VALID_URL = r'https?://(?:www\.)?deezer\.com/(../)?album/(?P<id>[0-9]+)'
|
||||||
|
_TEST = {
|
||||||
|
'url': 'https://www.deezer.com/fr/album/67505622',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '67505622',
|
||||||
|
'title': 'Last Week',
|
||||||
|
'uploader': 'Home Brew',
|
||||||
|
'thumbnail': r're:^https?://(e-)?cdns-images\.dzcdn\.net/images/cover/.*\.jpg$',
|
||||||
|
},
|
||||||
|
'playlist_count': 7,
|
||||||
|
}
|
||||||
|
|
||||||
|
def _real_extract(self, url):
|
||||||
|
album_id, webpage, data = self.get_data(url)
|
||||||
|
|
||||||
|
album_title = data.get('DATA', {}).get('ALB_TITLE')
|
||||||
|
album_uploader = data.get('DATA', {}).get('ART_NAME')
|
||||||
|
album_thumbnail = self._search_regex(
|
||||||
|
r'<img id="naboo_album_image".*?src="([^"]+)"', webpage,
|
||||||
|
'album thumbnail')
|
||||||
|
|
||||||
|
entries = []
|
||||||
|
for s in data.get('SONGS', {}).get('data'):
|
||||||
|
formats = [{
|
||||||
|
'format_id': 'preview',
|
||||||
|
'url': s.get('MEDIA', [{}])[0].get('HREF'),
|
||||||
|
'preference': -100, # Only the first 30 seconds
|
||||||
|
'ext': 'mp3',
|
||||||
|
}]
|
||||||
|
self._sort_formats(formats)
|
||||||
|
artists = ', '.join(
|
||||||
|
orderedSet(a.get('ART_NAME') for a in s.get('ARTISTS')))
|
||||||
|
entries.append({
|
||||||
|
'id': s.get('SNG_ID'),
|
||||||
|
'duration': int_or_none(s.get('DURATION')),
|
||||||
|
'title': '%s - %s' % (artists, s.get('SNG_TITLE')),
|
||||||
|
'uploader': s.get('ART_NAME'),
|
||||||
|
'uploader_id': s.get('ART_ID'),
|
||||||
|
'age_limit': 16 if s.get('EXPLICIT_LYRICS') == '1' else 0,
|
||||||
|
'formats': formats,
|
||||||
|
'track': s.get('SNG_TITLE'),
|
||||||
|
'track_number': int_or_none(s.get('TRACK_NUMBER')),
|
||||||
|
'track_id': s.get('SNG_ID'),
|
||||||
|
'artist': album_uploader,
|
||||||
|
'album': album_title,
|
||||||
|
'album_artist': album_uploader,
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
'_type': 'playlist',
|
||||||
|
'id': album_id,
|
||||||
|
'title': album_title,
|
||||||
|
'uploader': album_uploader,
|
||||||
|
'thumbnail': album_thumbnail,
|
||||||
|
'entries': entries,
|
||||||
|
}
|
||||||
|
@ -262,7 +262,10 @@
|
|||||||
)
|
)
|
||||||
from .dbtv import DBTVIE
|
from .dbtv import DBTVIE
|
||||||
from .dctp import DctpTvIE
|
from .dctp import DctpTvIE
|
||||||
from .deezer import DeezerPlaylistIE
|
from .deezer import (
|
||||||
|
DeezerPlaylistIE,
|
||||||
|
DeezerAlbumIE,
|
||||||
|
)
|
||||||
from .democracynow import DemocracynowIE
|
from .democracynow import DemocracynowIE
|
||||||
from .dfb import DFBIE
|
from .dfb import DFBIE
|
||||||
from .dhm import DHMIE
|
from .dhm import DHMIE
|
||||||
|
Loading…
Reference in New Issue
Block a user