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

Implement "Create new release on musicbrainz" feature #5300

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
445 changes: 429 additions & 16 deletions beetsplug/mbsubmit.py

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions beetsplug/mbsubmit/templates/create_release_add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<meta charset="UTF-8">
<html>
<body>
<form action="https://musicbrainz.org/release/add" method="post" style="display: none">
{% for k,v in task.formdata.items() %}
<input type="hidden" name="{{ k }}" value="{{ v }}">
{% endfor %}
<input type="submit">
</form>
<script>document.forms[0].submit()</script>
</body>
6 changes: 6 additions & 0 deletions beetsplug/mbsubmit/templates/create_release_complete_add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!doctype html>
<meta charset="UTF-8">
<html>
<body>
<p>Release <a href="https://www.musicbrainz.org/release/{{ task.result_release_mbid }}">{{ task.result_release_mbid }}</a> added. You can close this browser window now and return to beets.</p>
</body>
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Unreleased

Changelog goes here! Please add your entry to the bottom of one of the lists below!

New features:

* :doc:`plugins/mbsubmit`: Add new prompt choice "Create release on musicbrainz", automating
the process as much as possible.

Bug fixes:

* Improved naming of temporary files by separating the random part with the file extension.
Expand Down
62 changes: 61 additions & 1 deletion docs/plugins/mbsubmit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,24 @@ that is parseable by MusicBrainz's `track parser`_. The prompt choices are:
- Print the tracks to stdout in a format suitable for MusicBrainz's `track
parser`_.

- Create a new release on MusicBrainz, opens
https://musicbrainz.org/release/add in a new browser window with
fields pre-populated using existing metadata.

- Open the program `Picard`_ with the unmatched folder as an input, allowing
you to start submitting the unmatched release to MusicBrainz with many input
fields already filled in, thanks to Picard reading the preexisting tags of
the files.

To create new releases on MusicBrainz with this plugin you need to install the
`PyJWT`_ library with:

.. code-block:: console

$ pip install "beets[mbsubmit]"
Copy link
Contributor

Choose a reason for hiding this comment

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

We're now recommending that people install and manage beets with poetry, so if you wouldn't mind changing this, it should be poetry install beets --extras mbsubmit.


.. _PyJWT: https://pyjwt.readthedocs.io/en/stable/

For the last option, `Picard`_ is assumed to be installed and available on the
machine including a ``picard`` executable. Picard developers list `download
options`_. `other GNU/Linux distributions`_ may distribute Picard via their
Expand All @@ -34,7 +47,7 @@ choice is demonstrated::
No matching release found for 3 tracks.
For help, see: https://beets.readthedocs.org/en/latest/faq.html#nomatch
[U]se as-is, as Tracks, Group albums, Skip, Enter search, enter Id, aBort,
Print tracks, Open files with Picard? p
Print tracks, Open files with Picard, Create release on musicbrainz? p
01. An Obscure Track - An Obscure Artist (3:37)
02. Another Obscure Track - An Obscure Artist (2:05)
03. The Third Track - Another Obscure Artist (3:02)
Expand All @@ -56,6 +69,24 @@ the recommended workflow is to copy the output of the ``Print tracks`` choice
and paste it into the parser that can be found by clicking on the
"Track Parser" button on MusicBrainz "Tracklist" tab.

Create release on MusicBrainz
-----------------------------

The https://musicbrainz.org/release/add page can be seeded with existing
metadata, as described here: https://musicbrainz.org/doc/Development/Seeding/Release_Editor.
This works in the following way:

1. When you select the option to create a release, a local web server is started.
2. You point your web browser to that web server, either by clicking a link
displayed in the console, or by having beets open the link automatically.
3. The opened web page will redirect you to MusicBrainz, and the form fields
will be prepopulated with metadata found in the files. MusicBrainz may
ask you to confirm the action.
4. You edit the release on MusicBrainz and click "Enter edit" to finish.
5. MusicBrainz will redirect you to the local web server, submitting the ID
of the newly created release.
6. beets will add the release using the release ID returned by MusicBrainz.

Configuration
-------------

Expand All @@ -70,12 +101,41 @@ file. The following options are available:
Default: ``medium`` (causing the choice to be displayed for all albums that
have a recommendation of medium strength or lower). Valid values: ``none``,
``low``, ``medium``, ``strong``.
- **create_release_server_hostname**: The host name of the local web server used for the
'Create release on musicbrainz' functionality. The default is '127.0.0.1'.
Adjust this if beets is running on a different host in your local network.
Be aware that this web server is not secured in any way.
- **create_release_server_port**: The port for the local web server. By default,
beets will choose a random available port for you.
- **create_release_method**: Either 'open_browser' to automatically open a new
window/tab in your local browser or 'show_link' to simply show the link on
the console.
- **create_release_await_mbid**: Whether or not to wait for you to create the
release on MusicBrainz. If true, waits for a callback from MusicBrainz with
the new release ID and proceeds to add the unmatched album using that Id.
If false, simply shows the select action prompt again. Default: true.
- **create_release_default_type**: The default release type when none can be
identified from the unmatched files.
See https://musicbrainz.org/doc/Release_Group/Type
- **create_release_default_language**: The default language as an `ISO 639-3`_
code (eng, deu, jpn).
- **create_release_default_script**: The default script as an `ISO 15924`_ code
(Latn, Cyrl).
- **create_release_default_status**: The default status. Possible values:
official, promotion, bootleg, pseudo-release.
- **create_release_default_packaging**: The default packaging.
See https://musicbrainz.org/doc/Release/Packaging
- **create_release_default_edit_note**: The default edit note when submitting
new releases.
- **picard_path**: The path to the ``picard`` executable. Could be an absolute
path, and if not, ``$PATH`` is consulted. The default value is simply
``picard``. Windows users will have to find and specify the absolute path to
their ``picard.exe``. That would probably be:
``C:\Program Files\MusicBrainz Picard\picard.exe``.

.. _ISO 639-3: https://en.wikipedia.org/wiki/List_of_ISO_639-3_codes
.. _ISO 15924: https://en.wikipedia.org/wiki/ISO_15924

Please note that some values of the ``threshold`` configuration option might
require other ``beets`` command line switches to be enabled in order to work as
intended. In particular, setting a threshold of ``strong`` will only display
Expand Down
37 changes: 35 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ reflink = { version = "*", optional = true }
requests = { version = "*", optional = true }
requests-oauthlib = { version = ">=0.6.1", optional = true }
soco = { version = "*", optional = true }
pyjwt = { version = "*", optional = true }
waitress = { version = "*", optional = true }

[tool.poetry.group.test.dependencies]
beautifulsoup4 = "*"
Expand All @@ -80,6 +82,8 @@ rarfile = "*"
reflink = "*"
requests_oauthlib = "*"
responses = ">=0.3.0"
pyjwt = "*"
waitress = "*"

[tool.poetry.group.format.dependencies]
isort = { version = "<5.14", extras = ["colors"] }
Expand Down Expand Up @@ -127,6 +131,7 @@ kodiupdate = ["requests"]
lastgenre = ["pylast"]
lastimport = ["pylast"]
lyrics = ["beautifulsoup4", "langdetect", "requests"]
mbsubmit = ["pyjwt", "flask", "waitress"]
metasync = ["dbus-python"]
mpdstats = ["python-mpd2"]
plexupdate = ["requests"]
Expand Down
Loading
Loading