forked from lbovet/phpdigikam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-thumbnails.py
executable file
·44 lines (40 loc) · 1.53 KB
/
create-thumbnails.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
#!/usr/bin/python
## Copyright 2011 Mike Willis (http://blogs.warwick.ac.uk/mikewillis/contact/)
## Laurent Bovet <[email protected]>
##
## This file is part of phpdigikam
##
## It has been gratefully stolen from:
## http://blogs.warwick.ac.uk/mikewillis/entry/generating_freedesktoporg_spec/
##
## phpdigikam 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 2, 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.
import gnome.ui
import gnomevfs
import time
import os
import os.path
import sys
dir = sys.argv[1]
thumbFactory = gnome.ui.ThumbnailFactory(gnome.ui.THUMBNAIL_SIZE_LARGE)
for subdir, dirs, files in os.walk(dir):
for file in files:
path = os.path.join(subdir, file)
uri = gnomevfs.get_uri_from_local_path(path)
mime = gnomevfs.get_mime_type(path)
mtime = int(os.path.getmtime(path))
if not os.path.exists(gnome.ui.thumbnail_path_for_uri(uri, gnome.ui.THUMBNAIL_SIZE_LARGE)) and thumbFactory.can_thumbnail(uri, mime, 0):
print "Generating for %s" % uri
thumbnail = thumbFactory.generate_thumbnail(uri, mime)
if thumbnail is not None:
thumbFactory.save_thumbnail(thumbnail, uri, mtime)
else:
print "Skip %s" % uri