|
@@ -16,28 +16,32 @@ Options:
|
16
|
16
|
-f PATH, --folder PATH picon files output folder, default - "/media/hdd/picon"
|
17
|
17
|
-e PATH, --enigma PATH enigma2 folder whera lamedb,settings are located, default - "/etc/enigma2"
|
18
|
18
|
you can use urls, e.g. "ftp://root@receiver_address/etc/enigma2"
|
19
|
|
- -o, -overwrite overwrite existing picons file (default - no)
|
20
|
|
- -d, -debug display work progress and write debug info to file for not found services
|
|
19
|
+ -b COLOR_CODE, --background=COLOR_CODE background color code in hex format(HHHHHHHHH), last pair - opacity level
|
|
20
|
+ default - FFFFFF20 (almost transparent white)
|
|
21
|
+ -l, --simple simple, low resolution image with white background
|
|
22
|
+ -o, --overwrite overwrite existing picons file (default - no)
|
|
23
|
+ -d, --debug display work progress and write debug info to file for not found services
|
21
|
24
|
-h, --help this help file
|
22
|
25
|
|
23
|
26
|
(c)Ivars777 (ivars777@gmail.com) 2013-2015, v0.2
|
24
|
27
|
"""
|
25
|
28
|
|
26
|
|
-import sys, os, os.path, getopt
|
|
29
|
+import sys, os, os.path, getopt, traceback
|
27
|
30
|
import re
|
28
|
31
|
import urllib2
|
29
|
32
|
import requests
|
30
|
33
|
|
31
|
34
|
try:
|
32
|
|
- import Image
|
33
|
|
-except:
|
34
|
35
|
from PIL import Image
|
|
36
|
+except:
|
|
37
|
+ import Image
|
35
|
38
|
from StringIO import StringIO
|
36
|
39
|
import logging
|
37
|
40
|
|
38
|
41
|
options = args = None
|
39
|
42
|
_sd= lambda x,d: d if x is None else x # set default value
|
40
|
43
|
_sl= lambda x: False if x is None else True # set True of False for option
|
|
44
|
+hex2rgb = lambda c: tuple(int(c[i:i+2], 16) for i in xrange(0,len(c),2))
|
41
|
45
|
|
42
|
46
|
def parse_arguments(argv,opt_short,opt_long):
|
43
|
47
|
"Parse command line arguments"
|
|
@@ -59,19 +63,21 @@ def main(argv):
|
59
|
63
|
global options, args, services
|
60
|
64
|
|
61
|
65
|
# Parsing options
|
62
|
|
- opt_short = 'p:s:z:f:e:ordh'
|
63
|
|
- opt_long = ["package=","sat","folder=","enigma=","overwrite","hires","debug","help"]
|
|
66
|
+ opt_short = 'p:s:z:f:e:b:lodh'
|
|
67
|
+ opt_long = ["package=","sat=","size=","folder=","enigma=","background=","simple","overwrite","debug","help"]
|
64
|
68
|
options,args = parse_arguments(argv[1:], opt_short, opt_long)
|
65
|
69
|
options.package = _sd(options.package,_sd(options.p,""))
|
66
|
70
|
options.sat = _sd(options.sat,_sd(options.s,""))
|
67
|
71
|
options.enigma = _sd(options.enigma,_sd(options.e,"/etc/enigma2"))
|
68
|
72
|
options.folder = _sd(options.folder,_sd(options.f,"/media/hdd/picon"))
|
69
|
73
|
options.size = _sd(options.size,_sd(options.z,"220x132"))
|
|
74
|
+ options.simple = _sl(_sd(options.simple, options.l))
|
|
75
|
+ options.background = _sd(options.background, _sd(options.b, "FFFFFFFF"))
|
70
|
76
|
options.overwrite = _sl(_sd(options.overwrite,options.o))
|
71
|
77
|
options.debug = _sl(_sd(options.debug,options.d))
|
72
|
|
- options.hires = _sl(_sd(options.hires,options.r))
|
73
|
78
|
|
74
|
79
|
options.w,options.h = map(int,options.size.split("x"))
|
|
80
|
+ options.background = hex2rgb(options.background.lstrip("#"))
|
75
|
81
|
if not os.path.exists(options.folder):
|
76
|
82
|
os.makedirs(options.folder)
|
77
|
83
|
|
|
@@ -149,13 +155,10 @@ def create_picons(package):
|
149
|
155
|
b=0
|
150
|
156
|
icon_url = html_attr("src",td[b])
|
151
|
157
|
if icon_url:
|
152
|
|
- #icon_url = "http://www.lyngsat.com" + icon_url.group(1).replace("/icon","/logo").replace(".gif",".jpg")
|
153
|
158
|
# https://www.lyngsat.com/logo/tv/vv/viasat_history.png
|
154
|
159
|
# https://www.lyngsat-logo.com/hires/vv/viasat_history.png
|
155
|
|
- if options.hires:
|
156
|
|
- icon_url = "https://www.lyngsat-logo.com" + icon_url.group(1).replace("/logo/tv", "/hires")
|
157
|
|
- else:
|
158
|
|
- icon_url = "https://www.lyngsat.com" + icon_url.group(1) # simple picture
|
|
160
|
+ icon_url_hr = "https://www.lyngsat-logo.com" + icon_url.group(1).replace("/logo/tv", "/hires")
|
|
161
|
+ icon_url_lr = "https://www.lyngsat.com" + icon_url.group(1)
|
159
|
162
|
else:
|
160
|
163
|
icon_url = ""
|
161
|
164
|
name = html_text(td[b+1]).group(1)
|
|
@@ -197,25 +200,45 @@ def create_picons(package):
|
197
|
200
|
num_skipped += 1
|
198
|
201
|
continue
|
199
|
202
|
|
200
|
|
- #try:
|
201
|
|
- #im = Image.open(StringIO(urllib2.urlopen(icon_url).read()))
|
202
|
|
- data = get_page(icon_url)
|
|
203
|
+ if options.simple:
|
|
204
|
+ data = get_page(icon_url_lr)
|
|
205
|
+ hires = False
|
|
206
|
+ else:
|
|
207
|
+ data = get_page(icon_url_hr)
|
|
208
|
+ hires = True
|
|
209
|
+ if not data: # in not hires image available use lowres image
|
|
210
|
+ data = get_page(icon_url_lr)
|
|
211
|
+ hires = False
|
|
212
|
+
|
203
|
213
|
if not data:
|
204
|
214
|
if options.debug: print " -- NOK (no picon image)"
|
205
|
215
|
continue
|
206
|
216
|
try:
|
207
|
217
|
im = Image.open(StringIO(data))
|
208
|
218
|
im.thumbnail((options.w,options.h), Image.ANTIALIAS)
|
209
|
|
- im = im.convert('P', palette=Image.ADAPTIVE)
|
210
|
|
- except Exception:
|
211
|
|
- im = None
|
212
|
|
- if not im:
|
|
219
|
+ if hires:
|
|
220
|
+ im2 = Image.new("RGBA",(options.w,options.h),options.background)
|
|
221
|
+ #im2 = Image.new("RGBA",(options.w,options.h),(255,255,255,128))
|
|
222
|
+ width, height = im.size
|
|
223
|
+ x0 = (options.w-width)/2
|
|
224
|
+ y0 = (options.h-height)/2
|
|
225
|
+ if im.mode <> "RGBA":
|
|
226
|
+ im = im.convert("RGBA")
|
|
227
|
+ im2.paste(im,(x0,y0),im)
|
|
228
|
+ else:
|
|
229
|
+ im2 = im
|
|
230
|
+ #im2 = im2.convert('P', palette=Image.ADAPTIVE)
|
|
231
|
+ except Exception as e:
|
|
232
|
+ print e.message
|
|
233
|
+ traceback.print_exc()
|
|
234
|
+ im2 = None
|
|
235
|
+ if not im2:
|
213
|
236
|
if options.debug: print " -- NOK (no picon image)"
|
214
|
237
|
continue
|
215
|
238
|
|
216
|
239
|
if options.debug: print " -- downloaded"
|
217
|
|
- im.save(fname,"png")
|
218
|
|
- del im
|
|
240
|
+ im2.save(fname,"png")
|
|
241
|
+ del im2,im
|
219
|
242
|
num_picons += 1
|
220
|
243
|
|
221
|
244
|
print "%i picons created, %i skipped"%(num_picons,num_skipped)
|