spotify-downloader icon indicating copy to clipboard operation
spotify-downloader copied to clipboard

Rework, refactor, revamp web-ui

Open abcdefghijorngarbosaxyz opened this issue 1 year ago • 32 comments

Title

Use existing web-ui dist dir files

Description

Add a feat that checks if the dist dir already exists, use it instead, if not download the dist dir.

Related Issue

#1871

Motivation and Context

I like to reduce the server startup time. Also reduce internet data transmission.

How Has This Been Tested?

Some external pytest and running spotdl in poetry shell, as instructed in contributing.md

Screenshots (if appropriate)

running spotdl web with existing dist dir

image

running spotdl web with non-existing (deleted or first time user) dist dir

image

Types of Changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [x] Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • [x] My code follows the code style of this project
  • [ ] My change requires a change to the documentation
  • [ ] I have updated the documentation accordingly
  • [x] I have read the CONTRIBUTING document
  • [x] I have read the CORE VALUES document
  • [ ] I have added tests to cover my changes
  • [x] All new and existing tests passed

PS Had one error on mypy test but its not related to my changes :

Incompatible types in assignment (expression has type "AudioProvider", variable has type "Piped")  [assignment]

BREAKING CHANGE

Need to add release on the web-ui repo(currently none). A function checks for updates base on latest release on web-ui repo.

abcdefghijorngarbosaxyz avatar Jul 01 '23 18:07 abcdefghijorngarbosaxyz

But we still have to check if we aren't running an outdated version of web ui. Maybe add a file in the web repo with version, and a flag to force the update of web ui. Also consider implementing web ui version check in the flag that checks for updates.

xnetcat avatar Jul 01 '23 20:07 xnetcat

But we still have to check if we aren't running an outdated version of web ui. Maybe add a file in the web repo with version, and a flag to force the update of web ui. Also consider implementing web ui version check in the flag that checks for updates.

I'm currently working on the web-ui. It gets the version from the package.json, which then bundles as string in the static files. Which then compares it to the latest version number and informs the user if they're running an outdated web-ui, allows them to update.

abcdefghijorngarbosaxyz avatar Jul 02 '23 06:07 abcdefghijorngarbosaxyz

Please allow me to convert this to a draft.

abcdefghijorngarbosaxyz avatar Jul 02 '23 06:07 abcdefghijorngarbosaxyz

@xnetcat I added a function that gets the current web-ui version and the latest version from github api. Will update the files if not latest, before starting the server.

abcdefghijorngarbosaxyz avatar Jul 03 '23 02:07 abcdefghijorngarbosaxyz

PR looks good, but I am thinking that maybe I should convert it to PR for web-ui rework.?

xnetcat avatar Jul 04 '23 10:07 xnetcat

PR looks good, but I am thinking that maybe I should convert it to PR for web-ui rework.?

Of course. If you think its the appropriate.

abcdefghijorngarbosaxyz avatar Jul 09 '23 11:07 abcdefghijorngarbosaxyz

Just letting you know that if you need help with anything let me know!

xnetcat avatar Jul 12 '23 13:07 xnetcat

Just letting you know that if you need help with anything let me know!

Haven't made real progress yet on the web-ui. Waiting on merge of #1865, if ever. And, also working on the desktop app.

Planning to implement #1779 in the app.

abcdefghijorngarbosaxyz avatar Jul 13 '23 09:07 abcdefghijorngarbosaxyz

Ahh I didn't know you needed #1865. Merging it right now.

xnetcat avatar Jul 13 '23 09:07 xnetcat

Actually i need help. I'm trying to add --output-dir arg on the cli, like --use-web-output-dir, but can't think any implemention other than concatinating the path to the output format like c:\users\user\path\to\dir\{title} - {artist}.{output-ext}

abcdefghijorngarbosaxyz avatar Jul 13 '23 12:07 abcdefghijorngarbosaxyz

what do you need it for?

xnetcat avatar Jul 13 '23 12:07 xnetcat

what do you need it for?

Its not related to web-ui rework. LOL. Im implementing it in the desktop app. Please take a look at this.

And #1779 will be in the desktop app, not in the web-ui rework. I have some ideas but can't really implement it in Python(no knowledge on syntax and modules to use). But I can do it in Rust, so.

abcdefghijorngarbosaxyz avatar Jul 13 '23 20:07 abcdefghijorngarbosaxyz

gj with #1779 few questions though. why CD to downloads, why does it need elevated perms?

xnetcat avatar Jul 16 '23 20:07 xnetcat

why CD to downloads

When link with custom uri is clicked, example spotdl://https://open.spotify.com/track/5sICkBXVmaCQk5aISGR3x1?si=8f3379819fb24ecf

It opens a new cmd window, then execute spotdl download "url" there. but cwd will be in win32 folder because cmd is there lol. so need to cd to other folders, like the current user's downloads folder atleast, so the downloaded file will be saved there.

