diff options
| author | DemonKingSwarn <rockingswarn@gmail.com> | 2024-02-14 19:07:24 +0530 | 
|---|---|---|
| committer | DemonKingSwarn <rockingswarn@gmail.com> | 2024-02-14 19:07:24 +0530 | 
| commit | 1a0ce5cf17e0f5acd2e94d40ec2b7de8af387e60 (patch) | |
| tree | f2598d85316b39c3be498ee870525a781a13241f /yt_music | |
| parent | aaab15c874e66a552c5753d953484bb67bc027e6 (diff) | |
| download | yt-music-1a0ce5cf17e0f5acd2e94d40ec2b7de8af387e60.zip yt-music-1a0ce5cf17e0f5acd2e94d40ec2b7de8af387e60.tar.gz | |
feat: DOWNLOADER
Diffstat (limited to 'yt_music')
| -rw-r--r-- | yt_music/__version__.py | 2 | ||||
| -rw-r--r-- | yt_music/__yt_music__.py | 37 | 
2 files changed, 36 insertions, 3 deletions
| 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) | 
