[multimedia/kid3] /: Support enter URL as search into import dialog (Discogs, ...)

Urs Fleisch null at kde.org
Sat Jul 9 10:26:53 BST 2022


Git commit be999e8e6f4f0944f51f0e65bca364b465951c9a by Urs Fleisch.
Committed on 09/07/2022 at 08:56.
Pushed by ufleisch into branch 'master'.

Support enter URL as search into import dialog (Discogs, ...)

If the search was already done in the browser, its URL can be entered
into the first search field (normally used for the artist) of the
corresponding search dialog. Supported URLs are https://www.amazon.com/,
https://www.discogs.com/, https://gnudb.org/, https://musicbrainz.org/.

BUG 453270

M  +5    -0    doc/en/index.docbook
M  +14   -0    src/plugins/amazonimport/amazonimporter.cpp
M  +14   -0    src/plugins/discogsimport/discogsimporter.cpp
M  +29   -0    src/plugins/freedbimport/freedbimporter.cpp
M  +14   -0    src/plugins/musicbrainzimport/musicbrainzimporter.cpp

https://invent.kde.org/multimedia/kid3/commit/be999e8e6f4f0944f51f0e65bca364b465951c9a

diff --git a/doc/en/index.docbook b/doc/en/index.docbook
index ca874030..459c8569 100644
--- a/doc/en/index.docbook
+++ b/doc/en/index.docbook
@@ -1135,6 +1135,11 @@ When satisfied with the displayed tracks, they
 can be imported by terminating the import dialog with
 <guibutton>OK</guibutton>.
 </para>
+<para>
+If you already have a search result open in the web browser, you can enter the
+URL into the first search field. The result will then appear in the album list
+and can be directly imported into &kid3;.
+</para>
 <para id="import-discogs">
 A search on the Discogs server can be performed using
 <guibutton>Discogs</guibutton>. As in the <guibutton>gnudb.org</guibutton> dialog,
diff --git a/src/plugins/amazonimport/amazonimporter.cpp b/src/plugins/amazonimport/amazonimporter.cpp
index d6572591..ec3615db 100644
--- a/src/plugins/amazonimport/amazonimporter.cpp
+++ b/src/plugins/amazonimport/amazonimporter.cpp
@@ -319,6 +319,20 @@ void AmazonImporter::sendFindQuery(
   const ServerImporterConfig* cfg,
   const QString& artist, const QString& album)
 {
+  // If an URL is entered in the first search field, its result will be directly
+  // available in the album results list.
+  if (artist.startsWith(QLatin1String("https://www.amazon.com/"))) {
+    const int catBegin = 23;
+    int catEnd = artist.indexOf(QLatin1Char('/'), catBegin);
+    if (catEnd > catBegin) {
+      m_albumListModel->clear();
+      m_albumListModel->appendItem(
+            artist,
+            artist.mid(catBegin, catEnd - catBegin),
+            artist.mid(catEnd + 1));
+      return;
+    }
+  }
   /*
    * Query looks like this:
    * http://www.amazon.com/gp/search/ref=sr_adv_m_pop/?search-alias=popular&field-artist=amon+amarth&field-title=the+avenger
diff --git a/src/plugins/discogsimport/discogsimporter.cpp b/src/plugins/discogsimport/discogsimporter.cpp
index a293c41f..a8da7a91 100644
--- a/src/plugins/discogsimport/discogsimporter.cpp
+++ b/src/plugins/discogsimport/discogsimporter.cpp
@@ -1473,6 +1473,20 @@ void DiscogsImporter::sendFindQuery(
   const ServerImporterConfig* cfg,
   const QString& artist, const QString& album)
 {
+  // If an URL is entered in the first search field, its result will be directly
+  // available in the album results list.
+  if (artist.startsWith(QLatin1String("https://www.discogs.com/"))) {
+    const int catBegin = 24;
+    int catEnd = artist.indexOf(QLatin1Char('/'), catBegin);
+    if (catEnd > catBegin) {
+      m_htmlImpl->albumListModel()->clear();
+      m_htmlImpl->albumListModel()->appendItem(
+            artist,
+            artist.mid(catBegin, catEnd - catBegin),
+            artist.mid(catEnd + 1));
+      return;
+    }
+  }
   m_impl = selectImpl(cfg);
   m_impl->sendFindQuery(cfg, artist, album);
 }
diff --git a/src/plugins/freedbimport/freedbimporter.cpp b/src/plugins/freedbimport/freedbimporter.cpp
index 6decacb4..475e262a 100644
--- a/src/plugins/freedbimport/freedbimporter.cpp
+++ b/src/plugins/freedbimport/freedbimporter.cpp
@@ -324,6 +324,35 @@ void FreedbImporter::sendFindQuery(
   const ServerImporterConfig*,
   const QString& artist, const QString& album)
 {
+  // If an URL is entered in the first search field, its result will be directly
+  // available in the album results list.
+  if (artist.startsWith(QLatin1String("https://gnudb.org/"))) {
+    const int catBegin = 18;
+    int catEnd = artist.indexOf(QLatin1Char('/'), catBegin);
+    if (catEnd > catBegin) {
+      static QStringList categories({
+        QLatin1String("blues"),
+        QLatin1String("classical"),
+        QLatin1String("country"),
+        QLatin1String("data"),
+        QLatin1String("folk"),
+        QLatin1String("jazz"),
+        QLatin1String("newage"),
+        QLatin1String("reggae"),
+        QLatin1String("rock"),
+        QLatin1String("soundtrack"),
+        QLatin1String("misc")
+      });
+      QString id = artist.mid(catEnd + 1);
+      for (const auto& category : categories) {
+        if (id.startsWith(category.mid(0, 2))) {
+          m_albumListModel->clear();
+          m_albumListModel->appendItem(artist, category, id.mid(2));
+          return;
+        }
+      }
+    }
+  }
   // At the moment, only www.gnudb.org has a working search
   // so we always use this server for find queries.
   sendRequest(QString::fromLatin1(gnudbServer), QLatin1String("/search/") +
diff --git a/src/plugins/musicbrainzimport/musicbrainzimporter.cpp b/src/plugins/musicbrainzimport/musicbrainzimporter.cpp
index ca0b956c..80ac319c 100644
--- a/src/plugins/musicbrainzimport/musicbrainzimporter.cpp
+++ b/src/plugins/musicbrainzimport/musicbrainzimporter.cpp
@@ -614,6 +614,20 @@ void MusicBrainzImporter::sendFindQuery(
   const QString& artist, const QString& album)
 {
   Q_UNUSED(cfg)
+  // If an URL is entered in the first search field, its result will be directly
+  // available in the album results list.
+  if (artist.startsWith(QLatin1String("https://musicbrainz.org/"))) {
+    const int catBegin = 24;
+    int catEnd = artist.indexOf(QLatin1Char('/'), catBegin);
+    if (catEnd > catBegin) {
+      m_albumListModel->clear();
+      m_albumListModel->appendItem(
+            artist,
+            artist.mid(catBegin, catEnd - catBegin),
+            artist.mid(catEnd + 1));
+      return;
+    }
+  }
   /*
    * Query looks like this:
    * http://musicbrainz.org/ws/2/release?query=artist:wizard%20AND%20release:odin


More information about the kde-doc-english mailing list