Skip to content

Commit 1a0ce5c

Browse files
committedFeb 14, 2024·
feat: DOWNLOADER
1 parent aaab15c commit 1a0ce5c

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pip install --upgrade yt-music
2222
- Open a terminal
2323

2424
- Type:
25-
- `yt-music <your music you wanna listen`
25+
- `yt-music <your music you wanna listen>`
2626

2727
or
2828

‎pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "yt-music"
7-
version = "0.0.2"
7+
version = "0.0.3"
88
description = "A command line YouTube Music client."
99
authors = ["DemonKingSwarn <rockingswarn@gmail.com>"]
1010
license = "GPLv3"
@@ -14,6 +14,7 @@ readme = "readme.txt"
1414
python = "^3.10"
1515
httpx = "0.23.0"
1616
krfzf-py = "^0.0.4"
17+
yt-dlp = "^2023.12.30"
1718

1819
[tool.poetry.dev-dependencies]
1920

‎setup.py

-26
This file was deleted.

‎yt_music/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__core__ = "0.0.2"
1+
__core__ = "0.0.3"

‎yt_music/__yt_music__.py

+35-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sys
22
import re
33
import subprocess
4+
import platform
5+
import os
46

57
import httpx
68
import fzf
@@ -9,6 +11,7 @@
911
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0"
1012
}
1113

14+
1215
client = httpx.Client(headers=headers, timeout=None)
1316

1417
base_url = "https://vid.puffyan.us"
@@ -42,6 +45,31 @@ def extract_video_id(video_title):
4245
else:
4346
return None
4447

48+
def determine_path() -> str:
49+
50+
plt = platform.system()
51+
52+
if plt == "Windows":
53+
return f"C:\\Users\\{os.getenv('username')}\\Downloads"
54+
55+
elif (plt == "Linux"):
56+
return f"/home/{os.getlogin()}/Downloads"
57+
58+
elif (plt == "Darwin"):
59+
return f"/Users/{os.getlogin()}/Downloads"
60+
61+
else:
62+
print("[!] Make an issue for your OS.")
63+
exit(0)
64+
65+
def download(video_id, video_title):
66+
67+
path: str = determine_path()
68+
video_title = video_title.replace(' ', '_')
69+
70+
subprocess.call(f"yt-dlp -x \"https://music.youtube.com/watch?v={video_id}\" -o \"{path}/{video_title}\"", shell=True)
71+
72+
4573
def play_loop(video_id, video_title):
4674

4775
args = [
@@ -80,12 +108,17 @@ def main():
80108
ch = fzf.fzf_prompt(opts)
81109
print(ch)
82110
idx = extract_video_id(ch)
83-
play_ch = fzf.fzf_prompt(["play", "loop"])
111+
play_ch = fzf.fzf_prompt(["play", "loop", "download"])
84112
try:
85113
if play_ch == "play":
86114
play(idx, ch)
87-
else:
115+
elif play_ch == "loop":
88116
play_loop(idx, ch)
117+
elif play_ch == "download":
118+
download(idx, ch)
119+
else:
120+
print("[!] Nothing selected.")
121+
exit(1)
89122
except KeyboardInterrupt:
90123
exit(0)
91124

0 commit comments

Comments
 (0)
Please sign in to comment.