Ivars 6 years ago
parent
commit
4e556a1cd6
5 changed files with 68 additions and 30 deletions
  1. 4
    0
      changelog.md
  2. 45
    22
      get_picons.py
  3. 1
    1
      imake.bat
  4. 11
    2
      plugin.py
  5. 7
    5
      readme.md

+ 4
- 0
changelog.md View File

@@ -1,3 +1,7 @@
1
+**0.4e** (11.04.2017)
2
+- [feature] option to set background/transparency
3
+- [feature] use low-res image if high-res image is not available
4
+
1 5
 **0.4b** (29.03.2017)
2 6
 - [bugfix] url change
3 7
 - using simple picture instead of high-res

+ 45
- 22
get_picons.py View File

@@ -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)

+ 1
- 1
imake.bat View File

@@ -1,6 +1,6 @@
1 1
 @echo off
2 2
 :=== Parameters ===
3
-set ver=0.4c
3
+set ver=0.4e
4 4
 set prog=GetPicons
5 5
 set pack_name=enigma2-plugin-extensions-getpicons
6 6
 set pack_prefix=enigma2-plugin-extensions-

+ 11
- 2
plugin.py View File

@@ -68,6 +68,9 @@ class MainScreen(Screen):
68 68
             param += " -s %s"%(item) if item <> "all" else ""
69 69
             param += " -o" if config.plugins.getpicons.overwrite.value else ""
70 70
             param += " -z %s"%config.plugins.getpicons.size.value if config.plugins.getpicons.size.value else ""
71
+            param += " -b %s"%config.plugins.getpicons.background.value if config.plugins.getpicons.background.value else ""
72
+            param += " -l" if config.plugins.getpicons.simple.value else ""
73
+            param += " -d" if config.plugins.getpicons.debug.value else ""
71 74
             cur_directory = os.path.dirname(os.path.realpath(__file__))
72 75
             name = os.path.join(cur_directory,"get_picons.py")
73 76
             cmd = "python -u %s -f %s %s"%(name,config.plugins.getpicons.folder.value,param,)
@@ -93,8 +96,8 @@ Download channels picon files from lyngsat.com for all/selected satellites
93 96
 Could be run from terminal too:
94 97
 /usr/script/get_picons.sh -h
95 98
 
96
-Version 0.3
97
-(c) 2013-2016 ivars777@gmail.com"""
99
+Version 0.4
100
+(c) 2013-2017 ivars777@gmail.com"""
98 101
         self.session.open(MessageBox, txt, MessageBox.TYPE_INFO)
99 102
         #self.session.openWithCallback(self.callMyMsg, MessageBox, _("Do you want to exit the plugin?"), MessageBox.TYPE_INFO)
100 103
         return
@@ -111,6 +114,9 @@ config.plugins.getpicons = ConfigSubsection()
111 114
 config.plugins.getpicons.folder = ConfigDirectory(default="/media/hdd")
112 115
 config.plugins.getpicons.size = ConfigSelection({"400x240":"400x240","220x132":"220x132","100x60":"100x60"}, default="220x132")
113 116
 config.plugins.getpicons.overwrite = ConfigYesNo(default = True)
117
+config.plugins.getpicons.background = ConfigText(default="FFFFFF20")
118
+config.plugins.getpicons.simple = ConfigYesNo(default = False)
119
+config.plugins.getpicons.debug = ConfigYesNo(default = False)
114 120
 
115 121
 class ConfigScreen(ConfigListScreen,Screen):
116 122
     skin = """
@@ -137,6 +143,9 @@ class ConfigScreen(ConfigListScreen,Screen):
137 143
             getConfigListEntry(_("Picons folder"), cfg.folder),
138 144
             getConfigListEntry(_("Picon size"), cfg.size),
139 145
             getConfigListEntry(_("Overwrite existing picon files"), cfg.overwrite),
146
+            getConfigListEntry(_("Background color hex code (HHHHHHHH)"), cfg.background),
147
+            getConfigListEntry(_("Simple picon"), cfg.simple),
148
+            getConfigListEntry(_("Debug info"), cfg.debug),
140 149
         ]
141 150
         ConfigListScreen.__init__(self, self.list, session = self.session)
142 151
         self["key_red"] = Button(_("Cancel"))

+ 7
- 5
readme.md View File

@@ -2,19 +2,21 @@
2 2
 
3 3
 #### Enigma2 plugin to dowload and create channels picons files form lyngsat.com
4 4
 
5
-Dowloads and creates Enigma2 channels picons files form lyngsat.com (straight forward downloading and resizing without transparency and other fine tunings).
6
-Picons for all channels in lamed are downloaded (you can subselect particular sattelites or packages via paremeters).
5
+Creates Enigma2 channels picons form lyngsat.com.
6
+Downloads and resizes lyngsat-logo.com high resolution images. Simple low-res images with white background could be used too.
7
+It is possible to set bacground color/transparency. Background transparency works only if pillows python library is installed!
8
+Picons for all channels in Enigma2 lamedb are downloaded (you can subselect particular sattelites or packages via paremeters).
7 9
 No symlinks are created for same images.
8 10
 
9 11
 You can run it several ways:
10 12
 
11 13
 1. As a Dreambox plugin (GetPicons)
12 14
 2. From Dreambox command line (/usr/script/get_picons.sh)
13
-3. From PC command line
15
+3. From PC command line (use it if you want transparent background, since pillow library usually not available on enigma2)
14 16
 
15 17
 **Prerequisites**:
16 18
 - Python 2.x
17
-- Python libraries-  Imaging (PIL) (usually part of standart python)
19
+- Python libraries-  Imaging (PIL) (usually part of standart python) or pillow
18 20
 
19 21
 **Usage (command line):**
20 22
 ```
@@ -29,7 +31,7 @@ Options:
29 31
     -f PATH, --folder PATH                      picon files output folder, default - "/media/hdd/picon"
30 32
     -e PATH, --enigma PATH                      enigma2 folder whera lamedb,settings are located, default - "/etc/enigma2"
31 33
                                                 you can use urls, e.g. "ftp://root@receiver_address/etc/enigma2"
32
-    -o, -overwrite                              overwrite existing picons file (default - no)
34
+    -o, --overwrite                              overwrite existing picons file (default - no)
33 35
     -d, -debug                                  display work progress and write debug info to file for not found services
34 36
     -h, --help                                  this help file
35 37