Author Topic: bash script to properly rename music releases  (Read 5525 times)

Offline hanshansen

  • Decent Indexer
  • ***
  • Posts: 57
  • Helpful: +1/-0
bash script to properly rename music releases
« on: 2017-02-26, 01:45:35 pm »

I solved my problem where headphones didn't find a lot of music releases with the bash script below. The problem occurs when releases are renamed to their preDB name and don't get renamed again when getAudioInfo was successful.

The script works as following:

- gets all id's from the releases table where musicinfo_id AND a predb_id exist (>0)
- loops through all id's and gets categories_id, musicinfo_id and searchname from the releases table and artist, title and year from the musicinfo table

Since the musicinfo is far from 100% correct, the script then checks if all words from the artist and title and the year appear in the search name (= the predb name). Before that, I remove things like everything in brackets [] () from the title.  If all words match, it renames the release to "artist - title (year) category", sets predb_id=0 (so it won't be processed again) and saves the old searchname to the fromname, in case I might need it in the future. You could remove that if you don't see the need of that.

After I ran the script I update the sphinx search index with "php populate_rt_indexes.php releases_rt"

Code: [Select]

db_host=$(grep "DB_HOST" $config|cut -d"'" -f 4)
db_user=$(grep "DB_USER" $config|cut -d"'" -f 4)
db_password=$(grep "DB_PASSWORD" $config|cut -d"'" -f 4)
db_name=$(grep "DB_NAME" $config|cut -d"'" -f 4)

function mysqlcommand {
        mysql --skip-column-names -u $db_user -p$db_password -h $db_host $db_name -e "$1"

ids=$(mysqlcommand "SELECT id FROM releases WHERE musicinfo_id > 0 AND predb_id > 0;")

for id in $ids;do
        data=$(mysqlcommand "SELECT categories_id,musicinfo_id,searchname FROM releases WHERE id = '$id';")
        categories_id=$(echo $data|cut -d$'\t' -f1)
        musicinfo_id=$(echo $data|cut -d$'\t' -f2)
        searchname=$(echo $data|cut -d$'\t' -f3)

        case $categories_id in

        data=$(mysqlcommand "SELECT artist,title,year FROM musicinfo WHERE id = '$musicinfo_id';")
        artist=$(echo $data|cut -d$'\t' -f1)
        title=$(echo $data|cut -d$'\t' -f2|sed 's/\[.*\]//g;s/([^()]*)//g')
        year=$(echo $data|cut -d$'\t' -f3)
        IFS=" "
        for i in $artist $title $year;do
                i=$(echo $i|sed 's/[][()!,&:\x27]/\ /g')
                echo "$searchname"|grep -i -e "$i" 2>&1 > /dev/null||match="0"
        if [ $match -eq 1 ];then
                mysqlcommand "UPDATE releases SET searchname='$artist - $title ($year) $category',predb_id='0',fromname='$searchname' WHERE id='$id';"
                echo "$artist - $title ($year) $category                      $searchname"

As always, please do a backup before using this script. I don't take responsibility, if something goes wrong.
« Last Edit: 2017-02-26, 03:15:56 pm by hanshansen »