From dccf007192126ac5fa518677d4afbb453ae2b033 Mon Sep 17 00:00:00 2001 From: DemonKingSwarn Date: Fri, 10 May 2024 22:22:58 +0530 Subject: chore: added artist name in rpc --- pyproject.toml | 3 ++- yt_music/__yt_music__.py | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3b92e54..e05ba46 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.7" +version = "0.0.8" description = "A command line YouTube Music client." authors = ["DemonKingSwarn "] license = "GPLv3" @@ -16,6 +16,7 @@ httpx = "0.23.0" krfzf-py = "^0.0.4" yt-dlp = "^2023.12.30" pypresence = "4.3.0" +bs4 = "^0.0.2" [tool.poetry.dev-dependencies] diff --git a/yt_music/__yt_music__.py b/yt_music/__yt_music__.py index 895f64a..0170d9a 100644 --- a/yt_music/__yt_music__.py +++ b/yt_music/__yt_music__.py @@ -9,6 +9,7 @@ import json import httpx import fzf +from bs4 import BeautifulSoup as bs plt = platform.system() username = os.getenv('username') if plt == 'Windows' else os.getlogin() @@ -37,6 +38,7 @@ client = httpx.Client(headers=headers, timeout=None) base_url = "https://vid.puffyan.us" pattern = r'(.*?)<\/p>' +channel_name_pattern = r'(.*?)' MPV_EXECUTABLE = "mpv" @@ -55,6 +57,17 @@ query = query.replace(' ', '+') opts = [] +def get_channel(video_id): + resp = client.get(f"https://vid.puffyan.us/watch?v={video_id}") + html_content = resp.text + soup = bs(html_content, 'html.parser') + channel_names = re.findall(channel_name_pattern, html_content) + + for name in channel_names: + print(name.strip()) + get_channel.artist = name.strip() + + def extract_video_id(video_title): match = re.search(r' - ([\w-]+)$', video_title) @@ -62,9 +75,11 @@ def extract_video_id(video_title): if match: video_id = match.group(1) + get_channel(video_id) return video_id else: - return None + print("no video id found") + exit(1) def determine_path() -> str: @@ -89,6 +104,7 @@ def download(video_id, video_title): 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): if use_rpc == "true": @@ -96,9 +112,10 @@ def play_loop(video_id, video_title): large_image = f"http://img.youtube.com/vi/{video_id}/0.jpg", large_text = "haha checkmate spotify plebs", small_image = "youtube_music_icon_svg", - small_text = "yt-music", + small_text = f"yt-music", start = start, details = f"{video_title} - loop", + state = f"by {get_channel.artist}", buttons = [{"label": "Play on YouTube Music", "url": f"https://music.youtube.com/watch?v={video_id}"}], ) @@ -122,9 +139,10 @@ def play(video_id, video_title): large_image = f"http://img.youtube.com/vi/{video_id}/0.jpg", large_text = "haha checkmate spotify plebs", small_image = "youtube_music_icon_svg", - small_text = "yt-music", + small_text = f"yt-music", start = start, - details = video_title, + details = f"{video_title}", + state = f"by {get_channel.artist}", buttons = [{"label": "Play on YouTube Music", "url": f"https://music.youtube.com/watch?v={video_id}"}], ) -- cgit v1.1