exclude related artists with persistent ignore table

Seb Ruiz me at sebruiz.net
Thu Aug 10 12:11:47 UTC 2006


Hi Laurent,

Could you please explain why you think this patch should be included
in Amarok - such as usability improvements, convenience or other
reasons?

cheers,
seb


On 10/08/06, Laurent <lorijho at yes.lu> wrote:
> Hi to all Amarok Fans.
>
> I've improved my previous patch. ( see
> http://mail.kde.org/pipermail/amarok/2006-August/000937.html )
>
> There is now a persistent ignored_related_artists table.
> I hope the SQL used is compatible with all DB systems supported by Amarok.
>
> The ignored_related_artists table should be created when checking the
> persistent table version (DATABASE_PERSISTENT_TABLES_VERSION)!
>
> Read the patch below or give it a try...
>
> Greetings
>
> Laurent Baum (lorijho)
>
>
> diff -Naur amarok-1.4.1/amarok/src/collectiondb.cpp amarok-1.4.1.new/amarok/src/collectiondb.cpp
> --- amarok-1.4.1/amarok/src/collectiondb.cpp    2006-07-02 21:37:44.000000000 +0200
> +++ amarok-1.4.1.new/amarok/src/collectiondb.cpp        2006-08-10 13:17:48.774354000 +0200
> @@ -3470,6 +3470,32 @@
>                .arg( escapeString( path ) ) );
>  }
>
> +void
> +CollectionDB::ignoreRelatedArtist(const QString &artist, const QString &relArtist)
> +{
> +    // create persistant ignore list for unwanted artist relations
> +    // I KNOW THIS IS BAD. The table should be created when checking persistent table versions.
> +    query( QString( "CREATE TABLE ignored_related_artists ("
> +                    "artist " + textColumnType() + ","
> +                    "suggestion " + textColumnType() + ");" )  );
> +    query( "CREATE INDEX ignored_related_artists_artist ON ignored_related_artists( artist  );"  );
> +
> +    /*check for existing artist/related artist pair*/
> +    QStringList values = query( QString( "SELECT suggestion FROM ignored_related_artists "
> +                                "WHERE artist = '%1' AND suggestion = '%2';")
> +                        .arg( escapeString( artist  ), escapeString( relArtist  )  ) );
> +    /*add only if the pair is not already in the table*/
> +    if(values.isEmpty())
> +    {
> +        query( QString( "INSERT INTO ignored_related_artists (artist, suggestion) VALUES( '%1', '%2');" )
> +                .arg( escapeString( artist ), escapeString( relArtist ) ) );
> +    }
> +    /*
> +    query( QString( "DELETE FROM related_artists WHERE artist = '%1' AND suggestion = '%2';"  )
> +                .arg(  escapeString( artist  ), escapeString( relArtist  ) )  );
> +    */
> +
> +}
>
>  bool
>  CollectionDB::isDirInCollection( QString path )
> @@ -3513,11 +3539,23 @@
>  QStringList
>  CollectionDB::similarArtists( const QString &artist, uint count )
>  {
> +    // create persistant ignore list for unwanted artist relations
> +    // I KNOW THIS IS BAD. The table should be created when checking persistent table versions.
> +    query( QString( "CREATE TABLE ignored_related_artists ("
> +                    "artist " + textColumnType() + ","
> +                    "suggestion " + textColumnType() + ");" )  );
> +    query( "CREATE INDEX ignored_related_artists_artist ON ignored_related_artists( artist  );"  );
> +
>      QStringList values;
> -
> +    //exclude previously ignored related artists when querying for related artists
> +    values = query( QString( "SELECT suggestion FROM related_artists WHERE artist = '%1' "
> +                               "EXCEPT SELECT suggestion FROM ignored_related_artists WHERE artist = '%1' "
> +                               "LIMIT %2 OFFSET 0;"  )
> +                               .arg( escapeString( artist  ), QString::number( count  )  ) );
> +    /*
>      values = query( QString( "SELECT suggestion FROM related_artists WHERE artist = '%1' LIMIT %2 OFFSET 0;" )
>                                   .arg( escapeString( artist ), QString::number( count ) ) );
> -
> +    */
>      if ( values.isEmpty() )
>          Scrobbler::instance()->similarArtists( artist );
>
> diff -Naur amarok-1.4.1/amarok/src/collectiondb.h amarok-1.4.1.new/amarok/src/collectiondb.h
> --- amarok-1.4.1/amarok/src/collectiondb.h      2006-07-02 21:37:44.000000000 +0200
> +++ amarok-1.4.1.new/amarok/src/collectiondb.h  2006-08-09 22:00:52.292038750 +0200
> @@ -270,7 +270,8 @@
>          void removeSongsInDir( QString path );
>          void removeSongs( const KURL::List& urls );
>          void updateDirStats( QString path, const long datetime, const bool temporary = false );
> -
> +        /*member function that add a artist/related artist to the ignore table*/
> +        void ignoreRelatedArtist(const QString &artist, const QString &relArtist);
>          //song methods
>          bool addSong( MetaBundle* bundle, const bool incremental = false );
>          void doATFStuff( MetaBundle *bundle, const bool tempTables = true );
> diff -Naur amarok-1.4.1/amarok/src/contextbrowser.cpp amarok-1.4.1.new/amarok/src/contextbrowser.cpp
> --- amarok-1.4.1/amarok/src/contextbrowser.cpp  2006-07-02 21:37:44.000000000 +0200
> +++ amarok-1.4.1.new/amarok/src/contextbrowser.cpp      2006-08-10 13:14:57.287636750 +0200
> @@ -706,7 +706,8 @@
>
>  void ContextBrowser::slotContextMenu( const QString& urlString, const QPoint& point )
>  {
> -    enum { APPEND, ASNEXT, MAKE, MEDIA_DEVICE, INFO, TITLE, RELATED, SUGGEST, FAVES, FRESHPODCASTS, NEWALBUMS, FAVALBUMS };
> +    //enum { APPEND, ASNEXT, MAKE, MEDIA_DEVICE, INFO, TITLE, RELATED, SUGGEST, FAVES, FRESHPODCASTS, NEWALBUMS, FAVALBUMS };
> +    enum { APPEND, ASNEXT, MAKE, MEDIA_DEVICE, INFO, TITLE, RELATED, SUGGEST, FAVES, FRESHPODCASTS, NEWALBUMS, FAVALBUMS, IGNORE_REL_ARTIST }; /*added ID for ignoring related artist*/
>      debug() << "url string: " << urlString << endl;
>
>      if( urlString.startsWith( "musicbrainz" ) ||
> @@ -788,6 +789,14 @@
>              menu.changeTitle( TITLE, i18n("Artist") );
>              menu.changeItem( INFO,   i18n("Edit Artist &Information..." ) );
>              menu.changeItem( ASNEXT, i18n("&Queue Artist's Songs") );
> +            /*add menu item for excluding related artist only for the current track artist's related artists or recursively related artists*/
> +            const MetaBundle &currentTrack = EngineController::instance()->bundle();
> +            /*this->m_artist is set when browsing (recursively) related artists*/
> +            if (!currentTrack.artist().isEmpty() || !this->m_artist.isEmpty())
> +            {
> +                menu.insertSeparator();
> +                menu.insertItem( SmallIconSet( amaroK::icon( "remove_from_playlist" ) ), i18n( "E&xclude from similar artists list" ), IGNORE_REL_ARTIST );
> +            }
>          }
>          if ( url.protocol() == "album" )
>          {
> @@ -909,6 +918,40 @@
>          MediaBrowser::queue()->addURLs( urls );
>          break;
>
> +    /*add the artist/suggestion to the ignore table*/
> +    case IGNORE_REL_ARTIST:
> +    {
> +        /*this->m_artist is set so we have to consider a related artist as primary artist that has related artist*/
> +        QString curArtist;
> +        if ( !this->m_artist.isEmpty() )
> +        {
> +            curArtist=this->m_artist;
> +        }
> +        else
> +        {
> +            const MetaBundle &currentTrack = EngineController::instance()->bundle();
> +            curArtist = currentTrack.artist();
> +        }
> +        QString relArtist=url.path();
> +        if ( !curArtist.isEmpty() )
> +        {
> +            CollectionDB::instance()->ignoreRelatedArtist( curArtist, relArtist );
> +        }
> +        /*refresh related artist list in contextbrowser*/
> +        m_showRelated = !menu.isItemChecked( RELATED );
> +        amaroK::config( "ContextBrowser" )->writeEntry( "ShowRelated", m_showRelated );
> +        m_dirtyCurrentTrackPage = true;
> +        showCurrentTrack();
> +
> +        /*
> +        //debug() << "currentTrack.artist(): " << currentTrack.artist() << endl;
> +        debug() << "this->m_artist: " << this->m_artist << endl;
> +        debug() << "selected curArtist: " << curArtist << endl;
> +        debug() << "url.path(): " << url.path() << endl;
> +        */
> +
> +        break;
> +    }
>      }
>  }
>
>
>
> _______________________________________________
> Amarok mailing list
> Amarok at kde.org
> https://mail.kde.org/mailman/listinfo/amarok
>
>
>


-- 
http://www.sebruiz.net/



More information about the Amarok mailing list