Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PICARD-2519: Allow passing supported URLs on command line #2130

Merged
merged 31 commits into from
Jul 31, 2022

Conversation

skelly37
Copy link
Contributor

@skelly37 skelly37 commented Jul 20, 2022

Summary

  • This is a…
    • Bug fix
    • Feature addition
    • Refactoring
    • Minor / simple change (like a typo)
    • Other
  • Describe this change in 1-2 sentences:

Currently Picard supports passing file paths on command line to open the respective files. Picard also supports handling some URL patterns by drag and drop, e.g. MusicBrainz recordings, releases, release group and cdtoc URLs.

Extend Picard to also handle these supported URLs when passed via command line.

Problem

Solution

call urllib.parse.urlparse on each argument marked as FILE to determine whether it's a file or URL, then pass it to the actual Tagger.

Action

skelly37 added 5 commits July 20, 2022 10:27
['cdtoc/nuVRJcYftbCghFSdwVVK6D4e6Ko-']
D: 12:48:19,689 /usr/lib/python3.10/site-packages/picard/browser/filelookup.mbid_lookup:136: Lookup for cdtoc:nuVRJcYftbCghFSdwVVK6D4e6Ko-
QObject::startTimer: Timers cannot be started from another thread
QObject::startTimer: Timers cannot be started from another thread
@skelly37
Copy link
Contributor Author

I think that handling the QObject::startTimer: Timers cannot be started from another thread will make it actually done.

picard/tagger.py Fixed Show fixed Hide fixed
picard/tagger.py Fixed Show fixed Hide fixed
@skelly37
Copy link
Contributor Author

skelly37 commented Jul 20, 2022

Okay, I've found out that picard.webservice.WebService.add_task is responsible for raising QObject::startTimer errors twice. Ref

Seems like the WebService was designed to be called by the main thread, while the pipe listener runs on another one, so it cannot start the actual task (and even breaks the currently working drag'n'drop feature). I mean, drag'n'drop works until we try to pass some URL via command-line to an existing instance.

@skelly37
Copy link
Contributor Author

@zas @phw So basically I need help from the more proficient in Qt one of you

@rdswift
Copy link
Collaborator

rdswift commented Jul 20, 2022

At the risk of intoducing "scope creep", in addition to handling URLs on the command line, how about being able to just enter the MBID insead of the full URL? Of course, entering the full URL should work as well.

Basically the command line should probably accept the same inputs as the lookup text box: Album, Artist (?), Track. The only thing with just entering the MBID is that Picard won't know which type of record so it may have to try as many as three calls to the API to get a response. Perhaps the command line entry could (should) include a type identifier along with the MBID, like "Album:1fa3b874-dbef-4c86-9681-3f6d6877ddba"?

@rdswift
Copy link
Collaborator

rdswift commented Jul 20, 2022

Seems like the WebService was designed to be called by the main thread, while the pipe listener runs on another one, so it cannot start the actual task (and even breaks the currently working drag'n'drop feature).

I wonder if you could accomplish this using a signal? According to this article on setting handlers for asynchronous events, "Python signal handlers are always executed in the main Python thread of the main interpreter, even if the signal was received in another thread."

There are also a couple of threads on Stack Overflow (Python signals between threads and Emit signal in standard python thread) that might provide some insights. In particular, the the queue class looks like it might be promising.

I don't know if these are useful because I'm about the furthest thing from an expert on threaded processing. 😉

@phw
Copy link
Member

phw commented Jul 20, 2022

I wonder if you could accomplish this using a signal?

Indeed that is probably the way, and Picard has a helper for that. You can use the to_main function from picard.util.thread to run a task on the main thread.

Album, Artist (?), Track. The only thing with just entering the MBID is that Picard won't know which type of record so it may have to try as many as three calls to the API to get a response. Perhaps the command line entry could (should) include a type identifier along with the MBID, like "Album:1fa3b874-dbef-4c86-9681-3f6d6877ddba"?

