Marekkon5 / onetagger

Music tagger for Windows, MacOS and Linux with Beatport, Discogs, Musicbrainz, Spotify, Traxsource and many other platforms support.
https://onetagger.github.io/
GNU General Public License v3.0
633 stars 35 forks source link

Feature Request: command line #76

Closed jrsmile closed 2 years ago

jrsmile commented 2 years ago

Hi,

it would be nice to have a headless mode,

so one could just do ./onetagger -P /path/to/music --auto-tag "shazam,musicbrainz,spotify" --audio-feat (-x /path/to/shellscript for postprocessing) (--mv /path/to/output/directory )

in a dedicated server i can only get it to run in --server mode, ist there a way to disable the frontend, it would remove the need for the libgtk dependency.

Thanks in advance, J.

Marekkon5 commented 2 years ago

I can implement that, however the libgtk dependency will be always present in the binary, even in cli mode. To drop the libgtk dependency I'd have to distribute onetagger as 2 different binaries with the GUI features completely removed from it.

Marekkon5 commented 2 years ago

I've added a CLI prototype in the latest commit, however it is missing a lot of options. I am considering adding a --config option which would just load the config file in JSON format to prevent having 9999 different parameters for everything (especially confusing in the audio features section). Let me know what you think about this.

The current implementation only supports the existing options (--server, --expose) and AutoTagger:

./onetagger autotagger --id3v24 --path path/to/music --threads 16 --tags title,artist --platforms beatport,traxsource

You can also do ./onetagger --help or ./onetagger autotagger --help to see more.

To test it, you can get the binary from the Actions tab. Let me know if it works for you. Thanks

jrsmile commented 2 years ago

hi, sorry for letting you wait, haven't thought you are already implementing it. i like the config file it might be simpler then setting all the switches by hand. maybe even export it from the gui to repeat the process headless? unfortunately with the "actions" release at least on windows i get no output at all.

` C:\Users\Music>OneTagger-windows.exe --help

C:\Users\Music>OneTagger-windows.exe

C:\Users\Music>OneTagger-windows.exe --id3v24 -p . --threads 12 --tags title,artist --platforms spotify

C:\Users\Music>OneTagger-windows.exe -h

C:\Users\Music>OneTagger-windows.exe autotagger -h

C:\Users\Music>OneTagger-windows.exe autotagger --help

C:\Users\Music>OneTagger-windows.exe autotagger -help

C:\Users\Music>OneTagger-windows.exe --server --expose autotagger --help

C:\Users\Music>OneTagger-windows.exe autotagger --server --expose --help

`

only when using no parameters the default gui starts. will try on linux asap.

jrsmile commented 2 years ago

on linux its working good:

` ./onetagger autotagger -p . --threads 12 --tags title,artist --platforms beatport,traxsource Jan 26 01:29:13.337 INFO

Starting OneTagger v1.3.0 Commit: 5d5fc1e7 OS: linux

, module: onetagger::cli Jan 26 01:29:13.355 INFO Starting tagger with: 807 files!, module: onetagger::tagger Jan 26 01:29:13.403 INFO Starting Beatport, module: onetagger::tagger Jan 26 01:29:13.403 INFO Starting tagging: 807 files, 12 threads!, module: onetagger::tagger `

jrsmile commented 2 years ago

when implementing your idea with the config file, how would you cover the spotify auth part?

Marekkon5 commented 2 years ago

So in the latest commit, I've changed the CLI completely. It now uses the config files I mentioned earlier. The --tags or --platforms options don't work anymore - you have to set those in the config. Also -p or --path is always required in CLI mode and overrides path properties in config.

How to use:

You can always check the help, by running: ./onetagger --help

./onetagger --autotagger-config > autotagger.json
./onetagger autotagger --path music/directory --config autotagger.json

For Audio Features the steps are similar, but you have to provide Spotify Client ID and Client Secret as an argument:

./onetagger --audiofeatures-config > audiofeatures.json
./onetagger audiofeatures --path music/dir --config audiofeatures.json --client-id CLIENT_ID --client-secret CLIENT_SECRET

Spotify:

