+ Reply to Thread
Results 1 to 9 of 9

Album art in Linux with Amarok

This is a discussion on Album art in Linux with Amarok within the Firmware forums, part of the miniPlayer M6 / SL category; Hi. Given that albumart-qt doesn't seem to be active anymore (and I wanted to run it as a cron job), ...

  1. #1
    Passing By
    Join Date
    Oct 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Album art in Linux with Amarok

    Hi. Given that albumart-qt doesn't seem to be active anymore (and I wanted to run it as a cron job), I wrote a small bash script to copy albumart from Amarok's library to my Meizu M6.

    It first tries to find album art stored under "~/.kde/share/apps/amarok/albumcovers/large", and if it doesn't find anything, it looks in amarok's database for an associated cover containing "front" or "cover" in it (I'm sure there's a better way to do it, but I couldn't think of any).

    To use, first configure, then copy, paste, save, chmod +x and run.

    Hope it's useful, and if you find any bugs or have any suggestions please let me know. Cheers.

    Code:
    #!/bin/bash
    #
    #       Redistribution and use in source and binary forms, with or without
    #       modification, are permitted provided that the following conditions are
    #       met:
    #       
    #       * Redistributions of source code must retain the above copyright
    #         notice, this list of conditions and the following disclaimer.
    #       * Redistributions in binary form must reproduce the above
    #         copyright notice, this list of conditions and the following disclaimer
    #         in the documentation and/or other materials provided with the
    #         distribution.
    #       * Neither the name of the  nor the names of its
    #         contributors may be used to endorse or promote products derived from
    #         this software without specific prior written permission.
    #       
    #       THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    #       "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    #       LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    #       A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    #       OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    #       SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    #       LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    #       DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    #       THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    #       (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    #       OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    #
    #       Copyleft 2007 wishmechaos
    #        
    #        Thanks to Neil Moore @ #bash for the help
    #
    #    16-oct-07    0.1     Initial Version
    #    17-oct-07    0.2     Added support for SQlite
    #    18-oct-07    0.3     Added some support for copying album art not in
    #                         amaroK's cover directory.
    #                0.31     Cleaned up a little
    #                0.32    Renamed some variables, cleaned up a bit more
    
    
    #################################
    #        Configuration            #
    #################################
    
    # Output directory
    coversdir="/media/datos/covers"
    
    # Uncomment one of the following
    #database=mysql
    #database=sqlite
    
    # Directory where amaroK's album art is
    cd ~/.kde/share/apps/amarok/albumcovers/large
    
    #################################
    #        End Configuration        #
    #################################
    
    # Check if Amarok is running
    dcop amarok >/dev/null 2>&1
    if [[ $? = 1 ]]; then echo "Amarok must be running"; exit 1; fi
    
    # Check if covers directory exists
    if [[ ! -d "$coversdir" ]]; then echo "$coversdir does not exist"; exit 1; fi
    
    # Check if imagemagick is installed and in your path
    convert >/dev/null 2>&1
    if [[ $? = 127 ]]; then echo "This script requires imagemagick"; exit 1; fi
    
    # Check if md5sum is installed and in your path
    md5sum --version >/dev/null 2>&1
    if [[ $? = 127 ]]; then echo "This script requires md5sum"; exit 1; fi
    
        # function to actually check if the file exists and copy it
        copyalbumart() {
             # check for forbidden characters
            if [[ "$outputfile" =~ [\"^\/?*:\<\>] ]]; then
                echo "Can't copy "$artist" - "$album", since it would contain forbidden characters"
            else
                convert "$inputfile" -resize 80x80 "$coversdir"/"$outputfile".jpg
            fi    
        }
    
    copycovers() {
        while IFS=^ read artist album; do
         # concatenate, lowercase, md5sum
        inputfile=$(echo -n $artist$album | tr '[:upper:]' '[:lower:]' | md5sum -)
         # strip trailing characters
        inputfile=${inputfile&#37;???}
         # format for Meizu (%album%artist)
        outputfile=$album$artist
        if [[ -f "$inputfile" ]]; then        # if the file exists
            copyalbumart
        else
            # If it doesn't exist in amarok's folder, let's see if we
            # can find one elsewhere. This'll only match one if it
            # contains the word 'cover' or 'front'. If you've got any
            # more matching ideas, please tell me
            case "$database" in
                "mysql") inputfile=$(dcop amarok collection query "SELECT CONCAT(devices.lastmountpoint, '/', images.path) FROM images, devices WHERE devices.id = images.deviceid AND images.artist='$artist' AND images.album='$album' AND (images.path like '%front%' OR images.path like '%cover%') LIMIT 1");;
                "sqlite") inputfile=$(dcop amarok collection query "SELECT devices.lastmountpoint || '/' || images.path FROM images, devices WHERE devices.id = images.deviceid AND images.artist='$artist' AND images.album='$album' AND (images.path like '%front%' OR images.path like '%cover%') LIMIT 1");;
            esac
            if [[ -f "$inputfile" ]]; then
                copyalbumart
            else        
                echo "Can't find a cover for "$artist" - "$album""
            fi
        fi
    done
    }
    
    # Get Artist^Album pair (using ^ as IFS, if you have an artist or 
    # album with this character this'll probably fail)
    
    case "$database" in
        "mysql") dcop amarok collection query "SELECT DISTINCT CONCAT(artist.name,'^',album.name) FROM album, artist, tags WHERE album.id = tags.album AND artist.id = tags.artist" | copycovers;;
        "sqlite") dcop amarok collection query "SELECT DISTINCT artist.name || '^' || album.name FROM album, artist, tags WHERE album.id = tags.album AND artist.id = tags.artist" | copycovers;;
        *) echo "Set your database under Configuration";;
    esac
    Last edited by wishmechaos; 10-18-2007 at 08:22 PM. Reason: Updated script yet again

  2. #2
    Passing By
    Join Date
    Apr 2007
    Location
    Germany
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This looks good, but sadly doesn't work for me... I always get this:
    d41d8cd98f00b204e9800998ecf8427e ( - ) doesn't exist


    Don't know exactly what it's supposed to mean?!
    Other then that, great!

  3. #3
    Passing By
    Join Date
    Oct 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I keep on gettin that too

  4. #4
    Passing By
    Join Date
    Oct 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    edit: nevermind, I already figured it out, SQlite uses a different concat format. Updated my original post, remember to uncomment the proper line
    Last edited by wishmechaos; 10-17-2007 at 10:20 PM.

  5. #5
    Freshman
    Join Date
    Jul 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, just what I wanted. As I even use amarok to transfer the music lists to the meizu, this is great.

    Now, it would be perfect if we could convince amarok developers to add this. Or even to allow scripts to be used in the "transfar to device" module, as they are in the rest, so that we could fine tune it to our meizus.

  6. #6
    Passing By
    Join Date
    Oct 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SQlite or Mysql

    How do i tell what i'm using, SQlite or Mysql?
    EDIT: don't worry figured it out
    Last edited by jaymz34; 10-18-2007 at 08:11 AM.

  7. #7
    Passing By
    Join Date
    Oct 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jaymz34 View Post
    How do i tell what i'm using, SQlite or Mysql?
    If you don't know about it, then you're using SQlite. If you want to check, go to Settings -> Configure amaroK -> Collection, and under "Collection Database" you can see which one you're using

    @ jbernardo
    Glad to see it's useful to someone else You could try to submit a feature request... I asked around in IRC and basically got told 'use a script' (and so I did!) but maybe if enough of us ask for it...

    I've just added a little support for copying covers not in amaroK's own directory, but it may be a little shaky.
    Last edited by wishmechaos; 10-18-2007 at 08:28 AM.

  8. #8
    Passing By
    Join Date
    Oct 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change Output

    I have my music organized by just the album name and not artist - album. how can i modify the script to output to album name?

  9. #9
    Passing By
    Join Date
    Oct 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jaymz34 View Post
    I have my music organized by just the album name and not artist - album. how can i modify the script to output to album name?
    I thought only &#37;album%artist.jpg worked for the Meizu, but if for some reason you want to output %album.jpg, you'd need to change the line

    Code:
    outputfile=$album$artist
    to

    Code:
    outputfile=$album
    (caveat: download the latest version, I renamed some variables)

    Cheers.
    Last edited by wishmechaos; 10-18-2007 at 09:09 AM. Reason: simpler way to do it


 

Similar Threads

  1. Mounting M6 in Linux
    By jieryn in forum Technical
    Replies: 7
    Last Post: 06-25-2009, 04:35 PM
  2. Meizu M6 and linux
    By snapster in forum Technical
    Replies: 22
    Last Post: 04-22-2008, 09:49 PM
  3. Using the M3 with Linux
    By TUCG in forum music card M3
    Replies: 4
    Last Post: 08-28-2007, 07:27 PM
  4. album artist tag conflicts with album tag
    By wolffsed in forum Technical
    Replies: 1
    Last Post: 02-22-2007, 08:11 PM
  5. Avidemux / Linux
    By scaglifr in forum Video and Imaging
    Replies: 1
    Last Post: 02-01-2007, 01:30 PM