Exporting album covers
Maxime. Haselbauer
maxime.haselbauer at googlemail.com
Tue Mar 26 07:06:29 UTC 2013
If you are using mp3 files, I think it is also possible to save the cover
picture inside the mp3 itself, so that it always remains embeded.
I think there is an option like that in amarok configuration. (Or maybe I
dreamt ^^^) When I copy mp3 files to my N900 at least, all covers come
along with the mp3s.
2013/3/25 Scott Yanke <scott.yanke at charter.net>
> One of the side effects of having the many different devices we can play
> music on is that we often want to see cover images to go with the sound.
> It's easy enough to copy our music files from Amarok to a tablet or MP3
> player. The hard part has been getting the covers to go along for the
> ride. In Amarok, which is my core music repository, the covers are all
> uniquely named in the .kde/share/apps/amarok/albumcovers/large directory.
> That works great for Amarok, but not so well for one of my tablets.
>
> To make things easier for those who want the same cover image Amarok uses
> to also be on their tablet, I've put together a quick little python script
> that gets the unique image name, and creates a copy command to put that
> image in the directory where the albums tracks are (presumably). It isn't
> pretty, and it isn't perfect, but it does go through albums quickly and
> creates the proper output (mostly). It's simple enough that anyone can
> fine-tune it for their own needs.
>
> The python script is less than 60 lines long. Given that I am using the
> embedded mysql with Amarok, it starts mysql as a separate task to do the
> SQL against, then shuts it down when finished. That was easier than trying
> to learn embedded mysql. The script simply writes the output to the
> terminal. It's easy enough to redirect to a file for verification and
> editing.
>
> In the script, replace "scott" with whatever your login name is. My music
> files are in a directory structure with a base of /shared/music. The final
> print command corrects for the name received from Amarok so the copy of the
> cover image will go into the correct album location within that base. The
> imghdr module is used to obtain the image type, like jpeg or png. The
> script corrects the result from jpeg to jpg, although it probably doesn't
> have to. Because the result of the select on the directories table starts
> with "./", a temporary variable is used to help trim that off the front of
> the path.
>
> Note that this script does nothing with images that are not in the users
> amarok/albumcovers directory. It also does not change anything within the
> Amarok database - it is a read-only set of statements to figure out what
> the image is called.
>
> You are welcome to use this script however you want. It has helped me
> with getting my album covers out of Amarok and onto my tablets. If someone
> wanted to burn a CD of their music, the images might help them also. Run
> time on this is less than 20 seconds for 1,600 albums. Personally I wish
> Cover Manager had an export tool that did this.
>
> #!/usr/bin/python
> # -*- coding: utf-8 -*-
>
> import MySQLdb as mdb
> import sys
> import os
> import time
> import imghdr
>
> con = None
> # start an instance of mysqld to query against.
> os.system("/usr/libexec/mysqld
> --defaults-file=/home/scott/.kde/share/apps/amarok/my.cnf
> --socket=/var/local/mysql_amarok.sock
> --datadir=/home/scott/.kde/share/apps/amarok/mysqle
> --default-storage-engine=MyISAM --skip-grant-tables --port=33306
> --user=scott &")
> # wait for mysqld to fully start up.
> time.sleep(10)
>
> try:
> # open a connection to the instance of mysqld that was just started. Note
> the port and unix_socket requirements.
> con = mdb.Connect(host='localhost', port=33306, user='scott',
> passwd='', db='amarok', unix_socket='/var/local/mysql_amarok.sock')
>
> cur.execute("select id, image, name from albums order by albums.id")
> rows = cur.fetchall()
> for row in rows:
> if (row[1] > 0):
> album_name = row[2];
> cur1 = con.cursor()
> # for each album we will loop through getting the image path,
> track location, url of the tracks, and finally the directory name of A
> track for that album
> cur1.execute('SELECT images.id, images.path FROM images,
> albums WHERE albums.image = images.id and albums.id = %s',(row[0]))
> if (cur1.rowcount > 0):
> data = cur1.fetchone()
> cached_image_path = data[1];
> # only deal with images that are cached, and not elsewhere
> if (cached_image_path.find('/home/scott',0) > -1):
> img_type = imghdr.what(cached_image_path)
> if (img_type == 'jpeg'):
> img_type = 'jpg'
> cur1.execute('select url from tracks where
> tracks.album = %s',(row[0]))
> if (cur1.rowcount > 0):
> url_id = cur1.fetchone()
> if (url_id[0] > 0):
> cur1.execute('select directory from urls where
> id = %s',(url_id[0]))
> directory_id = cur1.fetchone()
> cur1.execute('select dir from directories
> where id = %s',(directory_id[0]))
> if (cur1.rowcount > 0):
> dir_name = cur1.fetchone()
> # this makes it easier to trim the first
> two characters from the directory name when building the print line
> t1 = dir_name[0]
> print 'cp -i "%s" "/shared/%s%s.%s"' %
> (cached_image_path,t1[2:],album_name,img_type)
> cur1.close
> cur.close
>
> except mdb.Error, e:
>
> print "Error %d: %s" % (e.args[0],e.args[1])
> sys.exit(1)
>
> finally:
>
> if con:
> con.close()
> os.system("mysqladmin --socket=/var/local/mysql_amarok.sock
> shutdown")
>
>
> ===============================================================================================================================
> This is an example of the output of the script that was used to copy the
> images to the music directories. As you can see, the final file names are
> the album names as Amarok knows them. The copy is interactive, just to
> make sure I'm not wiping out an existing image I might want.
>
> cp -i
> "/home/scott/.kde/share/apps/amarok/albumcovers/large/ed6cdb11ab1fe164cf8f27dc6496b7e9_"
> "/shared/music/Beatles/Abbey Road/Abbey Road.jpg"
> cp -i
> "/home/scott/.kde/share/apps/amarok/albumcovers/large/e212883f2b4d21cb182b66dcd2406c44"
> "/shared/music/Beatles/Beatles for Sale/Beatles For Sale.jpg"
> cp -i
> "/home/scott/.kde/share/apps/amarok/albumcovers/large/6cd152daca5a3a7614e77f6868338d80"
> "/shared/music/Beatles/Hard Days Night/A Hard Day's Night.jpg"
> cp -i
> "/home/scott/.kde/share/apps/amarok/albumcovers/large/4c0968a4a64b01360f29c769b6e1e140"
> "/shared/music/Beatles/Help/Help!.jpg"
> cp -i
> "/home/scott/.kde/share/apps/amarok/albumcovers/large/25f700f3909b13004413c72f4085f7cf"
> "/shared/music/Beatles/Let It Be/Let It Be.jpg"
> cp -i
> "/home/scott/.kde/share/apps/amarok/albumcovers/large/8940ae83622110785b68ed3f934336d4"
> "/shared/music/Beatles/Magical Mystery Tour/Magical Mystery Tour.jpg"
> cp -i
> "/home/scott/.kde/share/apps/amarok/albumcovers/large/73fd61a9ae7606c343030447310c014a"
> "/shared/music/Beatles/Past Masters/Past Masters.jpg"
> cp -i
> "/home/scott/.kde/share/apps/amarok/albumcovers/large/18aed807d397bc66404c56931c7c66e0"
> "/shared/music/Beatles/Please Please Me/Please Please Me.jpg"
> cp -i
> "/home/scott/.kde/share/apps/amarok/albumcovers/large/8776808ff700ded76d32cc3b373e263c"
> "/shared/music/Beatles/Revolver/Revolver.jpg"
> cp -i
> "/home/scott/.kde/share/apps/amarok/albumcovers/large/887c8359aa717138f0ef5cb3dd054eef"
> "/shared/music/Beatles/Rubber Soul/Rubber Soul.jpg"
> cp -i
> "/home/scott/.kde/share/apps/amarok/albumcovers/large/9d6bdee11a958449e06d3bac53c5bd76_"
> "/shared/music/Beatles/Sgt Peppers Lonely Hearts Club Band/Sgt. Pepper's
> Lonely Hearts Club Band.jpg"
>
>
>
> --
> Scott Yanke
>
> _______________________________________________
> Amarok mailing list
> Amarok at kde.org
> https://mail.kde.org/mailman/listinfo/amarok
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/amarok/attachments/20130326/c500b25d/attachment.html>
More information about the Amarok
mailing list