Skip to content

Commit

Permalink
Preserving local web-ui, added --force-update-gui option to force che…
Browse files Browse the repository at this point in the history
…ckout a new copy of web ui (#2117)

Co-authored-by: kuba <xnetcat.dev@gmail.com>
  • Loading branch information
karanbheda and xnetcat authored Jul 20, 2024
1 parent 6890493 commit ac5f990
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions spotdl/console/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import sys
import webbrowser
import os

from fastapi import Depends, FastAPI
from fastapi.middleware.cors import CORSMiddleware
Expand Down Expand Up @@ -62,13 +63,14 @@ def web(web_settings: WebOptions, downloader_settings: DownloaderOptions):

downloader_settings["simple_tui"] = True

# Download web app from GitHub
logger.info("Updating web app \n")
# Download web app from GitHub if not already downloaded or force flag set
web_app_dir = str(get_spotdl_path().absolute())
download_github_dir(
"https://github.com/spotdl/web-ui/tree/master/dist",
output_dir=web_app_dir,
)
if not os.path.exists(web_app_dir) or web_settings["force_update_gui"]:
logger.info("Updating web app \n")
download_github_dir(
"https://github.com/spotdl/web-ui/tree/master/dist",
output_dir=web_app_dir,
)

app_state.api = FastAPI(
title="spotDL",
Expand Down
1 change: 1 addition & 0 deletions spotdl/types/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class WebOptions(TypedDict):
ca_file: str | None
allowed_origins: Optional[List[str]]
keep_sessions: bool
force_update_gui: bool


class SpotDLOptions(SpotifyOptions, DownloaderOptions, WebOptions):
Expand Down
7 changes: 7 additions & 0 deletions spotdl/utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,13 @@ def parse_web_options(parser: _ArgumentGroup):
help="Keep the session directory after the web server is closed.",
)

# Add keep sessions argument
parser.add_argument(
"--force-update-gui",
action="store_const",
const=True,
default=False,
help="Refresh the web server directory with a fresh git checkout",
# Enable TLS for the web server
parser.add_argument(
"--enable-tls",
Expand Down
1 change: 1 addition & 0 deletions spotdl/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def get_parameter(cls, key):
"ca_file": None,
"allowed_origins": None,
"keep_sessions": False,
"force_update_gui": False,
}

# Type: ignore because of the issues above
Expand Down

0 comments on commit ac5f990

Please sign in to comment.