You have to either login at least once inside UI (doesn't matter if Audio Features or AutoTagger), or use the CLI login method:

./onetagger authorize-spotify --client-id CLIENT_ID --client-secret CLIENT_SECRET

Which will prompt you to visit a Spotify authorization website to authenticate.

You can also authorize on your PC and later copy the token to a headless machine (~/.config/onetagger/spotify_token_cache.json)

However in AutoTagger config you also have to manually specify the Client ID and Secret:

     "spotify": {
        "clientId": "CLIENT_ID",
        "clientSecret": "CLIENT_SECRET"
      },

The reason of this inconsistency (autotagger is config X audiofeatures is cli arguments) is because of how the configs are shared with the GUI part and how it's implemented. Sorry for that

Windows

OneTagger is a GUI app - so on Windows it is compiled with the -mwindows option (Windows Subsystem). That means it's not a console app, therefore it doesn't have a console window. I've tried playing with AllocConsole win32 function, but no luck with that so far. Most GUI apps don't get consoles on Windows, so it might be problematic. However all of the features above do work, and you can see the progress inside the actual onetagger.log file. Piping also works (onetagger.exe 2> log.txt to pipe the 1T log, onetagger --autotagger-config > autotagger.json to pipe the stdout data)

As always - binary is in the actions tab. Let me know, if it works for you. Thanks

jrsmile commented 2 years ago

hi this time i only tested on linux, the setup was a bit uncomfortable but workable, i have been warned :-) i tested with 807 mp3s some tagged some not. the tagging went well and with only 4 failed tracks, (i know why they failed) the audio features process went well too, but i noticed drastic slowdown when using the cli. gui was 144 seconds. cli was 1302 seconds. same settings for both gui and cli ( as far as i could see)

Marekkon5 commented 2 years ago
  1. As for the user experience - do you have any suggestions how to make it better? What would you change?
  2. Only audio features were slow, or autotagger too? If autotagger too - did you set the same amount of threads?

I'll have a look and test it myself tomorrow. Thanks for testing and feedback.

jrsmile commented 2 years ago
  1. if not asked to much i would try to fetch the spotify token via username and password, as for dedicated servers the oauth method is hard to realise, im not sure, but i think, if not updated the token only works for 3600 seconds. if it is possible derive spotify auth settings from cli so it can be used in a docker container.

if the process is done one might need to know which tracks were exact identified which via shazam and which failed. i haven't found the possibility to move files to a completed folder, maybe you can move the analysed mp3s into failed, unsure, completed folders via path parameters?

my ideal scenario would be:

a. have unknown music in a folder (numbered, no tags or correct filenames). b. docker run --rm -p /path/to/input:/input -p /path/to/output:/output -p config.json:/config.json -e SPOTIFY_USER=dreamjob -e SPOTIFY_PASS=12312312 Marekkon5/onetagger b.1 maybe even as daemon that watches the input folder for new files and (optionally) deletes them if completed. c. have an output folder with 3 subfolders (completed,unsure,failed) and the mp3s are tagged with everything, the filename is correct and audiofeature have been added.

  1. it was only the audio features the tagger ran great.

  2. let me add that you created a really good software here with all features i dreamed of. in addition im really impressed by your support for the software, i tipped you via paypal to support you with this software.

Marekkon5 commented 2 years ago
  1. Spotify: The cached token contains a refresh token - so it's valid until you revoke it. So you don't have to login every time, just once. + you can just copy the cached token from your PC to the server. As for username + password - the Spotify API doesnt allow it. Another option would be like rclone or spotipy - pasting the redirect URL into the terminal rather than having to run the callback server.

As for the automation - 1T saves a .m3u files with all the tagged or failed tracks. You can check the Run command option in GUI (and later use the same value in the CLI version).

  1. Will check tomorrow

  2. Thanks, I really appreciate it.

Marekkon5 commented 2 years ago

I've added --prompt option to the authorize-spotify CLI mode - instead of starting a callback server, it will prompt you to paste the token into the terminal.

As for the AudioFeatures - I wasn't able to reproduce it. I got 200 tracks in 40s. Can you maybe share the log file? Thanks

Marekkon5 commented 2 years ago

In the latest commit, I've cleaned up the CLI - it now supports both config & passing most of the parameters as arguments. I consider it done at this point, comment or reopen if you have any more issues / questions.

RDeluxe commented 2 years ago

Hello, just chiming in.

Thanks for the great tool, that's a lot of hard work!

Just wondering where I could find the documentation for the CLI. Just by reading the rust source files?

Thanks

Marekkon5 commented 2 years ago

@RDeluxe you can run onetagger-cli --help or onetagger-cli autotagger --help or onetagger-cli audiofeatures --help. It should show you all the available options.

Let me know if that's enough or if I should write some wiki page or something.

RDeluxe commented 2 years ago

Tks, will take a look at this this week.