aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--pyproject.toml3
-rw-r--r--setup.py26
-rw-r--r--yt_music/__version__.py2
-rw-r--r--yt_music/__yt_music__.py37
5 files changed, 39 insertions, 31 deletions
diff --git a/README.md b/README.md
index 479331e..d8ba16d 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/pyproject.toml b/pyproject.toml
index 0a9b23c..79f1677 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -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 <rockingswarn@gmail.com>"]
license = "GPLv3"
@@ -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]
diff --git a/setup.py b/setup.py
deleted file mode 100644
index c509d29..0000000
--- a/setup.py
+++ /dev/null
@@ -1,26 +0,0 @@
-from setuptools import setup, find_packages
-from yt_music.__version__ import __core__
-
-with open("requirements.txt") as requirements_txt:
- requirements = requirements_txt.read().splitlines()
-
-setup(
- name="yt-music",
- version=__core__,
- author="d3m0n@demonkingswarn",
- author_email="demonkingswarn@protonmail.com",
- description="A command line YouTube Music client",
- packages=find_packages(),
- url="https://github.com/DemonKingSwarn/yt-music",
- keywords=[
- "youtube",
- "youtube music",
- "yt-music"
- ],
- install_requires=requirements,
- entry_points="""
- [console_scripts]
- yt-music=yt_music.__main__:__ytmusic__
- """,
- include_package_data=True,
-)
diff --git a/yt_music/__version__.py b/yt_music/__version__.py
index 18bf362..24d9284 100644
--- a/yt_music/__version__.py
+++ b/yt_music/__version__.py
@@ -1 +1 @@
-__core__ = "0.0.2"
+__core__ = "0.0.3"
diff --git a/yt_music/__yt_music__.py b/yt_music/__yt_music__.py
index 3f0d6ef..5e19c2d 100644
--- a/yt_music/__yt_music__.py
+++ b/yt_music/__yt_music__.py
@@ -1,6 +1,8 @@
import sys
import re
import subprocess
+import platform
+import os
import httpx
import fzf
@@ -9,6 +11,7 @@ headers = {
"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"
@@ -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 = [
@@ -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)