Skip to content

Commit

Permalink
feat: DOWNLOADER
Browse files Browse the repository at this point in the history
  • Loading branch information
DemonKingSwarn committed Feb 14, 2024
1 parent aaab15c commit 1a0ce5c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pip install --upgrade yt-music
- Open a terminal

- Type:
- `yt-music <your music you wanna listen`
- `yt-music <your music you wanna listen>`

or

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "yt-music"
version = "0.0.2"
version = "0.0.3"
description = "A command line YouTube Music client."
authors = ["DemonKingSwarn <[email protected]>"]
license = "GPLv3"
Expand All @@ -14,6 +14,7 @@ readme = "readme.txt"
python = "^3.10"
httpx = "0.23.0"
krfzf-py = "^0.0.4"
yt-dlp = "^2023.12.30"

[tool.poetry.dev-dependencies]

Expand Down
26 changes: 0 additions & 26 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion yt_music/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__core__ = "0.0.2"
__core__ = "0.0.3"
37 changes: 35 additions & 2 deletions yt_music/__yt_music__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
import re
import subprocess
import platform
import os

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


client = httpx.Client(headers=headers, timeout=None)

base_url = "https://vid.puffyan.us"
Expand Down Expand Up @@ -42,6 +45,31 @@ def extract_video_id(video_title):
else:
return None

def determine_path() -> str:

plt = platform.system()

if plt == "Windows":
return f"C:\\Users\\{os.getenv('username')}\\Downloads"

elif (plt == "Linux"):
return f"/home/{os.getlogin()}/Downloads"

elif (plt == "Darwin"):
return f"/Users/{os.getlogin()}/Downloads"

else:
print("[!] Make an issue for your OS.")
exit(0)

def download(video_id, video_title):

path: str = determine_path()
video_title = video_title.replace(' ', '_')

subprocess.call(f"yt-dlp -x \"https://music.youtube.com/watch?v={video_id}\" -o \"{path}/{video_title}\"", shell=True)


def play_loop(video_id, video_title):

args = [
Expand Down Expand Up @@ -80,12 +108,17 @@ def main():
ch = fzf.fzf_prompt(opts)
print(ch)
idx = extract_video_id(ch)
play_ch = fzf.fzf_prompt(["play", "loop"])
play_ch = fzf.fzf_prompt(["play", "loop", "download"])
try:
if play_ch == "play":
play(idx, ch)
else:
elif play_ch == "loop":
play_loop(idx, ch)
elif play_ch == "download":
download(idx, ch)
else:
print("[!] Nothing selected.")
exit(1)
except KeyboardInterrupt:
exit(0)

Expand Down

0 comments on commit 1a0ce5c

Please sign in to comment.