Skip to content

Commit 46ccdd4

Browse files
committed
update to latest ytmusicapi, now uses oauth for authentication. fixes #29
1 parent c0a0ecb commit 46ccdd4

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
module_name = "ytmusic-deleter"
1616

17-
install_reqs = ["click", "ytmusicapi == 0.25.0", "enlighten"]
17+
install_reqs = ["click", "ytmusicapi >= 1.5.0", "enlighten"]
1818

1919
develop_reqs = [
2020
"pre-commit",

ytmusic_deleter/cli.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
from json import JSONDecodeError
12
import logging
23
import os
34
import re
45
import sys
56
from pathlib import Path
67
from random import shuffle as unsort
78
from time import strftime
9+
import ytmusicapi
810

911
import click
1012
import enlighten
@@ -17,15 +19,16 @@
1719

1820
def ensure_auth(credential_dir):
1921
global youtube_auth
20-
headers_file_path = Path(credential_dir) / const.HEADERS_FILE
22+
oauth_file_path: str = str(Path(credential_dir) / const.OAUTH_FILENAME)
2123
try:
22-
logging.info(f'Looking for {headers_file_path}"')
23-
youtube_auth = YTMusic(headers_file_path)
24-
logging.info(f'Found {headers_file_path}"')
25-
except (KeyError, AttributeError):
26-
logging.info(f"Creating {const.HEADERS_FILE} file...")
27-
youtube_auth = YTMusic(YTMusic.setup(filepath=headers_file_path))
28-
logging.info(f'Created {headers_file_path}"')
24+
logging.info(f'Attempting authentication with: {oauth_file_path}')
25+
youtube_auth = YTMusic(oauth_file_path)
26+
logging.info(f'Authenticated with: {oauth_file_path}"')
27+
except JSONDecodeError:
28+
logging.info(f"Creating file: {const.OAUTH_FILENAME}")
29+
ytmusicapi.setup_oauth(filepath=oauth_file_path, open_browser=True)
30+
youtube_auth = YTMusic(oauth_file_path)
31+
logging.info(f'Created: {oauth_file_path}"')
2932

3033

3134
@click.group()

ytmusic_deleter/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
LIKE = "LIKE"
22
INDIFFERENT = "INDIFFERENT"
3-
HEADERS_FILE = "headers_auth.json"
3+
OAUTH_FILENAME = "oauth.json"
44
UNKNOWN_ARTIST = "Unknown Artist"

0 commit comments

Comments
 (0)