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
+**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
 **0.4b** (29.03.2017)
5
 **0.4b** (29.03.2017)
2
 - [bugfix] url change
6
 - [bugfix] url change
3
 - using simple picture instead of high-res
7
 - using simple picture instead of high-res

+ 45
- 22
get_picons.py View File

16
     -f PATH, --folder PATH                      picon files output folder, default - "/media/hdd/picon"
16
     -f PATH, --folder PATH                      picon files output folder, default - "/media/hdd/picon"
17
     -e PATH, --enigma PATH                      enigma2 folder whera lamedb,settings are located, default - "/etc/enigma2"
17
     -e PATH, --enigma PATH                      enigma2 folder whera lamedb,settings are located, default - "/etc/enigma2"
18
                                                 you can use urls, e.g. "ftp://root@receiver_address/etc/enigma2"
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
     -h, --help                                  this help file
24
     -h, --help                                  this help file
22
 
25
 
23
 (c)Ivars777 (ivars777@gmail.com) 2013-2015, v0.2
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
 import re
30
 import re
28
 import urllib2
31
 import urllib2
29
 import requests
32
 import requests
30
 
33
 
31
 try:
34
 try:
32
-    import Image
33
-except:
34
     from PIL import Image
35
     from PIL import Image
36
+except:
37
+    import Image
35
 from StringIO import StringIO
38
 from StringIO import StringIO
36
 import logging
39
 import logging
37
 
40
 
38
 options = args = None
41
 options = args = None
39
 _sd= lambda x,d: d if x is None else x # set default value
42
 _sd= lambda x,d: d if x is None else x # set default value
40
 _sl= lambda x: False if x is None else True # set True of False for option
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
 def parse_arguments(argv,opt_short,opt_long):
46
 def parse_arguments(argv,opt_short,opt_long):
43
     "Parse command line arguments"
47
     "Parse command line arguments"
59
     global options, args, services
63
     global options, args, services
60
 
64
 
61
     # Parsing options
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
     options,args = parse_arguments(argv[1:], opt_short, opt_long)
68
     options,args = parse_arguments(argv[1:], opt_short, opt_long)
65
     options.package = _sd(options.package,_sd(options.p,""))
69
     options.package = _sd(options.package,_sd(options.p,""))
66
     options.sat = _sd(options.sat,_sd(options.s,""))
70
     options.sat = _sd(options.sat,_sd(options.s,""))
67
     options.enigma = _sd(options.enigma,_sd(options.e,"/etc/enigma2"))
71
     options.enigma = _sd(options.enigma,_sd(options.e,"/etc/enigma2"))
68
     options.folder = _sd(options.folder,_sd(options.f,"/media/hdd/picon"))
72
     options.folder = _sd(options.folder,_sd(options.f,"/media/hdd/picon"))
69
     options.size = _sd(options.size,_sd(options.z,"220x132"))
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
     options.overwrite = _sl(_sd(options.overwrite,options.o))
76
     options.overwrite = _sl(_sd(options.overwrite,options.o))
71
     options.debug = _sl(_sd(options.debug,options.d))
77
     options.debug = _sl(_sd(options.debug,options.d))
72
-    options.hires = _sl(_sd(options.hires,options.r))
73
 
78
 
74
     options.w,options.h = map(int,options.size.split("x"))
79
     options.w,options.h = map(int,options.size.split("x"))
80
+    options.background = hex2rgb(options.background.lstrip("#"))
75
     if not os.path.exists(options.folder):
81
     if not os.path.exists(options.folder):
76
         os.makedirs(options.folder)
82
         os.makedirs(options.folder)
77
 
83
 
149
                 b=0
155
                 b=0
150
             icon_url = html_attr("src",td[b])
156
             icon_url = html_attr("src",td[b])
151
             if icon_url:
157
             if icon_url:
152
-                #icon_url = "http://www.lyngsat.com" + icon_url.group(1).replace("/icon","/logo").replace(".gif",".jpg")
153
                 # https://www.lyngsat.com/logo/tv/vv/viasat_history.png
158
                 # https://www.lyngsat.com/logo/tv/vv/viasat_history.png
154
                 # https://www.lyngsat-logo.com/hires/vv/viasat_history.png
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
             else:
162
             else:
160
                 icon_url = ""
163
                 icon_url = ""
161
             name = html_text(td[b+1]).group(1)
164
             name = html_text(td[b+1]).group(1)
197
                 num_skipped += 1
200
                 num_skipped += 1
198
                 continue
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
             if not data:
213
             if not data:
204
                 if options.debug: print " -- NOK (no picon image)"
214
                 if options.debug: print " -- NOK (no picon image)"
205
                 continue
215
                 continue
206
             try:
216
             try:
207
                 im = Image.open(StringIO(data))
217
                 im = Image.open(StringIO(data))
208
                 im.thumbnail((options.w,options.h), Image.ANTIALIAS)
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
                 if options.debug: print " -- NOK (no picon image)"
236
                 if options.debug: print " -- NOK (no picon image)"
