diff --git a/.gitignore b/.gitignore index fe35e0e..b1790ef 100644 --- a/.gitignore +++ b/.gitignore @@ -113,6 +113,6 @@ dmypy.json .pyre/ - +.vscode/ result.json \ No newline at end of file diff --git a/musicdl/__main__.py b/musicdl/__main__.py index a184010..fcea6bd 100644 --- a/musicdl/__main__.py +++ b/musicdl/__main__.py @@ -1,12 +1,11 @@ from sys import argv -import musicdl.metadata as metadata +from musicdl.download import download +from musicdl.metadata import search def main(): url = argv[1] - print(url) - result = metadata.search("You Wouldn't Know", "Jonathan Coulton feat. Ellen McLain") - import json - json.dump(result, open("result.json", "w"), indent=4) + title, artist, album = download(url) + results = search(title, artist, album) if __name__ == '__main__': main() \ No newline at end of file diff --git a/musicdl/download.py b/musicdl/download.py new file mode 100644 index 0000000..861217e --- /dev/null +++ b/musicdl/download.py @@ -0,0 +1,4 @@ +def download(url: str): + if "youtu" in url: + from musicdl.youtube import download + return download(url) \ No newline at end of file diff --git a/musicdl/youtube.py b/musicdl/youtube.py new file mode 100644 index 0000000..556c7f2 --- /dev/null +++ b/musicdl/youtube.py @@ -0,0 +1,23 @@ +import yt_dlp + +def download(url: str): + ydl_opts = { + 'format': 'bestaudio/best', + 'postprocessors': [{ + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'mp3', + }], + 'outtmpl': '%(title)s.%(ext)s', + } + + ydl = yt_dlp.YoutubeDL(ydl_opts) #type: ignore + # get data + info = ydl.extract_info(url, download=False) + title = info['title'] + artist = info['creator'] + album = None + + # download + #ydl.download(url) + + return title, artist, album \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 07695e3..0d88b7b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -musicbrainzngs \ No newline at end of file +musicbrainzngs +yt_dlp \ No newline at end of file