the thumbnailing library filename ends with .0
[mussorgsky] / src / album_art_spec.py
1 import os
2 import md5
3 import unicodedata
4 import string
5
6 COVERS_LOCATION = os.getenv ("HOME") + "/.cache/media-art/"
7 THUMBS_LOCATION = os.getenv ("HOME") + "/.thumbnails/cropped/"
8
9 # Hardcoded locations for testing in scratchbox 
10 #
11 #COVERS_LOCATION = "/home/user/.cache/media-art/"
12 #THUMBS_LOCATION = "/home/user/.thumbnails/cropped/"
13
14 # Do this only once...
15 import ctypes
16 clib = ctypes.CDLL ("libhildonthumbnail.so.0")
17
18 album_art_func = clib.hildon_albumart_get_path
19 album_art_func.restype = ctypes.c_char_p
20
21 def getCoverArtFileName (album):
22     return album_art_func (None, album, "album")
23     
24 def getCoverArtThumbFileName (album):
25     artFile = getCoverArtFileName (album)
26     if not artFile.startswith ("file://"):
27         artFile = "file://" + artFile
28     thumbFile = THUMBS_LOCATION + md5.new (artFile).hexdigest() + ".jpeg"
29     return thumbFile
30
31 def get_thumb_filename_for_path (path):
32     if not path.startswith ("file://"):
33         path = "file://" + path
34     thumbnail = THUMBS_LOCATION + md5.new (path).hexdigest () + ".jpeg"
35     return thumbnail
36
37 if __name__ == "__main__":
38     import sys
39     from optparse import OptionParser
40
41     parser = OptionParser()
42     parser.add_option ("-a", "--artist", dest="artist", type="string",
43                        help="ARTIST to look for", metavar="ARTIST")
44     parser.add_option ("-b", "--album", dest="album", type="string",
45                        help="ALBUM to look for", metavar="ALBUM")
46
47     (options, args) = parser.parse_args ()
48     print options
49     if (not options.artist and not options.album):
50         parser.print_help ()
51         sys.exit (-1)
52
53     print "Album art        :", getCoverArtFileName (options.album)
54     print "Thumbnail (album):", getCoverArtThumbFileName (options.album)
55     print "Thumbnail (path) :", get_thumb_filename_for_path (getCoverArtFileName(options.album))