diff options
author | DemonKingSwarn <rockingswarn@gmail.com> | 2024-05-10 22:22:58 +0530 |
---|---|---|
committer | DemonKingSwarn <rockingswarn@gmail.com> | 2024-05-10 22:22:58 +0530 |
commit | dccf007192126ac5fa518677d4afbb453ae2b033 (patch) | |
tree | bb8468bd810ce4fad657e92bdafc106d0ad33652 /yt_music | |
parent | 7e4c9465a197ed2024e85151b2b7d53d51704d1b (diff) | |
download | yt-music-dccf007192126ac5fa518677d4afbb453ae2b033.zip yt-music-dccf007192126ac5fa518677d4afbb453ae2b033.tar.gz |
chore: added artist name in rpc
Diffstat (limited to 'yt_music')
-rw-r--r-- | yt_music/__yt_music__.py | 26 |
1 files changed, 22 insertions, 4 deletions
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'<a.*?href="/watch\?v=(.*?)".*?><p.*?>(.*?)<\/p></a>' +channel_name_pattern = r'<span id="channel-name">(.*?)</span>' 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}"}], ) |