Implemented the song class for musicbrainz search
This commit is contained in:
1
create_venv.bat
Normal file
1
create_venv.bat
Normal file
@@ -0,0 +1 @@
|
|||||||
|
python3 -m venv venv
|
||||||
@@ -5,7 +5,8 @@ from musicdl.metadata import search
|
|||||||
def main():
|
def main():
|
||||||
url = argv[1]
|
url = argv[1]
|
||||||
title, artist, album = download(url)
|
title, artist, album = download(url)
|
||||||
results = search(title, artist, album)
|
result = search(title, artist, album)
|
||||||
|
print(result.title, result.artist, result.album, result.album_artist, result.track_number)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
def download(url: str):
|
def download(url: str) -> tuple[str | None, str | None, str | None]:
|
||||||
if "youtu" in url:
|
if "youtu" in url:
|
||||||
from musicdl.youtube import download
|
from musicdl.youtube import download
|
||||||
return download(url)
|
return download(url)
|
||||||
|
|
||||||
|
|
||||||
|
return None, None, None
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import musicdl.musicbrainz as musicbrainz
|
import musicdl.musicbrainz as musicbrainz
|
||||||
|
import musicdl.song as Song
|
||||||
|
|
||||||
def search(title: str, artist: str = None, album: str = None):
|
def search(title: str | None, artist: str | None = None, album: str | None = None) -> Song:
|
||||||
results = musicbrainz.search(title, artist, album)
|
results = musicbrainz.search(title, artist, album)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import musicbrainzngs
|
import musicbrainzngs
|
||||||
|
from musicdl.song import Song
|
||||||
|
|
||||||
musicbrainzngs.set_useragent(
|
musicbrainzngs.set_useragent(
|
||||||
"MusicDL",
|
"MusicDL",
|
||||||
@@ -6,7 +7,7 @@ musicbrainzngs.set_useragent(
|
|||||||
"https://git.krzak.org/N0VA/musicdl"
|
"https://git.krzak.org/N0VA/musicdl"
|
||||||
)
|
)
|
||||||
|
|
||||||
def search(title: str, artist: str = None, album: str = None):
|
def search(title: str | None, artist: str | None = None, album: str | None = None) -> Song:
|
||||||
result = musicbrainzngs.search_recordings(
|
result = musicbrainzngs.search_recordings(
|
||||||
query=title,
|
query=title,
|
||||||
artist=artist,
|
artist=artist,
|
||||||
@@ -14,4 +15,15 @@ def search(title: str, artist: str = None, album: str = None):
|
|||||||
limit=1
|
limit=1
|
||||||
)
|
)
|
||||||
|
|
||||||
return result
|
title: str = result['recording-list'][0]['title']
|
||||||
|
artist: str = result['recording-list'][0]['artist-credit'][0]['artist']['name']
|
||||||
|
album: str = result['recording-list'][0]['release-list'][0]['title']
|
||||||
|
album_artist: str = result['recording-list'][0]['release-list'][0]['artist-credit'][0]['artist']['name']
|
||||||
|
track_number = 0
|
||||||
|
|
||||||
|
for track in result['recording-list'][0]['release-list'][0]["medium-list"][0]["track-list"]:
|
||||||
|
if track["title"] == title:
|
||||||
|
track_number = track['number']
|
||||||
|
break
|
||||||
|
|
||||||
|
return Song(title, artist, album, album_artist, track_number)
|
||||||
@@ -5,8 +5,8 @@ class Song():
|
|||||||
artist: str,
|
artist: str,
|
||||||
album: str,
|
album: str,
|
||||||
album_artist: str,
|
album_artist: str,
|
||||||
track_number: str,
|
track_number: int,
|
||||||
cover: str
|
cover: str | None = None
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
self.title = title
|
self.title = title
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import yt_dlp
|
import yt_dlp
|
||||||
|
|
||||||
def download(url: str):
|
def download(url: str) -> tuple[str | None, str | None, str | None]:
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'format': 'bestaudio/best',
|
'format': 'bestaudio/best',
|
||||||
'postprocessors': [{
|
'postprocessors': [{
|
||||||
@@ -13,8 +13,8 @@ def download(url: str):
|
|||||||
ydl = yt_dlp.YoutubeDL(ydl_opts) #type: ignore
|
ydl = yt_dlp.YoutubeDL(ydl_opts) #type: ignore
|
||||||
# get data
|
# get data
|
||||||
info = ydl.extract_info(url, download=False)
|
info = ydl.extract_info(url, download=False)
|
||||||
title = info['title']
|
title = info['title'] if 'title' in info else None
|
||||||
artist = info['creator']
|
artist = info['creator'] if 'creator' in info else None
|
||||||
album = None
|
album = None
|
||||||
|
|
||||||
# download
|
# download
|
||||||
|
|||||||
116
results.json
Normal file
116
results.json
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
{
|
||||||
|
"recording-list": [
|
||||||
|
{
|
||||||
|
"id": "0567332d-f973-4a74-9c0c-cf8c8cbf8baa",
|
||||||
|
"ext:score": "100",
|
||||||
|
"title": "You Wouldn’t Know",
|
||||||
|
"length": "197000",
|
||||||
|
"artist-credit": [
|
||||||
|
{
|
||||||
|
"name": "Jonathan Coulton",
|
||||||
|
"artist": {
|
||||||
|
"id": "d8df7087-06d5-4545-9024-831bb8558ad1",
|
||||||
|
"name": "Jonathan Coulton",
|
||||||
|
"sort-name": "Coulton, Jonathan",
|
||||||
|
"alias-list": [
|
||||||
|
{
|
||||||
|
"sort-name": "J. Coulton",
|
||||||
|
"type": "Search hint",
|
||||||
|
"alias": "J. Coulton"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"sort-name": "Coulton, Jonathan William",
|
||||||
|
"type": "Legal name",
|
||||||
|
"alias": "Jonathan William Coulton"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"locale": "en",
|
||||||
|
"sort-name": "Coulton, Jonathan",
|
||||||
|
"type": "Artist name",
|
||||||
|
"primary": "primary",
|
||||||
|
"alias": "Jonathan Coulton"
|
||||||
|
},
|
||||||
|
{ "sort-name": "JoCo", "type": "Artist name", "alias": "JoCo" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
" feat. ",
|
||||||
|
{
|
||||||
|
"name": "Ellen McLain",
|
||||||
|
"artist": {
|
||||||
|
"id": "f318585d-b1a6-4127-bac3-c0d4d2019b67",
|
||||||
|
"name": "Ellen McLain",
|
||||||
|
"sort-name": "McLain, Ellen"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"release-list": [
|
||||||
|
{
|
||||||
|
"id": "d381e5c3-5166-4000-8819-bc5b405f8bf1",
|
||||||
|
"title": "You Wouldn’t Know",
|
||||||
|
"status": "Official",
|
||||||
|
"artist-credit": [
|
||||||
|
{
|
||||||
|
"name": "Jonathan Coulton",
|
||||||
|
"artist": {
|
||||||
|
"id": "d8df7087-06d5-4545-9024-831bb8558ad1",
|
||||||
|
"name": "Jonathan Coulton",
|
||||||
|
"sort-name": "Coulton, Jonathan"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
" feat. ",
|
||||||
|
{
|
||||||
|
"name": "Ellen McLain",
|
||||||
|
"artist": {
|
||||||
|
"id": "f318585d-b1a6-4127-bac3-c0d4d2019b67",
|
||||||
|
"name": "Ellen McLain",
|
||||||
|
"sort-name": "McLain, Ellen"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"release-group": {
|
||||||
|
"id": "fd297dd1-86cc-4c45-aee6-4ee38ddacf84",
|
||||||
|
"type": "Single",
|
||||||
|
"title": "You Wouldn’t Know",
|
||||||
|
"primary-type": "Single",
|
||||||
|
"secondary-type-list": ["Soundtrack"]
|
||||||
|
},
|
||||||
|
"date": "2015-09-28",
|
||||||
|
"country": "XW",
|
||||||
|
"release-event-list": [
|
||||||
|
{
|
||||||
|
"date": "2015-09-28",
|
||||||
|
"area": {
|
||||||
|
"id": "525d4e18-3d00-31b9-a58b-a146a916de8f",
|
||||||
|
"name": "[Worldwide]",
|
||||||
|
"sort-name": "[Worldwide]",
|
||||||
|
"iso-3166-1-code-list": ["XW"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"medium-list": [
|
||||||
|
{
|
||||||
|
"position": "1",
|
||||||
|
"format": "Digital Media",
|
||||||
|
"track-list": [
|
||||||
|
{
|
||||||
|
"id": "4127d181-61a8-4f7c-8383-9e50cd5eadfd",
|
||||||
|
"number": "1",
|
||||||
|
"title": "You Wouldn’t Know",
|
||||||
|
"length": "197000",
|
||||||
|
"track_or_recording_length": "197000"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"track-count": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"medium-track-count": 1,
|
||||||
|
"medium-count": 1,
|
||||||
|
"artist-credit-phrase": "Jonathan Coulton feat. Ellen McLain"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"artist-credit-phrase": "Jonathan Coulton feat. Ellen McLain"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"recording-count": 2922944
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user