2022-01-24 17:41:21 +01:00
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
|
|
|
date_from_str,
|
|
|
|
format_field,
|
|
|
|
try_get,
|
|
|
|
unified_strdate,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class MusicdexBaseIE(InfoExtractor):
|
2024-06-12 01:09:58 +02:00
|
|
|
def _return_info(self, track_json, album_json, video_id):
|
2022-01-24 17:41:21 +01:00
|
|
|
return {
|
2024-06-12 01:09:58 +02:00
|
|
|
'id': str(video_id),
|
2022-01-24 17:41:21 +01:00
|
|
|
'title': track_json.get('name'),
|
|
|
|
'track': track_json.get('name'),
|
|
|
|
'description': track_json.get('description'),
|
|
|
|
'track_number': track_json.get('number'),
|
|
|
|
'url': format_field(track_json, 'url', 'https://www.musicdex.org/%s'),
|
|
|
|
'duration': track_json.get('duration'),
|
2024-03-08 23:36:41 +01:00
|
|
|
'genres': [genre.get('name') for genre in track_json.get('genres') or []],
|
2022-01-24 17:41:21 +01:00
|
|
|
'like_count': track_json.get('likes_count'),
|
|
|
|
'view_count': track_json.get('plays'),
|
2024-03-08 23:36:41 +01:00
|
|
|
'artists': [artist.get('name') for artist in track_json.get('artists') or []],
|
|
|
|
'album_artists': [artist.get('name') for artist in album_json.get('artists') or []],
|
2022-01-24 17:41:21 +01:00
|
|
|
'thumbnail': format_field(album_json, 'image', 'https://www.musicdex.org/%s'),
|
|
|
|
'album': album_json.get('name'),
|
|
|
|
'release_year': try_get(album_json, lambda x: date_from_str(unified_strdate(x['release_date'])).year),
|
|
|
|
'extractor_key': MusicdexSongIE.ie_key(),
|
|
|
|
'extractor': 'MusicdexSong',
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class MusicdexSongIE(MusicdexBaseIE):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?musicdex\.org/track/(?P<id>\d+)'
|
|
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://www.musicdex.org/track/306/dual-existence',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '306',
|
|
|
|
'ext': 'mp3',
|
|
|
|
'title': 'dual existence',
|
|
|
|
'description': '#NIPPONSEI @ IRC.RIZON.NET',
|
|
|
|
'track': 'dual existence',
|
|
|
|
'track_number': 1,
|
|
|
|
'duration': 266000,
|
2024-03-08 23:36:41 +01:00
|
|
|
'genres': ['Anime'],
|
2022-01-24 17:41:21 +01:00
|
|
|
'like_count': int,
|
|
|
|
'view_count': int,
|
2024-03-08 23:36:41 +01:00
|
|
|
'artists': ['fripSide'],
|
|
|
|
'album_artists': ['fripSide'],
|
2022-01-24 17:41:21 +01:00
|
|
|
'thumbnail': 'https://www.musicdex.org/storage/album/9iDIam1DHTVqUG4UclFIEq1WAFGXfPW4y0TtZa91.png',
|
|
|
|
'album': 'To Aru Kagaku no Railgun T OP2 Single - dual existence',
|
2024-06-12 01:09:58 +02:00
|
|
|
'release_year': 2020,
|
2022-01-24 17:41:21 +01:00
|
|
|
},
|
2024-06-12 01:09:58 +02:00
|
|
|
'params': {'skip_download': True},
|
2022-01-24 17:41:21 +01:00
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2024-06-12 01:09:58 +02:00
|
|
|
video_id = self._match_id(url)
|
|
|
|
data_json = self._download_json(
|
|
|
|
f'https://www.musicdex.org/secure/tracks/{video_id}?defaultRelations=true', video_id)['track']
|
|
|
|
return self._return_info(data_json, data_json.get('album') or {}, video_id)
|
2022-01-24 17:41:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
class MusicdexAlbumIE(MusicdexBaseIE):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?musicdex\.org/album/(?P<id>\d+)'
|
|
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://www.musicdex.org/album/56/tenmon-and-eiichiro-yanagi-minori/ef-a-tale-of-memories-original-soundtrack-2-fortissimo',
|
|
|
|
'playlist_mincount': 28,
|
|
|
|
'info_dict': {
|
|
|
|
'id': '56',
|
2024-03-08 23:36:41 +01:00
|
|
|
'genres': ['OST'],
|
2022-01-24 17:41:21 +01:00
|
|
|
'view_count': int,
|
2024-03-08 23:36:41 +01:00
|
|
|
'artists': ['TENMON & Eiichiro Yanagi / minori'],
|
2022-01-24 17:41:21 +01:00
|
|
|
'title': 'ef - a tale of memories Original Soundtrack 2 ~fortissimo~',
|
|
|
|
'release_year': 2008,
|
|
|
|
'thumbnail': 'https://www.musicdex.org/storage/album/2rSHkyYBYfB7sbvElpEyTMcUn6toY7AohOgJuDlE.jpg',
|
|
|
|
},
|
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2024-06-12 01:09:58 +02:00
|
|
|
playlist_id = self._match_id(url)
|
|
|
|
data_json = self._download_json(
|
|
|
|
f'https://www.musicdex.org/secure/albums/{playlist_id}?defaultRelations=true', playlist_id)['album']
|
|
|
|
entries = [self._return_info(track, data_json, track['id'])
|
|
|
|
for track in data_json.get('tracks') or [] if track.get('id')]
|
2022-01-24 17:41:21 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
'_type': 'playlist',
|
2024-06-12 01:09:58 +02:00
|
|
|
'id': playlist_id,
|
2022-01-24 17:41:21 +01:00
|
|
|
'title': data_json.get('name'),
|
|
|
|
'description': data_json.get('description'),
|
2024-03-08 23:36:41 +01:00
|
|
|
'genres': [genre.get('name') for genre in data_json.get('genres') or []],
|
2022-01-24 17:41:21 +01:00
|
|
|
'view_count': data_json.get('plays'),
|
2024-03-08 23:36:41 +01:00
|
|
|
'artists': [artist.get('name') for artist in data_json.get('artists') or []],
|
2022-01-24 17:41:21 +01:00
|
|
|
'thumbnail': format_field(data_json, 'image', 'https://www.musicdex.org/%s'),
|
|
|
|
'release_year': try_get(data_json, lambda x: date_from_str(unified_strdate(x['release_date'])).year),
|
|
|
|
'entries': entries,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-16 01:57:43 +01:00
|
|
|
class MusicdexPageIE(MusicdexBaseIE): # XXX: Conventionally, base classes should end with BaseIE/InfoExtractor
|
2024-06-12 01:09:58 +02:00
|
|
|
def _entries(self, playlist_id):
|
|
|
|
next_page_url = self._API_URL % playlist_id
|
2022-01-24 17:41:21 +01:00
|
|
|
while next_page_url:
|
2024-06-12 01:09:58 +02:00
|
|
|
data_json = self._download_json(next_page_url, playlist_id)['pagination']
|
|
|
|
yield from data_json.get('data') or []
|
2022-01-24 17:41:21 +01:00
|
|
|
next_page_url = data_json.get('next_page_url')
|
|
|
|
|
|
|
|
|
|
|
|
class MusicdexArtistIE(MusicdexPageIE):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?musicdex\.org/artist/(?P<id>\d+)'
|
|
|
|
_API_URL = 'https://www.musicdex.org/secure/artists/%s/albums?page=1'
|
|
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://www.musicdex.org/artist/11/fripside',
|
|
|
|
'playlist_mincount': 28,
|
|
|
|
'info_dict': {
|
|
|
|
'id': '11',
|
|
|
|
'view_count': int,
|
|
|
|
'title': 'fripSide',
|
|
|
|
'thumbnail': 'https://www.musicdex.org/storage/artist/ZmOz0lN2vsweegB660em3xWffCjLPmTQHqJls5Xx.jpg',
|
|
|
|
},
|
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2024-06-12 01:09:58 +02:00
|
|
|
playlist_id = self._match_id(url)
|
|
|
|
data_json = self._download_json(f'https://www.musicdex.org/secure/artists/{playlist_id}', playlist_id)['artist']
|
2022-01-24 17:41:21 +01:00
|
|
|
entries = []
|
2024-06-12 01:09:58 +02:00
|
|
|
for album in self._entries(playlist_id):
|
2022-01-24 17:41:21 +01:00
|
|
|
entries.extend(self._return_info(track, album, track['id']) for track in album.get('tracks') or [] if track.get('id'))
|
|
|
|
|
|
|
|
return {
|
|
|
|
'_type': 'playlist',
|
2024-06-12 01:09:58 +02:00
|
|
|
'id': playlist_id,
|
2022-01-24 17:41:21 +01:00
|
|
|
'title': data_json.get('name'),
|
|
|
|
'view_count': data_json.get('plays'),
|
|
|
|
'thumbnail': format_field(data_json, 'image_small', 'https://www.musicdex.org/%s'),
|
|
|
|
'entries': entries,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class MusicdexPlaylistIE(MusicdexPageIE):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?musicdex\.org/playlist/(?P<id>\d+)'
|
|
|
|
_API_URL = 'https://www.musicdex.org/secure/playlists/%s/tracks?perPage=10000&page=1'
|
|
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://www.musicdex.org/playlist/9/test',
|
|
|
|
'playlist_mincount': 73,
|
|
|
|
'info_dict': {
|
|
|
|
'id': '9',
|
|
|
|
'view_count': int,
|
|
|
|
'title': 'Test',
|
|
|
|
'thumbnail': 'https://www.musicdex.org/storage/album/jXATI79f0IbQ2sgsKYOYRCW3zRwF3XsfHhzITCuJ.jpg',
|
|
|
|
'description': 'Test 123 123 21312 32121321321321312',
|
|
|
|
},
|
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2024-06-12 01:09:58 +02:00
|
|
|
playlist_id = self._match_id(url)
|
|
|
|
data_json = self._download_json(f'https://www.musicdex.org/secure/playlists/{playlist_id}', playlist_id)['playlist']
|
2022-01-24 17:41:21 +01:00
|
|
|
entries = [self._return_info(track, track.get('album') or {}, track['id'])
|
2024-06-12 01:09:58 +02:00
|
|
|
for track in self._entries(playlist_id) or [] if track.get('id')]
|
2022-01-24 17:41:21 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
'_type': 'playlist',
|
2024-06-12 01:09:58 +02:00
|
|
|
'id': playlist_id,
|
2022-01-24 17:41:21 +01:00
|
|
|
'title': data_json.get('name'),
|
|
|
|
'description': data_json.get('description'),
|
|
|
|
'view_count': data_json.get('plays'),
|
|
|
|
'thumbnail': format_field(data_json, 'image', 'https://www.musicdex.org/%s'),
|
|
|
|
'entries': entries,
|
|
|
|
}
|