214
                 continue
237
                 continue
215
 
238
 
216
             if options.debug: print " -- downloaded"
239
             if options.debug: print " -- downloaded"
217
-            im.save(fname,"png")
218
-            del im
240
+            im2.save(fname,"png")
241
+            del im2,im
219
             num_picons += 1
242
             num_picons += 1
220
 
243
 
221
     print "%i picons created, %i skipped"%(num_picons,num_skipped)
244
     print "%i picons created, %i skipped"%(num_picons,num_skipped)

+ 1
- 1
imake.bat View File

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

+ 11
- 2
plugin.py View File

68
             param += " -s %s"%(item) if item <> "all" else ""
68
             param += " -s %s"%(item) if item <> "all" else ""
69
             param += " -o" if config.plugins.getpicons.overwrite.value else ""
69
             param += " -o" if config.plugins.getpicons.overwrite.value else ""
70
             param += " -z %s"%config.plugins.getpicons.size.value if config.plugins.getpicons.size.value else ""
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
             cur_directory = os.path.dirname(os.path.realpath(__file__))
74
             cur_directory = os.path.dirname(os.path.realpath(__file__))
72
             name = os.path.join(cur_directory,"get_picons.py")
75
             name = os.path.join(cur_directory,"get_picons.py")
73
             cmd = "python -u %s -f %s %s"%(name,config.plugins.getpicons.folder.value,param,)
76
             cmd = "python -u %s -f %s %s"%(name,config.plugins.getpicons.folder.value,param,)
93
 Could be run from terminal too:
96
 Could be run from terminal too:
94
 /usr/script/get_picons.sh -h
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
         self.session.open(MessageBox, txt, MessageBox.TYPE_INFO)
101
         self.session.open(MessageBox, txt, MessageBox.TYPE_INFO)
99
         #self.session.openWithCallback(self.callMyMsg, MessageBox, _("Do you want to exit the plugin?"), MessageBox.TYPE_INFO)
102
         #self.session.openWithCallback(self.callMyMsg, MessageBox, _("Do you want to exit the plugin?"), MessageBox.TYPE_INFO)
100
         return
103
         return
111
 config.plugins.getpicons.folder = ConfigDirectory(default="/media/hdd")
114
 config.plugins.getpicons.folder = ConfigDirectory(default="/media/hdd")
112
 config.plugins.getpicons.size = ConfigSelection({"400x240":"400x240","220x132":"220x132","100x60":"100x60"}, default="220x132")
115
 config.plugins.getpicons.size = ConfigSelection({"400x240":"400x240","220x132":"220x132","100x60":"100x60"}, default="220x132")
113
 config.plugins.getpicons.overwrite = ConfigYesNo(default = True)
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
 class ConfigScreen(ConfigListScreen,Screen):
121
 class ConfigScreen(ConfigListScreen,Screen):
116
     skin = """
122
     skin = """
137
             getConfigListEntry(_("Picons folder"), cfg.folder),
143
             getConfigListEntry(_("Picons folder"), cfg.folder),
138
             getConfigListEntry(_("Picon size"), cfg.size),
144
             getConfigListEntry(_("Picon size"), cfg.size),
139
             getConfigListEntry(_("Overwrite existing picon files"), cfg.overwrite),
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
         ConfigListScreen.__init__(self, self.list, session = self.session)
150
         ConfigListScreen.__init__(self, self.list, session = self.session)
142
         self["key_red"] = Button(_("Cancel"))
151
         self["key_red"] = Button(_("Cancel"))

+ 7
- 5
readme.md View File

2
 
2
 
3
 #### Enigma2 plugin to dowload and create channels picons files form lyngsat.com
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
 No symlinks are created for same images.
9
 No symlinks are created for same images.
8
 
10
 
9
 You can run it several ways:
11
 You can run it several ways:
10
 
12
 
11
 1. As a Dreambox plugin (GetPicons)
13
 1. As a Dreambox plugin (GetPicons)
12
 2. From Dreambox command line (/usr/script/get_picons.sh)
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
 **Prerequisites**:
17
 **Prerequisites**:
16
 - Python 2.x
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
 **Usage (command line):**
21
 **Usage (command line):**
20
 ```
22
 ```
29
     -f PATH, --folder PATH                      picon files output folder, default - "/media/hdd/picon"
31
     -f PATH, --folder PATH                      picon files output folder, default - "/media/hdd/picon"
30
     -e PATH, --enigma PATH                      enigma2 folder whera lamedb,settings are located, default - "/etc/enigma2"
32
     -e PATH, --enigma PATH                      enigma2 folder whera lamedb,settings are located, default - "/etc/enigma2"
31
                                                 you can use urls, e.g. "ftp://root@receiver_address/etc/enigma2"
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
     -d, -debug                                  display work progress and write debug info to file for not found services
35
     -d, -debug                                  display work progress and write debug info to file for not found services
34
     -h, --help                                  this help file
36
     -h, --help                                  this help file
35
 
37