aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md12
-rw-r--r--config.json.example3
-rw-r--r--pyproject.toml2
-rw-r--r--yt_music/__version__.py2
-rw-r--r--yt_music/__yt_music__.py63
5 files changed, 55 insertions, 27 deletions
diff --git a/README.md b/README.md
index d8ba16d..3cc76d4 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,18 @@ pip install --upgrade yt-music
**NOTE** YOU NEED TO HAVE THEM IN YOUR `PATH`
+## Config
+
+Config file has to be in the following location depending on your OS:
+
+- On Linux and Mac:
+ `$HOME/.config/yt-music/config.json`
+
+- On Windows:
+ `C:\Users\<username>\.config\yt-music\config.json`
+
+You can copy the example config `config.json.example`
+
## Usage
- Open a terminal
diff --git a/config.json.example b/config.json.example
new file mode 100644
index 0000000..ec3aef7
--- /dev/null
+++ b/config.json.example
@@ -0,0 +1,3 @@
+{
+ "RPC": "true"
+}
diff --git a/pyproject.toml b/pyproject.toml
index aab7a4e..3b92e54 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.6"
+version = "0.0.7"
description = "A command line YouTube Music client."
authors = ["DemonKingSwarn <rockingswarn@gmail.com>"]
license = "GPLv3"
diff --git a/yt_music/__version__.py b/yt_music/__version__.py
index a952047..82474e3 100644
--- a/yt_music/__version__.py
+++ b/yt_music/__version__.py
@@ -1 +1 @@
-__core__ = "0.0.6"
+__core__ = "0.0.7"
diff --git a/yt_music/__yt_music__.py b/yt_music/__yt_music__.py
index 4b9e977..895f64a 100644
--- a/yt_music/__yt_music__.py
+++ b/yt_music/__yt_music__.py
@@ -5,20 +5,33 @@ import platform
import os
import time
import html
+import json
-from pypresence import Presence
import httpx
import fzf
+plt = platform.system()
+username = os.getenv('username') if plt == 'Windows' else os.getlogin()
+config_path = os.path.join(os.path.expanduser(f'~{username}'), '.config', 'yt-music', 'config.json')
+
+if os.path.exists(config_path):
+ with open(config_path) as f:
+ config = json.load(f)
+ use_rpc = config['RPC']
+else:
+ use_rpc = "false"
+
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0"
}
-start = int(time.time())
-client_id = "1075791459409723472"
-RPC = Presence(client_id)
-RPC.connect()
+if use_rpc == "true":
+ from pypresence import Presence
+ start = int(time.time())
+ client_id = "1075791459409723472"
+ RPC = Presence(client_id)
+ RPC.connect()
client = httpx.Client(headers=headers, timeout=None)
@@ -55,8 +68,6 @@ def extract_video_id(video_title):
def determine_path() -> str:
- plt = platform.system()
-
if plt == "Windows":
return f"C:\\Users\\{os.getenv('username')}\\Downloads"
@@ -80,15 +91,16 @@ def download(video_id, video_title):
def play_loop(video_id, video_title):
- RPC.update(
- 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",
- start = start,
- details = f"{video_title} - loop",
- buttons = [{"label": "Play on YouTube Music", "url": f"https://music.youtube.com/watch?v={video_id}"}],
- )
+ if use_rpc == "true":
+ RPC.update(
+ 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",
+ start = start,
+ details = f"{video_title} - loop",
+ buttons = [{"label": "Play on YouTube Music", "url": f"https://music.youtube.com/watch?v={video_id}"}],
+ )
args = [
MPV_EXECUTABLE,
@@ -105,15 +117,16 @@ def play_loop(video_id, video_title):
def play(video_id, video_title):
- RPC.update(
- 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",
- start = start,
- details = video_title,
- buttons = [{"label": "Play on YouTube Music", "url": f"https://music.youtube.com/watch?v={video_id}"}],
- )
+ if use_rpc == "true":
+ RPC.update(
+ 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",
+ start = start,
+ details = video_title,
+ buttons = [{"label": "Play on YouTube Music", "url": f"https://music.youtube.com/watch?v={video_id}"}],
+ )
args = [
MPV_EXECUTABLE,