feat: initial commit
This commit is contained in:
commit
d3259551b2
10 changed files with 866 additions and 0 deletions
49
download_service.py
Normal file
49
download_service.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
import sys
|
||||
|
||||
import yt_dlp
|
||||
|
||||
from music_player import Track
|
||||
|
||||
ydl_opts = {
|
||||
"format": "mp3/bestaudio/best",
|
||||
# ℹ️ See help(yt_dlp.postprocessor) for a list of available Postprocessors and their arguments
|
||||
"postprocessors": [
|
||||
{
|
||||
"key": "FFmpegExtractAudio",
|
||||
"preferredcodec": "mp3",
|
||||
}
|
||||
],
|
||||
"paths": {"home": "queue"},
|
||||
"outtmpl": {"default": "%(artist)s - %(track)s [%(id)s].%(ext)s"},
|
||||
}
|
||||
|
||||
|
||||
class DownloadService:
|
||||
def __init__(self) -> None:
|
||||
self.ydl = yt_dlp.YoutubeDL(ydl_opts)
|
||||
|
||||
def download(self, url: str) -> Track:
|
||||
info = self.ydl.extract_info(url, download=True)
|
||||
|
||||
track = Track(
|
||||
artist=info["artists"][0], # type: ignore
|
||||
title=info["title"], # type: ignore
|
||||
duration=info["duration"], # type: ignore
|
||||
filepath=info["requested_downloads"][-1]["filepath"], # type: ignore
|
||||
)
|
||||
|
||||
print(f"Finished processing {track}")
|
||||
|
||||
return track
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit(1)
|
||||
|
||||
qser = DownloadService()
|
||||
qser.download(sys.argv[1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue