Browse Source

--hires -r opcija

try/except lai nelido ārā uz bojātiem imidžiem
Ivars 7 years ago
parent
commit
f1da2f6b74
2 changed files with 46 additions and 16 deletions
  1. 21
    0
      deploy.bat
  2. 25
    16
      get_picons.py

+ 21
- 0
deploy.bat View File

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 View File

59
     global options, args, services
59
     global options, args, services
60
 
60
 
61
     # Parsing options
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
     options,args = parse_arguments(argv[1:], opt_short, opt_long)
64
     options,args = parse_arguments(argv[1:], opt_short, opt_long)
65
     options.package = _sd(options.package,_sd(options.p,""))
65
     options.package = _sd(options.package,_sd(options.p,""))
66
     options.sat = _sd(options.sat,_sd(options.s,""))
66
     options.sat = _sd(options.sat,_sd(options.s,""))
69
     options.size = _sd(options.size,_sd(options.z,"220x132"))
69
     options.size = _sd(options.size,_sd(options.z,"220x132"))
70
     options.overwrite = _sl(_sd(options.overwrite,options.o))
70
     options.overwrite = _sl(_sd(options.overwrite,options.o))
71
     options.debug = _sl(_sd(options.debug,options.d))
71
     options.debug = _sl(_sd(options.debug,options.d))
72
+    options.hires = _sl(_sd(options.hires,options.r))
72
 
73
 
73
     options.w,options.h = map(int,options.size.split("x"))
74
     options.w,options.h = map(int,options.size.split("x"))
74
     if not os.path.exists(options.folder):
75
     if not os.path.exists(options.folder):
78
         #filename="get_picons.log" if not os.name == "posix" else "/var/log/get_picons.log"
79
         #filename="get_picons.log" if not os.name == "posix" else "/var/log/get_picons.log"
79
         filename = os.path.join(options.folder,"get_picons.log")
80
         filename = os.path.join(options.folder,"get_picons.log")
80
         FORMAT = "%(asctime)-15s %(message)s"
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
     print "** Analyzing lamedb"
84
     print "** Analyzing lamedb"
84
     services = DBServices(options.enigma)
85
     services = DBServices(options.enigma)
151
                 #icon_url = "http://www.lyngsat.com" + icon_url.group(1).replace("/icon","/logo").replace(".gif",".jpg")
152
                 #icon_url = "http://www.lyngsat.com" + icon_url.group(1).replace("/icon","/logo").replace(".gif",".jpg")
152
                 # https://www.lyngsat.com/logo/tv/vv/viasat_history.png
153
                 # https://www.lyngsat.com/logo/tv/vv/viasat_history.png
153
                 # https://www.lyngsat-logo.com/hires/vv/viasat_history.png
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
             else:
159
             else:
158
                 icon_url = ""
160
                 icon_url = ""
159
             name = html_text(td[b+1]).group(1)
161
             name = html_text(td[b+1]).group(1)
179
                 sref = find_sref(ns,freq+1,polar,sid)
181
                 sref = find_sref(ns,freq+1,polar,sid)
180
                 if not sref:
182
                 if not sref:
181
                     sref = find_sref(ns,freq-1,polar,sid)
183
                     sref = find_sref(ns,freq-1,polar,sid)
184
+                    if not sref:
185
+                        sref = find_sref(ns, freq, polar-2, sid)
182
             if not sref:
186
             if not sref:
183
                 if options.debug:
187
                 if options.debug:
184
                     print " -- NOK (no sref in lamedb!)"
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
                 continue
190
                 continue
187
 
191
 
188
             fname = sref.replace(":","_")
192
             fname = sref.replace(":","_")
196
             #try:
200
             #try:
197
             #im = Image.open(StringIO(urllib2.urlopen(icon_url).read()))
201
             #im = Image.open(StringIO(urllib2.urlopen(icon_url).read()))
198
             data = get_page(icon_url)
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
             if not im:
212
             if not im:
207
                 if options.debug: print " -- NOK (no picon image)"
213
                 if options.debug: print " -- NOK (no picon image)"
208
                 continue
214
                 continue
209
 
215
 
210
             if options.debug: print " -- downloaded"
216
             if options.debug: print " -- downloaded"
211
             im.save(fname,"png")
217
             im.save(fname,"png")
218
+            del im
212
             num_picons += 1
219
             num_picons += 1
213
 
220
 
214
     print "%i picons created, %i skipped"%(num_picons,num_skipped)
221
     print "%i picons created, %i skipped"%(num_picons,num_skipped)
550
 """)
557
 """)
551
 
558
 
552
 def get_page(url):
559
 def get_page(url):
553
-    
554
    r=requests.get(url,headers=headers)
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
 html_text = lambda html: re.search(r">([^<^\n]+?)<", html, re.DOTALL | re.IGNORECASE)
567
 html_text = lambda html: re.search(r">([^<^\n]+?)<", html, re.DOTALL | re.IGNORECASE)