I would limit it to URLs for now, otherwise it can get confused with normal valid local paths. If we would introduce MBIDs, they should be with identify identifier in the form release:{mbid}, recording:{mbid} or artist:{mbid}. This is the short form of the full MB URLs, which is in this form already supported.

@skelly37
Copy link
Contributor Author

I tend to agree with @phw on extending the current functionality to just URLs. The GUI automations we've discussed on IRC seem to be more useful than @rdswift's suggestion imo, especially because MBID isn't something that a user would enter like other CLI arguments.

@skelly37
Copy link
Contributor Author

Also thanks for the decent feedback, gonna read the articles and mentioned methods :)

@rdswift
Copy link
Collaborator

rdswift commented Jul 20, 2022

I would limit it to URLs for now, otherwise it can get confused with normal valid local paths.

Okay. Perhaps somthing to consider in the future to better facilitate batch processing of an automated rip -> tag workflow.

If we would introduce MBIDs, they should be with identify identifier in the form release:{mbid}, recording:{mbid} or artist:{mbid}.

Agreed.

@rdswift
Copy link
Collaborator

rdswift commented Jul 20, 2022

especially because MBID isn't something that a user would enter like other CLI arguments.

Actually it easily could be part of an automated rip -> tag batch process workflow.

@zas
Copy link
Collaborator

zas commented Jul 21, 2022

I would limit it to URLs for now, otherwise it can get confused with normal valid local paths. If we would introduce MBIDs, they should be with identify identifier in the form release:{mbid}, recording:{mbid} or artist:{mbid}. This is the short form of the full MB URLs, which is in this form already supported.

What about allowing URLs in the form of:

mbid://<entity-type>/<mbid>

Examples:

mbid://release/dbd0ce67-cae6-33eb-8f5a-1143a30c2353
mbid://artist/83d91898-7763-47d7-b03b-b92132375c47

@skelly37
Copy link
Contributor Author

I would limit it to URLs for now, otherwise it can get confused with normal valid local paths. If we would introduce MBIDs, they should be with identify identifier in the form release:{mbid}, recording:{mbid} or artist:{mbid}. This is the short form of the full MB URLs, which is in this form already supported.

What about allowing URLs in the form of:

mbid://<entity-type>/<mbid>

Hm, it could be easily parsed by urllib.parse.urlparse to separate MBID from HTTP(S). Worth considering.

@skelly37
Copy link
Contributor Author

Okay, I've added the "mbid://" option, you might want to review the code now :)

picard/tagger.py Outdated Show resolved Hide resolved
picard/tagger.py Outdated Show resolved Hide resolved
skelly37 and others added 3 commits July 21, 2022 11:25
Co-authored-by: Laurent Monin <github@norz.org>
Co-authored-by: Laurent Monin <github@norz.org>
picard/tagger.py Outdated Show resolved Hide resolved
@skelly37 skelly37 requested a review from zas July 24, 2022 17:33
picard/tagger.py Outdated Show resolved Hide resolved
Tagger._parse_items_to_load() -> ParseItemsToLoad class
@skelly37 skelly37 requested a review from zas July 24, 2022 20:28
zas
zas previously approved these changes Jul 24, 2022
Copy link
Collaborator

@zas zas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

picard/tagger.py Outdated Show resolved Hide resolved
Co-authored-by: Laurent Monin <github@norz.org>
@zas zas requested a review from phw July 25, 2022 09:02
picard/tagger.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@zas zas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

picard/tagger.py Show resolved Hide resolved
ParseItemsToLoad: add __bool__() and use it to bring tagger to front
@phw phw merged commit 32fff9d into metabrainz:master Jul 31, 2022
@phw
Copy link
Member

phw commented Jul 31, 2022

Works great, thanks a lot

@skelly37 skelly37 deleted the url branch July 31, 2022 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants