-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit da10d9c
Showing
10 changed files
with
853 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Publish version changes to PyPI | ||
on: | ||
push: | ||
paths: | ||
- "yt_music/__version__.py" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checking out repository content | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setting up Python 3.11 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Build the file | ||
run: | | ||
pip install setuptools wheel | ||
python setup.py sdist | ||
- name: Publish a Python distribution to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
env | ||
yt_music.egg-info | ||
build | ||
__pycache__ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# yt-music | ||
|
||
A command line YouTube Music client. | ||
|
||
## Installation | ||
|
||
```sh | ||
pip install --upgrade yt-music | ||
``` | ||
|
||
**NOTE** YOU NEED `PYTHON` INSTALLED AND IN YOUR `PATH` | ||
|
||
## Usage | ||
|
||
- Open a terminal | ||
|
||
- Type: | ||
- `yt-music <your music you wanna listen' | ||
or | ||
- `yt-music` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
httpx | ||
krfzf-py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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="[email protected]", | ||
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, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from . import __yt_music__ | ||
|
||
def __ytmusic__(): | ||
__yt_music__ | ||
|
||
if __name__ == "__main__": | ||
__ytmusic__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__core__ = "0.0.1a" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import sys | ||
import re | ||
import subprocess | ||
|
||
import httpx | ||
import fzf | ||
|
||
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" | ||
pattern = r'<a.*?href="/watch\?v=(.*?)".*?><p.*?>(.*?)<\/p></a>' | ||
|
||
MPV_EXECUTABLE = "mpv" | ||
|
||
try: | ||
if len(sys.argv) == 1: | ||
query = input("Search: ") | ||
if query == "": | ||
print("ValueError: no query parameter provided") | ||
exit(1) | ||
else: | ||
query = " ".join(sys.argv[1:]) | ||
except KeyboardInterrupt: | ||
exit(0) | ||
|
||
query = query.replace(' ', '+') | ||
opts = [] | ||
|
||
|
||
def extract_video_id(video_title): | ||
pattern = r' - (\w+)$' | ||
|
||
match = re.search(pattern, video_title) | ||
|
||
if match: | ||
video_id = match.group(1) | ||
return video_id | ||
else: | ||
return None | ||
|
||
def play_loop(video_id, video_title): | ||
|
||
args = [ | ||
MPV_EXECUTABLE, | ||
f"https://music.youtube.com/watch?v={video_id}", | ||
f"--force-media-title={video_title}", | ||
"--no-video", | ||
"--loop", | ||
] | ||
|
||
mpv_process = subprocess.Popen(args, stdout=subprocess.DEVNULL) | ||
mpv_process.wait() | ||
|
||
|
||
|
||
def play(video_id, video_title): | ||
|
||
args = [ | ||
MPV_EXECUTABLE, | ||
f"https://music.youtube.com/watch?v={video_id}", | ||
f"--force-media-title={video_title}", | ||
"--no-video", | ||
] | ||
|
||
mpv_process = subprocess.Popen(args, stdout=subprocess.DEVNULL) | ||
mpv_process.wait() | ||
|
||
|
||
def main(): | ||
fetch = client.get(f"{base_url}/search?q={query}") | ||
matches = re.findall(pattern, fetch.text) | ||
for match in matches: | ||
video_id, title = match | ||
opt = f"{title} - {video_id}" | ||
opts.append(opt) | ||
ch = fzf.fzf_prompt(opts) | ||
print(ch) | ||
idx = extract_video_id(ch) | ||
play_ch = fzf.fzf_prompt(["play", "loop"]) | ||
try: | ||
if play_ch == "play": | ||
play(idx, ch) | ||
else: | ||
play_loop(idx, ch) | ||
except KeyboardInterrupt: | ||
exit(0) | ||
|
||
main() |