Also if we remove the cmd start and just execute the spotdl download "url" i dont know where the browser starts the command and download. Maybe in the same folder where the browsers exe file is? I haven't checked.

why does it need elevated perms

I think registering a winreg key needs elevated access. I tried it with no elevation it gives a permission error.

abcdefghijorngarbosaxyz avatar Jul 16 '23 20:07 abcdefghijorngarbosaxyz

thanks for explaining, maybe try adding some info about where songs are being downloaded when using uri opener etc and maybe add some logging to Inform users on what's happening.

xnetcat avatar Jul 16 '23 20:07 xnetcat

When a url like this spotdl://https://open.spotify.com/track/5sICkBXVmaCQk5aISGR3x1?si=8f3379819fb24ecf is clicked it will show alert on browser:

image

and opens a cmd window like this

image

Its exactly the spotdl download tui.

About the download folder maybe we can add the user's preferred path when installing like spotdl --install-uri-scheme "C:\some\folder". Maybe with sys.argv but I think its too hacky.

abcdefghijorngarbosaxyz avatar Jul 16 '23 21:07 abcdefghijorngarbosaxyz

or get a module path then create a path to script and start it with the python or something.

traversing all $PATH directories isn't the best idea someone might be running py -m spotdl because their python environment is messed up

xnetcat avatar Jul 16 '23 21:07 xnetcat

I used print insted of the logger. For some reason the logger doesnt output on cmd when registering the winreg key, but it does work on PermissionError block. I like to reiterate that I'm noob in python so I need help in this 🤣

abcdefghijorngarbosaxyz avatar Jul 16 '23 21:07 abcdefghijorngarbosaxyz

or get a module path then create a path to script and start it with the python or something.

traversing all $PATH directories isn't the best idea someone might be running py -m spotdl because their python environment is messed up

Ill try this. Another use case is if the user is using a downloaded compile exe.

abcdefghijorngarbosaxyz avatar Jul 16 '23 21:07 abcdefghijorngarbosaxyz

or get a module path then create a path to script and start it with the python or something.

traversing all $PATH directories isn't the best idea someone might be running py -m spotdl because their python environment is messed up

Ill try this. Another use case is if the user is using a downloaded compile exe.

yeah that's what I've meant by spotdl.exe

xnetcat avatar Jul 16 '23 21:07 xnetcat

I used print insted of the logger. For some reason the logger doesnt output on cmd when registering the winreg key, but it does work on PermissionError block. I like to reiterate that I'm noob in python so I need help in this 🤣

logging is not initialized at this point of cli lifecycle. it's totally fine to use prints here

xnetcat avatar Jul 16 '23 21:07 xnetcat

Also, I think we'll need to implement the --output-dir arg so we can use it in the uri command like spotdl download "url" --output-dir "c:\some\folder" instead of having to cd into the folder.

So when custom uri is used the browser will show image

instead of image

The "trying to open windows command processor" will be confusing

abcdefghijorngarbosaxyz avatar Jul 16 '23 21:07 abcdefghijorngarbosaxyz

there's already a --output flag, what would --output-dir change?

xnetcat avatar Jul 16 '23 21:07 xnetcat

In description the --output flag specifies the download file name format. Users can't control the uri command. --output-dir can be used in spotdl --install-uri-scheme "C:\some\folder"

So the uri command will be spotdl download "url" --output-dir "C:\some\folder" instead of cd "C:\some\folder" && spotdl download "url"

The "trying to open windows command processor" will be confusing

If you really prefer the --output flag we can just use it and user will install the uri scheme with something like spotl --install-uri-scheme "C:\some\folder\{title} - {artist}.{output-ext}", but in this way, the output is fixed, at least with --output-dir, only the dir will be fixed, user can still change the output in config.json and will reflect on the uri command.

Hope you get what im meaning

abcdefghijorngarbosaxyz avatar Jul 16 '23 22:07 abcdefghijorngarbosaxyz

file name is not required when passing a directory path to the --output flag

xnetcat avatar Jul 16 '23 22:07 xnetcat

https://github.com/spotDL/spotify-downloader/issues/1728

xnetcat avatar Jul 16 '23 22:07 xnetcat

file name is not required when passing a directory path to the --output flag

Oh I didnt know that. So we can just pass the output folder?

abcdefghijorngarbosaxyz avatar Jul 16 '23 22:07 abcdefghijorngarbosaxyz

It actually worked. Lol. Some new knowledge for me. image

abcdefghijorngarbosaxyz avatar Jul 16 '23 22:07 abcdefghijorngarbosaxyz

Ok I think I get what you mean now. Since we have to CD first, browser will show an alert with trying to open the windows command processor message. Maybe try doing spotdl -v && cd path && spotDL download url console gets cleared before downloading songs so this shouldn't be an issue.

xnetcat avatar Jul 16 '23 22:07 xnetcat

Having spotdl as the first argument wont launch a cmd window. No idea why.

abcdefghijorngarbosaxyz avatar Jul 16 '23 23:07 abcdefghijorngarbosaxyz