Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nathom committed Aug 13, 2021
2 parents cb4415e + 6cfd068 commit 3629190
Show file tree
Hide file tree
Showing 10 changed files with 1,296 additions and 1,222 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added demo/.DS_Store
Binary file not shown.
51 changes: 40 additions & 11 deletions rip/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
logger = logging.getLogger("streamrip")

outdated = False
newest_version = __version__


class DownloadCommand(Command):
Expand All @@ -43,9 +44,11 @@ class DownloadCommand(Command):

def handle(self):
global outdated
global newest_version

# Use a thread so that it doesn't slow down startup
update_check = threading.Thread(target=is_outdated, daemon=True)
update_check.start()

config = Config()
path, codec, quality, no_db = clean_options(
Expand Down Expand Up @@ -83,16 +86,39 @@ def handle(self):
elif not urls and path is None:
self.line("<error>Must pass arguments. See </><cmd>rip url -h</cmd>.")

try:
update_check.join()
if outdated:
self.line(
"<info>A new version of streamrip is available! Run</info> "
"<cmd>pip3 install streamrip --upgrade to update</cmd>"
)
except RuntimeError as e:
logger.debug("Update check error: %s", e)
pass
update_check.join()
if outdated:
import subprocess
import re

self.line(
f"<info>Updating streamrip to <title>v{newest_version}</title>...</info>\n"
)

# update in background
update_p = subprocess.Popen(
["pip3", "install", "streamrip", "--upgrade"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

md_header = re.compile(r"#\s+(.+)")
bullet_point = re.compile(r"-\s+(.+)")
code = re.compile(r"`([^`]+)`")
issue_reference = re.compile(r"(#\d+)")

release_notes = requests.get(
"https://api.github.com/repos/nathom/streamrip/releases/latest"
).json()["body"]

release_notes = md_header.sub(r"<header>\1</header>", release_notes)
release_notes = bullet_point.sub(r"<options=bold>•</> \1", release_notes)
release_notes = code.sub(r"<cmd>\1</cmd>", release_notes)
release_notes = issue_reference.sub(r"<options=bold>\1</>", release_notes)

self.line(release_notes)

update_p.wait()

return 0

Expand Down Expand Up @@ -451,6 +477,7 @@ def create_io(self, input=None, output=None, error_output=None):
formatter.set_style("path", Style("green", options=["bold"]))
formatter.set_style("cmd", Style("magenta"))
formatter.set_style("title", Style("yellow", options=["bold"]))
formatter.set_style("header", Style("yellow", options=["bold", "underline"]))
io.output.set_formatter(formatter)
io.error_output.set_formatter(formatter)

Expand Down Expand Up @@ -494,8 +521,10 @@ def clean_options(*opts):

def is_outdated():
global outdated
global newest_version
r = requests.get("https://pypi.org/pypi/streamrip/json").json()
outdated = r["info"]["version"] != __version__
newest_version = r["info"]["version"]
outdated = newest_version != __version__


def main():
Expand Down
16 changes: 12 additions & 4 deletions rip/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from getpass import getpass
from hashlib import md5
from string import Formatter
import threading
from typing import Dict, Generator, List, Optional, Tuple, Type, Union

import requests
Expand Down Expand Up @@ -219,7 +220,7 @@ def _get_download_args(self) -> dict:
"parent_folder": session["downloads"]["folder"],
"folder_format": filepaths["folder_format"],
"track_format": filepaths["track_format"],
"embed_cover": session["artwork"]["embed"],
"embed_cover": artwork["embed"],
"embed_cover_size": artwork["size"],
"keep_hires_cover": artwork["keep_hires_cover"],
"set_playlist_to_album": session["metadata"]["set_playlist_to_album"],
Expand Down Expand Up @@ -367,7 +368,7 @@ def login(self, client):
if client.source == "deezer" and creds["arl"] == "":
if self.config.session["deezer"]["deezloader_warnings"]:
secho(
"Falling back to Deezloader (max 320kbps MP3). If you have a subscription, run ",
"Falling back to Deezloader (unstable). If you have a subscription, run ",
nl=False,
fg="yellow",
)
Expand All @@ -385,9 +386,16 @@ def login(self, client):
creds = self.config.creds(client.source)
except MissingCredentials:
logger.debug("Credentials are missing. Prompting..")
get_tokens = threading.Thread(
target=client._get_app_id_and_secrets, daemon=True
)
get_tokens.start()

self.prompt_creds(client.source)
creds = self.config.creds(client.source)

get_tokens.join()

if (
client.source == "qobuz"
and not creds.get("secrets")
Expand Down Expand Up @@ -451,7 +459,7 @@ def parse_urls(self, url: str) -> List[Tuple[str, str, str]]:
for item, url in zip(soundcloud_items, soundcloud_urls)
)

logger.debug(f"Parsed urls: {parsed}")
logger.debug("Parsed urls: %s", parsed)

return parsed

Expand Down Expand Up @@ -493,7 +501,7 @@ def handle_lastfm_urls(self, urls: str):
# This will match somthing like "Test (Person Remix]" though, so its not perfect
banned_words_plain = re.compile(r"(?i)(?:(?:re)?mix|live|karaoke)")
banned_words = re.compile(
rf"(?i)[\(\[][^\)\]]*?(?:(?:re)?mix|live|karaoke)[^\)\]]*[\]\)]"
r"(?i)[\(\[][^\)\]]*?(?:(?:re)?mix|live|karaoke)[^\)\]]*[\]\)]"
)

def search_query(title, artist, playlist) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion rip/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create(self):
)
command = f"CREATE TABLE {self.name} ({params})"

logger.debug(f"executing {command}")
logger.debug("executing %s", command)

conn.execute(command)

Expand Down
Loading

0 comments on commit 3629190

Please sign in to comment.