Ver código fonte

--hires -r opcija

try/except lai nelido ārā uz bojātiem imidžiem
Ivars 7 anos atrás
pai
commit
f1da2f6b74
2 arquivos alterados com 46 adições e 16 exclusões
  1. 21
    0
      deploy.bat
  2. 25
    16
      get_picons.py

+ 21
- 0
deploy.bat Ver arquivo

@@ -0,0 +1,21 @@
1
+@echo off
2
+set dm=dm800se
3
+
4
+if (dm800se)==(%1%) (
5
+	set TARGET=v:\usr\lib\enigma2\python\Plugins\Extensions\GetPicons\
6
+) else if (dm500hd)==(%1%) (
7
+	set TARGET=u:\usr\lib\enigma2\python\Plugins\Extensions\GetPicons\
8
+) else (
9
+	echo Not valid dreambox name
10
+	pause
11
+	GOTO:EOF
12
+)
13
+
14
+for %%f in (
15
+readme.txt
16
+__init__.py
17
+plugin.py
18
+get_picons.py
19
+) do echo f | xcopy /y  %%f %TARGET%%%f
20
+
21
+pause

+ 25
- 16
get_picons.py Ver arquivo

@@ -59,8 +59,8 @@ def main(argv):
59 59
     global options, args, services
60 60
 
61 61
     # Parsing options
62
-    opt_short = 'p:s:z:f:e:odh'
63
-    opt_long = ["package=","sat","folder=","enigma=","overwrite","debug","help"]
62
+    opt_short = 'p:s:z:f:e:ordh'
63
+    opt_long = ["package=","sat","folder=","enigma=","overwrite","hires","debug","help"]
64 64
     options,args = parse_arguments(argv[1:], opt_short, opt_long)
65 65
     options.package = _sd(options.package,_sd(options.p,""))
66 66
     options.sat = _sd(options.sat,_sd(options.s,""))
@@ -69,6 +69,7 @@ def main(argv):
69 69
     options.size = _sd(options.size,_sd(options.z,"220x132"))
70 70
     options.overwrite = _sl(_sd(options.overwrite,options.o))
71 71
     options.debug = _sl(_sd(options.debug,options.d))
72
+    options.hires = _sl(_sd(options.hires,options.r))
72 73
 
73 74
     options.w,options.h = map(int,options.size.split("x"))
74 75
     if not os.path.exists(options.folder):
@@ -78,7 +79,7 @@ def main(argv):
78 79
         #filename="get_picons.log" if not os.name == "posix" else "/var/log/get_picons.log"
79 80
         filename = os.path.join(options.folder,"get_picons.log")
80 81
         FORMAT = "%(asctime)-15s %(message)s"
81
-        logging.basicConfig(filename=filename, format=FORMAT,level=logging.DEBUG)
82
+        logging.basicConfig(filename=filename, format=FORMAT,level=logging.ERROR)
82 83
 
83 84
     print "** Analyzing lamedb"
84 85
     services = DBServices(options.enigma)
@@ -151,9 +152,10 @@ def create_picons(package):
151 152
                 #icon_url = "http://www.lyngsat.com" + icon_url.group(1).replace("/icon","/logo").replace(".gif",".jpg")
152 153
                 # https://www.lyngsat.com/logo/tv/vv/viasat_history.png
153 154
                 # https://www.lyngsat-logo.com/hires/vv/viasat_history.png
154
-                icon_url = "https://www.lyngsat.com" + icon_url.group(1) # simple picture
155
-                # TODO - varētu ņemt labo bildi un pēc tam to jēdzīgi apstrādāt ?
156
-                #icon_url = "https://www.lyngsat-logo.com" + icon_url.group(1).replace("/logo/tv","/hires") # advanced picture
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
157 159
             else:
158 160
                 icon_url = ""
159 161
             name = html_text(td[b+1]).group(1)
@@ -179,10 +181,12 @@ def create_picons(package):
179 181
                 sref = find_sref(ns,freq+1,polar,sid)
180 182
                 if not sref:
181 183
                     sref = find_sref(ns,freq-1,polar,sid)
184
+                    if not sref:
185
+                        sref = find_sref(ns, freq, polar-2, sid)
182 186
             if not sref:
183 187
                 if options.debug:
184 188
                     print " -- NOK (no sref in lamedb!)"
185
-                    logging.debug(u" no sref - package:%i/%s: service:%s pos:%s/%s freq:%i polar:%s sid:%i/%x"%(ns,package, name,ns, pos_int2str(ns),freq,polar,sid,sid))
189
+                    logging.error(u" no sref - package:%i/%s: service:%s pos:%s/%s freq:%i polar:%s sid:%i/%x"%(ns,package, name,ns, pos_int2str(ns),freq,polar,sid,sid))
186 190
                 continue
187 191
 
188 192
             fname = sref.replace(":","_")
@@ -196,19 +200,22 @@ def create_picons(package):
196 200
             #try:
197 201
             #im = Image.open(StringIO(urllib2.urlopen(icon_url).read()))
198 202
             data = get_page(icon_url)
199
-            im = Image.open(StringIO(data))
200
-            #im = im.crop((0,10,132,89))
201
-    
202
-            im = im.resize((options.w,options.h), Image.ANTIALIAS)
203
-            im = im.convert('P', palette=Image.ADAPTIVE)
204
-            #except Exception:
205
-            #    im = None
203
+            if not data:
204
+                if options.debug: print " -- NOK (no picon image)"
205
+                continue
206
+            try:
207
+                im = Image.open(StringIO(data))
208
+                im.thumbnail((options.w,options.h), Image.ANTIALIAS)
209
+                im = im.convert('P', palette=Image.ADAPTIVE)
210
+            except Exception:
211
+                im = None
206 212
             if not im:
207 213
                 if options.debug: print " -- NOK (no picon image)"
208 214
                 continue
209 215
 
210 216
             if options.debug: print " -- downloaded"
211 217
             im.save(fname,"png")
218
+            del im
212 219
             num_picons += 1
213 220
 
214 221
     print "%i picons created, %i skipped"%(num_picons,num_skipped)
@@ -550,9 +557,11 @@ Referer: http://www.lyngsat.com/
550 557
 """)
551 558
 
552 559
 def get_page(url):
553
-    
554 560
    r=requests.get(url,headers=headers)
555
-   return r.content
561
+   if r.status_code in (200,304):
562
+        return r.content
563
+   else:
564
+       return ""
556 565
     
557 566
     
558 567
 html_text = lambda html: re.search(r">([^<^\n]+?)<", html, re.DOTALL | re.IGNORECASE)