-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
cover-thumbnailer.py
executable file
·718 lines (642 loc) · 27.2 KB
/
cover-thumbnailer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#########################################################################
## ##
## ┏━╸┏━┓╻ ╻┏━╸┏━┓ ╺┳╸╻ ╻╻ ╻┏┳┓┏┓ ┏┓╻┏━┓╻╻ ┏━╸┏━┓ ##
## ┃ ┃ ┃┃┏┛┣╸ ┣┳┛ ┃ ┣━┫┃ ┃┃┃┃┣┻┓┃┗┫┣━┫┃┃ ┣╸ ┣┳┛ ##
## ┗━╸┗━┛┗┛ ┗━╸╹┗╸ ╹ ╹ ╹┗━┛╹ ╹┗━┛╹ ╹╹ ╹╹┗━╸┗━╸╹┗╸ ##
## — www.flogisoft.com — ##
## ##
############################################################################
## ##
## Cover thumbnailer ##
## ##
## Copyright (C) 2009 - 2024 Fabien Loison <http://www.flozz.fr/> ##
## ##
## This program is free software: you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
## ##
############################################################################
## ##
## WEB SITE : https://github.com/flozz/cover-thumbnailer ##
## ##
#########################################################################
"""Generates thumbnails for nautilus' folders.
Cover thumbnailer generates thumbnail that will be displayed instead of the
default folder icons. It has a specific presentation for music and pictures
folders, and a generic one for other folders.
Usage:
cover-thumbnailer <directory's path> <output thumbnail's path>
"""
__version__ = "0.10.2"
__author__ = "Fabien Loison <http://www.flozz.fr/>"
__copyright__ = "Copyright © 2009 - 2024 Fabien LOISON"
import re
import sys
import os.path
from gi.repository import Gio
try:
from PIL import Image
except:
import Image
#==================================================================== CONF ====
#Base path for cover thumbnailer's pictures
if "DEVEL" in os.environ:
BASE_PATH = "./share/" #For devel
else:
BASE_PATH = "/usr/share/cover-thumbnailer/"
#Cover files list
COVER_FILES = ["cover.png", "cover.jpg", ".cover.png", ".cover.jpg",
"Cover.png", "Cover.jpg", ".Cover.png", ".Cover.jpg",
"folder.png", "folder.jpg", ".folder.png", ".folder.jpg",
"Folder.png", "Folder.jpg", ".Folder.png", ".Folder.jpg"]
#Supported picture ext (ALWAY LAST 4 CHARS !!)
PICTURES_EXT = [".jpg", ".JPG", "jpeg", "JPEG",
".png", ".PNG", #Not interlaced
".gif", ".GIF",
".bmp", ".BMP", #Window ans OS/2 bitmap
".ico", ".ICO", #Windows icon format
".tga", ".TGA", #Truevision Targa format
".tif", ".TIF", "tiff", "TIFF", #Adobe Tagged Image File Format
".psd", ".PSD", #Adobe Photosop format (only version 2.5 and 3.0)
]
#==============================================================================
class Conf(dict):
""" Import configuration.
Import configuration from the GNOME and cover thumbnailer files
"""
def __init__(self):
""" The constructor
Set the default values
"""
#Initialize the dictionary
dict.__init__(self)
#Music
self['music_enabled'] = True
self['music_keepdefaulticon'] = False
self['music_usegnomefolder'] = True
self['music_cropimg'] = True
self['music_makemosaic'] = False
self['music_paths'] = []
self['music_defaultimg'] = os.path.join(BASE_PATH, "music_default.png")
self['music_fg'] = os.path.join(BASE_PATH, "music_fg.png")
self['music_bg'] = os.path.join(BASE_PATH, "music_bg.png")
#Pictures
self['pictures_enabled'] = True
self['pictures_keepdefaulticon'] = False
self['pictures_usegnomefolder'] = True
self['pictures_maxthumbs'] = 3
self['pictures_paths'] = []
self['pictures_fg'] = os.path.join(BASE_PATH, "pictures_fg.png")
self['pictures_bg'] = os.path.join(BASE_PATH, "pictures_bg.png")
#Other
self['other_enabled'] = True
self['other_fg'] = os.path.join(BASE_PATH, 'other_fg.png')
#Ignored
self['ignored_dotted'] = False
self['ignored_paths'] = []
#Never ignored
self['neverignored_paths'] = []
#Global
self.user_homedir = os.environ.get("HOME")
self.user_gnomeconf = os.path.join(
self.user_homedir,
".config/user-dirs.dirs"
)
self.user_conf = os.path.join(
self.user_homedir,
".cover-thumbnailer/cover-thumbnailer.conf"
)
#Read configuration
self.import_user_conf()
self.import_gnome_conf()
def import_gnome_conf(self):
""" Import user folders from GNOME configuration file. """
if os.path.isfile(self.user_gnomeconf):
gnome_conf_file = open(self.user_gnomeconf, 'r')
for line in gnome_conf_file:
if re.match(r'.*?XDG_MUSIC_DIR.*?=.*?"(.*)".*?', line) and self['music_usegnomefolder']:
match = re.match(r'.*?XDG_MUSIC_DIR.*?=.*?"(.*)".*?', line)
path = match.group(1).replace('$HOME', self.user_homedir)
#If path == user home dir, don't use it, it's probably a misconfiguration !
if os.path.isdir(path) and not os.path.samefile(path, self.user_homedir):
self['music_paths'].append(path)
elif re.match(r'.*?XDG_PICTURES_DIR.*?=.*?"(.*)".*?', line) and self['pictures_usegnomefolder']:
match = re.match(r'.*?XDG_PICTURES_DIR.*?=.*?"(.*)".*?', line)
path = match.group(1).replace('$HOME', self.user_homedir)
#If path == user home dir, don't use it, it's probably a misconfiguration !
if os.path.isdir(path) and not os.path.samefile(path, self.user_homedir):
self['pictures_paths'].append(path)
gnome_conf_file.close()
else:
print("W: [%s:Conf.import_gnome_conf] Can't find `user-dirs.dirs' file." % __file__)
def import_user_conf(self):
""" Import user configuration file. """
if os.path.isfile(self.user_conf):
current_section = "unknown"
user_conf_file = open(self.user_conf, "r")
for line in user_conf_file:
#Comments
if re.match(r"\s*#.*", line):
continue
#Section
elif re.match(r"\s*\[([a-z]+)\]\s*", line.lower()):
match = re.match(r'\s*\[([a-z]+)\]\s*', line.lower())
current_section = match.group(1)
#Boolean key
elif re.match(r"\s*([a-z]+)\s*=\s*(yes|no|true|false)\s*", line.lower()):
match = re.match(r"\s*([a-z]+)\s*=\s*(yes|no|true|false)\s*", line.lower())
key = match.group(1)
value = match.group(2)
if value in ("yes", "true"):
value = True
else:
value = False
self[current_section + "_" + key] = value
#String key : path
elif re.match(r"\s*(path|PATH|Path)\s*=\s*\"(.+)\"\s*", line):
match = re.match(r"\s*(path|PATH|Path)\s*=\s*\"(.+)\"\s*", line)
key = "paths"
value = match.group(2)
self[current_section + "_" + key].append(value)
#Integer key
elif re.match(r"\s*([a-z]+)\s*=\s*([0-9]+)\s*", line.lower()):
match = re.match(r"\s*([a-z]+)\s*=\s*([0-9]+)\s*", line.lower())
key = match.group(1)
value = match.group(2)
self[current_section + "_" + key] = int(value)
user_conf_file.close()
#Replace "~/" by the user home dir
for path_list in (self['music_paths'], self['pictures_paths'], self['ignored_paths']):
for i in range(0, len(path_list)):
if path_list[i][0] == "~":
path_list[i] = os.path.join(self.user_homedir, path_list[i][2:])
#Import "useGnomeConf" key (for compatibility)
if "miscellaneous_usegnomeconf" in self:
self["music_usegnomefolder"] = self["miscellaneous_usegnomeconf"]
self["pictures_usegnomefolder"] = self["miscellaneous_usegnomeconf"]
class Thumb(object):
""" Makes thumbnails.
Generate thumbnails for all kind of folders
"""
def __init__(self, img_paths):
"""The constructor.
Argument:
* img_paths -- a list of picture path
"""
self.img = []
for path in img_paths:
try:
img = Image.open(path).convert("RGBA")
except IOError:
print("E: [%s:Thumb.__init__] Can't open '%s'." % (__file__, path))
else:
self.img.append(img)
self.thumb = None
def thumbnailize(self, image, twidth=128, theight=128, crop=True):
""" Make thumbnail.
Crop the picture if necessaries and return a thumbnail of it.
Keyword argument:
* twidth -- the width of the thumbnail (in pixels).
* theight -- the width of the thumbnail (in pixels).
NOTE: useless if crop = True
* crop -- the resize method (True for having a squared thumbnail)
NOTE: the size shouldn't be greater than 128 px for a standard
freedesktop thumbnail.
"""
width = image.size[0]
height = image.size[1]
if crop and width >= twidth and height >= theight:
if width > height:
left = int((width - height) / 2)
upper = 0
right = height + left
lower = height
else:
left = 0
upper = int((height - width) / 2)
right = width
lower = width + upper
image = image.crop((left, upper, right, lower))
image.thumbnail((twidth, theight), Image.LANCZOS)
return image
def music_thumbnail(self, bg_picture, fg_picture, crop=True):
""" Makes thumbnails for music folders.
Argument:
* bg_picture -- the background picture
* fg_picture -- the foreground picture
* crop -- the resize method (True for having a squared thumbnail)
"""
#Background picture
bg = Image.open(bg_picture).convert("RGB")
bg_width = bg.size[0]
bg_height = bg.size[1]
#Album cover
cover = self.thumbnailize(self.img[0], bg_height, crop=crop)
cover_width = cover.size[0]
cover_height = cover.size[1]
#Cover position on background
delta = bg_width - bg_height #The left border of album
x = int((bg_width - cover_width + delta) / 2)
y = int((bg_height - cover_height) / 2)
#Past cover on background
bg.paste(cover, (x, y), cover)
#Forground picture
fg = Image.open(fg_picture).convert("RGBA")
#Past forground on background+cover
bg.paste(fg, (0, 0), fg)
self.thumb = bg
def music_thumbnail_mosaic(self, bg_picture, fg_picture, crop=True):
""" Makes thumbnails composed by more than one cover for music folders.
Argument:
* bg_picture -- the background picture
* fg_picture -- the foreground picture
* crop -- the resize method (True for having a squared thumbnail)
NOTE: call this function ONLY if self.img has, at least, two pictures.
"""
#Background picture
bg = Image.open(bg_picture).convert("RGB")
bg_width = bg.size[0]
bg_height = bg.size[1]
#Album covers
covers_thumb = []
for img in self.img:
cover_thumb = self.thumbnailize(img, int(bg_height / 2), crop=crop)
cover_thumb_width = cover_thumb.size[0]
cover_thumb_height = cover_thumb.size[1]
covers_thumb.append({
'cover': cover_thumb,
'width': cover_thumb_width,
'height': cover_thumb_height
})
#For having 4 covers for the mosaic
if len(covers_thumb) == 2:
covers_thumb.append(covers_thumb[1].copy())
covers_thumb.append(covers_thumb[0].copy())
elif len(covers_thumb) == 3:
covers_thumb.append(covers_thumb[0].copy())
#Covers position on background
delta = bg_width - bg_height #The left border of album
covers_thumb[0]['x'] = int(1*(bg_width - delta)/4 - covers_thumb[0]['width']/2 + delta)
covers_thumb[0]['y'] = int(1*bg_height/4 - covers_thumb[0]['height']/2)
covers_thumb[1]['x'] = int(3*(bg_width - delta)/4 - covers_thumb[1]['width']/2 + delta)
covers_thumb[1]['y'] = int(1*bg_height/4 - covers_thumb[1]['height']/2)
covers_thumb[2]['x'] = int(1*(bg_width - delta)/4 - covers_thumb[2]['width']/2 + delta)
covers_thumb[2]['y'] = int(3*bg_height/4 - covers_thumb[2]['height']/2)
covers_thumb[3]['x'] = int(3*(bg_width - delta)/4 - covers_thumb[3]['width']/2 + delta)
covers_thumb[3]['y'] = int(3*bg_height/4 - covers_thumb[3]['height']/2)
#Paste covers on background
for i in range(0, 4):
bg.paste(covers_thumb[i]['cover'],
(covers_thumb[i]['x'], covers_thumb[i]['y']),
covers_thumb[i]['cover']
)
#Forground picture
fg = Image.open(fg_picture).convert("RGBA")
#Paste forground on background+cover
bg.paste(fg, (0, 0), fg)
self.thumb = bg
def pictures_thumbnail(self, bg_picture, fg_picture, max_pictures=3):
""" Makes thumbnails for picture folders.
Arguments:
* bg_picture -- the background picture
* fg_picture -- the foreground picture
Keyword argument:
* max_pictures -- the maximum number of pictures on the thumbnail
"""
#Background
bg = Image.open(bg_picture).convert("RGBA")
bg_width = bg.size[0]
bg_height = bg.size[1]
picts = []
number_of_pictures = 0
#One picture
if len(self.img) == 1 or max_pictures == 1 and len(self.img) > 0:
number_of_pictures = 1
thumb = self.thumbnailize(
self.img[0],
bg_width - 20,
bg_height - 20,
crop=False
)
x = int((bg_width - thumb.size[0]) / 2)
y = int((bg_height - thumb.size[1]) / 2)
picts.append({
'thumb': thumb,
'x': x,
'y': y
})
#Two pictures
elif len(self.img) == 2 or max_pictures == 2 and len(self.img) > 0:
number_of_pictures = 2
#Thumb 0
thumb = self.thumbnailize(
self.img[0],
bg_width - 20,
int(0.53*bg_height),
crop=False
)
picts.append({
'thumb': thumb,
'x': 10,
'y': 5
})
#Thumb 1
thumb = self.thumbnailize(
self.img[1],
bg_width - 20,
int(0.53*bg_height),
crop=False
)
x = bg_width - thumb.size[0] - 10
y = bg_height - thumb.size[1] - 5
picts.append({
'thumb': thumb,
'x': x,
'y': y
})
#Three pictures
elif len(self.img) == 3 or max_pictures == 3 and len(self.img) > 0:
number_of_pictures = 3
#Thumb 0
thumb = self.thumbnailize(self.img[0], 49, 56, crop=False)
picts.append({
'thumb': thumb,
'x': 20,
'y': 5
})
#Thumb 1
thumb = self.thumbnailize(self.img[1], 49, 56, crop=False)
x = int(bg_width - thumb.size[0] - 5)
picts.append({
'thumb': thumb,
'x': x,
'y': 5
})
#Thumb 2
h = int(bg_height - max(picts[0]['thumb'].size[1], picts[1]['thumb'].size[1]) - 15)
thumb = self.thumbnailize(self.img[2], 103, h, crop=False)
x = int((bg_width - 15 - thumb.size[0])/2 + 15)
y = int(bg_height - thumb.size[1] - 5)
picts.append({
'thumb': thumb,
'x': x,
'y': y
})
#Four pictures
elif len(self.img) == 4 or max_pictures == 4 and len(self.img) > 0:
number_of_pictures = 4
#Thumb 0
thumb = self.thumbnailize(
self.img[0],
int(bg_width/2 - 7.5),
int(bg_height/2 - 7.5),
crop=False
)
x = int(1*bg_width/4 - thumb.size[0]/2)
y = int(1*bg_height/4 - thumb.size[1]/2)
picts.append({
'thumb': thumb,
'x': x,
'y': y
})
#Thumb 1
thumb = self.thumbnailize(
self.img[1],
int(bg_width/2 - 7.5),
int(bg_height/2 - 7.5),
crop=False
)
x = int(3*bg_width/4 - thumb.size[0]/2)
y = int(1*bg_height/4 - thumb.size[1]/2)
picts.append({
'thumb': thumb,
'x': x,
'y': y
})
#Thumb 2
thumb = self.thumbnailize(
self.img[2],
int(bg_width/2 - 7.5),
int(bg_height/2 - 7.5),
crop=False
)
x = int(1*bg_width/4 - thumb.size[0]/2)
y = int(3*bg_height/4 - thumb.size[1]/2)
picts.append({
'thumb': thumb,
'x': x,
'y': y
})
#Thumb 3
thumb = self.thumbnailize(
self.img[3],
int(bg_width/2 - 7.5),
int(bg_height/2 - 7.5),
crop=False
)
x = int(3*bg_width/4 - thumb.size[0]/2)
y = int(3*bg_height/4 - thumb.size[1]/2)
picts.append({
'thumb': thumb,
'x': x,
'y': y
})
#Paste pictures on background
for i in range(0, number_of_pictures):
bg.paste(
picts[i]['thumb'],
(picts[i]['x'], picts[i]['y']),
picts[i]['thumb']
)
#Paste forground on background+pictures
fg = Image.open(fg_picture).convert("RGBA")
bg.paste(fg, (0, 0), fg)
self.thumb = bg
def other_thumbnail(self, fg_picture):
""" Makes thumbnails for "other" folders
Argument:
* fg_picture -- the foreground picture to add
"""
fg = Image.open(fg_picture).convert("RGBA")
size = fg.size[0]
if len(self.img) == 1:
image = self.thumbnailize(self.img[0], size, crop=True)
if image.size[0] == size and image.size[1] == size:
image.paste(fg, (0, 0), fg)
self.thumb = image
def save_thumb(self, output_path, output_format='PNG'):
""" Save the thumbnail in a file.
Argument:
* output_path -- the output path for the thumbnail
Keyword argument:
* format -- the format of the picture (PNG, JPEG,...)
NOTE : The output format must be a PNG for a standard
freedesktop thumbnail
"""
if self.thumb is not None:
self.thumb.save(output_path, output_format)
else:
print("E: [%s:Thumb.save_thumb] No thumbnail created" % __file__)
def search_cover(path):
""" Search for a cover file.
Search for files like cover.png, .folder.jpg,... in the folder and return
its name as a list of on item (or an empty list if no pictures were found)
Argument:
* path -- the path of the folder
"""
cover_path = []
for cover in COVER_FILES:
if os.path.isfile(os.path.join(path, cover)):
cover_path.append(os.path.join(path, cover))
break
return cover_path
def search_pictures(path):
""" Search for pictures in the folder
Search for pictures in the folder and return their name as a list (or an
empty list if no pictures were found).
Argument:
* path -- the path of the folder
"""
files = os.listdir(path)
pictures = []
for file_ in files:
if file_[-4:] in PICTURES_EXT:
pictures.append(os.path.join(path, file_))
if len(pictures) >= 4: #4 pictures max... don't need more
break
return pictures
def search_pictures_recursiv(path):
""" Search recursively for pictures in the folder
Search for pictures in the subfolders and return their name as a list
(or an empty list if no pictures were found).
Argument:
* path -- the path of the folder
"""
pictures = []
for root, dirs, files in os.walk(path):
if len(pictures) <= 4: #4 pictures max... don't need more
for file_ in files:
if file_[-4:] in PICTURES_EXT:
pictures.append(os.path.join(path, root, file_))
break
else:
break
return pictures
def match_path(path, path_list):
""" Test if a folder is a sub-folder of another one in the list.
Arguments
* path -- path to check
* path_list -- list of path
"""
match = False
#We add a slash at the end.
if path[-1:] != "/":
path += "/"
for entry in path_list:
#We add a slash at the end.
if entry[-1:] != "/":
entry += "/"
if re.match(r"^" + entry + ".*", path):
if path != entry:
match = True
break
return match
def gvfs_uri_to_path(uri):
"""Returns local file path from gvfs URI
Arguments:
uri -- the gvfs URI
"""
if not re.match(r"^[a-zA-Z0-9_-]+://", uri):
return uri
gvfs = Gio.Vfs.get_default()
return gvfs.get_file_for_uri(uri).get_path()
if __name__ == "__main__":
#If we have 2 args
if len(sys.argv) == 3:
INPUT_FOLDER = gvfs_uri_to_path(sys.argv[1])
OUTPUT_FILE = gvfs_uri_to_path(sys.argv[2])
else:
#Display informations and usage
print("Cover thumbnailer - %s" % __doc__)
print("Version: %s" % __version__)
print(__copyright__)
sys.exit(1)
#If input path does not exists
if not os.path.isdir(INPUT_FOLDER):
print("E: [%s:__main__] '%s' is not a directory" % (__file__, INPUT_FOLDER))
sys.exit(2)
#Load configuration
CONF = Conf()
#Ignored folders
if match_path(INPUT_FOLDER, CONF['ignored_paths']) \
and not match_path(INPUT_FOLDER, CONF['neverignored_paths']):
sys.exit(0)
#Folders whose name starts with a dot
elif CONF['ignored_dotted'] and re.match(r".*/\..*", INPUT_FOLDER):
sys.exit(0)
#Music folders
elif CONF['music_enabled'] and match_path(INPUT_FOLDER, CONF['music_paths']):
covers = search_cover(INPUT_FOLDER)
if len(covers) == 0:
covers = search_pictures(INPUT_FOLDER)
if len(covers) == 0:
covers = search_pictures_recursiv(INPUT_FOLDER)
if len(covers) == 0 and not CONF['music_keepdefaulticon']:
covers = [CONF['music_defaultimg']]
if len(covers) > 0:
if len(covers) == 1 or not CONF['music_makemosaic']:
thumbnail = Thumb([covers[0], CONF['music_defaultimg']])
thumbnail.music_thumbnail(
CONF['music_bg'],
CONF['music_fg'],
CONF['music_cropimg']
)
thumbnail.save_thumb(OUTPUT_FILE, "PNG")
else:
thumbnail = Thumb(covers)
thumbnail.music_thumbnail_mosaic(
CONF['music_bg'],
CONF['music_fg'],
CONF['music_cropimg']
)
thumbnail.save_thumb(OUTPUT_FILE, "PNG")
elif not CONF['music_keepdefaulticon']:
thumbnail = Thumb([CONF['music_defaultimg']])
thumbnail.music_thumbnail(
CONF['music_bg'],
CONF['music_fg'],
CONF['music_cropimg']
)
thumbnail.save_thumb(OUTPUT_FILE, "PNG")
#Picture folders
elif CONF['pictures_enabled'] and match_path(INPUT_FOLDER, CONF['pictures_paths']):
picture_list = search_cover(INPUT_FOLDER)
if len(picture_list) == 0:
picture_list = search_pictures(INPUT_FOLDER)
if len(picture_list) == 0:
picture_list = search_pictures_recursiv(INPUT_FOLDER)
thumbnail = Thumb(picture_list)
thumbnail.pictures_thumbnail(
CONF['pictures_bg'],
CONF['pictures_fg'],
CONF['pictures_maxthumbs']
)
thumbnail.save_thumb(OUTPUT_FILE, "PNG")
#Other folders
elif CONF['other_enabled']:
covers = search_cover(INPUT_FOLDER)
if len(covers) == 1:
thumbnail = Thumb(covers)
thumbnail.other_thumbnail(CONF['other_fg'])
thumbnail.save_thumb(OUTPUT_FILE, "PNG")