Browse Source

Initial commit

Ivars 8 years ago
commit
c129d8ba9f
9 changed files with 1448 additions and 0 deletions
  1. 1
    0
      __init__.py
  2. 576
    0
      get_picons.py
  3. 5
    0
      get_picons.sh
  4. 25
    0
      get_picons.txt
  5. 19
    0
      get_picons.wpr
  6. 544
    0
      get_picons.wpu
  7. 76
    0
      imake.bat
  8. 195
    0
      plugin.py
  9. 7
    0
      readme.txt

+ 1
- 0
__init__.py View File

@@ -0,0 +1 @@
1
+

+ 576
- 0
get_picons.py View File

@@ -0,0 +1,576 @@
1
+# coding: utf-8
2
+#
3
+# This file is part of GetPicons - enigma2 plugin to download picons from lyngsat.com
4
+# Copyright (c) 2016 ivars777 (ivars777@gmail.com)
5
+# Distributed under the GNU GPL v3. For full terms see http://www.gnu.org/licenses/gpl-3.0.en.html
6
+
7
+"""
8
+Dowload and create Enigma2 channels' picons files form lyngsat.com
9
+
10
+Usage [options]
11
+Options:
12
+    -p PACKAGE_LIST, --package=PACKAGE_LIST     list of package names (html file name in lyngsat),
13
+                                                e.g "viasat,ntvplus36"
14
+    -s  SAT_LIST, --sat=SAT_LIST                list of sattelite positions, e.g. "4.9,-0.8"
15
+    -z  SIZE                                    icon size, e.g. "100x60", default - "220x132"
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"
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
21
+    -h, --help                                  this help file
22
+
23
+(c)Ivars777 (ivars777@gmail.com) 2013-2015, v0.2
24
+"""
25
+
26
+import sys, os, os.path, getopt
27
+import re
28
+import urllib2
29
+import requests
30
+
31
+try:
32
+    import Image
33
+except:
34
+    from PIL import Image
35
+from StringIO import StringIO
36
+import logging
37
+
38
+options = args = None
39
+_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
41
+
42
+def parse_arguments(argv,opt_short,opt_long):
43
+    "Parse command line arguments"
44
+    try:
45
+        options, args = getopt.gnu_getopt(argv, opt_short,opt_long)
46
+        options = Rec(dict([(o[0].replace("-",""),o[1]) for o in options]))
47
+    except getopt.GetoptError, err:
48
+        print err.msg
49
+        print __doc__
50
+        sys.exit(2)
51
+    if options.has_key("h") or options.has_key("help"):
52
+        print __doc__
53
+        sys.exit(2)
54
+    return options,args
55
+
56
+services = None
57
+
58
+def main(argv):
59
+    global options, args, services
60
+
61
+    # Parsing options
62
+    opt_short = 'p:s:z:f:e:odh'
63
+    opt_long = ["package=","sat","folder=","enigma=","overwrite","debug","help"]
64
+    options,args = parse_arguments(argv[1:], opt_short, opt_long)
65
+    options.package = _sd(options.package,_sd(options.p,""))
66
+    options.sat = _sd(options.sat,_sd(options.s,""))
67
+    options.enigma = _sd(options.enigma,_sd(options.e,"/etc/enigma2"))
68
+    options.folder = _sd(options.folder,_sd(options.f,"/media/hdd/picon"))
69
+    options.size = _sd(options.size,_sd(options.z,"220x132"))
70
+    options.overwrite = _sl(_sd(options.overwrite,options.o))
71
+    options.debug = _sl(_sd(options.debug,options.d))
72
+
73
+    options.w,options.h = map(int,options.size.split("x"))
74
+    if not os.path.exists(options.folder):
75
+        os.makedirs(options.folder)
76
+
77
+    if options.debug:
78
+        #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
+        FORMAT = "%(asctime)-15s %(message)s"
81
+        logging.basicConfig(filename=filename, format=FORMAT,level=logging.DEBUG)
82
+
83
+    print "** Analyzing lamedb"
84
+    services = DBServices(options.enigma)
85
+    if options.sat:
86
+        package_list = []
87
+        for sat in options.sat.split(","):
88
+            package_list.extend(get_packages(sat))
89
+    elif options.package:
90
+        package_list = options.package.split(",")
91
+    else: # get sattelite list from Enigma settings
92
+        sat_list = []
93
+        package_list = []
94
+        if not "ftp:" in options.enigma:
95
+            fname = os.path.join(options.enigma,"settings")
96
+            f = open(fname)
97
+        else:
98
+            sep = "" if options.enigma[-1]=="//" else "//"
99
+            fname = options.enigma + sep + "settings"
100
+            f = urllib2.urlopen(fname)
101
+        for line in f:
102
+            if not "config.Nims.0.advanced.sat." in line: continue
103
+            sat_list.append(line.split(".")[5])
104
+        for sat in sat_list:
105
+            package_list.extend(get_packages(sat))
106
+
107
+    for package in package_list:
108
+        create_picons(package)
109
+
110
+def create_picons(package):
111
+    "Create picons files for package"
112
+    global services,options
113
+    url_package = "http://www.lyngsat.com/packages/%s.html"%package
114
+    if options.debug:
115
+        print "** Downloading and looking %s for picons"%url_package
116
+    num_picons = 0
117
+    num_skipped = 0
118
+    num = 0
119
+    try:
120
+        #soup = html = urllib2.urlopen(url_package).read().decode("latin1")
121
+        soup = html = get_page(url_package).decode("latin1")
122
+    except:
123
+        raise Exception("Package page '%s' does not found"%url_package)
124
+    title = re.search("<title>(.+?)</title>", soup, re.DOTALL | re.IGNORECASE).group(1)
125
+    pos = re.search("\d+\.\d+",title).group().replace(".","")
126
+    ew = re.search("\xb0.",title).group()[1]
127
+    ns = int(pos)
128
+    if ew == "W":
129
+        ns = 3600 - ns
130
+    if ns==48: ns=49
131
+    if ns==359: ns=360
132
+    #pos = "%04x0000"%ns
133
+    #pos_num = int(pos[0:4],16)
134
+    title2 = title[0:title.index("- LyngSat")]
135
+    print "** %s: "%title2.replace(u'\xb0',""),
136
+    tables = re.findall(r"<table width=720 border cellspacing=0 cellpadding=0>\s*(?:(?=<tr>))(.+?)</table>", soup, re.DOTALL | re.IGNORECASE)
137
+    for table in tables:
138
+        tr= html_findall("tr",table)
139
+        for i in range(2,len(tr)-1):
140
+            td= html_findall("td",tr[i])
141
+            if len(td) == 10:
142
+                freq,polar = re.search(r"<b>(\d+) ([HVLR])", tr[i], re.DOTALL | re.IGNORECASE).groups()
143
+                freq = int(freq)
144
+                p_value = {"H":0,"V":1,"L":2,"R":3}
145
+                polar = p_value[polar]
146
+                b=1
147
+            else:
148
+                b=0
149
+            icon_url = html_attr("src",td[b])
150
+            if icon_url:
151
+                icon_url = "http://www.lyngsat.com" + icon_url.group(1).replace("/icon","/logo").replace(".gif",".jpg")
152
+            else:
153
+                icon_url = ""
154
+            name = html_text(td[b+1]).group(1)
155
+            sid = html_text(td[b+5])
156
+            sid = sid.group(1).replace("&nbsp;","") if sid else ""
157
+            sid = int(sid) if sid and not sid == u"-" else ""
158
+            vpid = html_text(td[b+6])
159
+            vpid = vpid.group(1).replace("&nbsp;","") if vpid else ""
160
+            #try:
161
+            #    vpid = int(vpid)
162
+            #except Exception:
163
+            #    vpid = None
164
+            #vpid = int(vpid) if vpid and not vpid == u"-" else None
165
+            if not sid  or not vpid or icon_url=="":
166
+                continue
167
+
168
+            if options.debug:
169
+                print " package:%i/%s: service:%s "%(ns,package, name.encode("ascii","replace")),
170
+            num += 1
171
+
172
+            sref = find_sref(ns,freq,polar,sid)
173
+            if not sref:
174
+                sref = find_sref(ns,freq+1,polar,sid)
175
+                if not sref:
176
+                    sref = find_sref(ns,freq-1,polar,sid)
177
+            if not sref:
178
+                if options.debug:
179
+                    print " -- NOK (no sref in lamedb!)"
180
+                    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))
181
+                continue
182
+
183
+            fname = sref.replace(":","_")
184
+            fname  = fname[:-1]+".png"
185
+            fname = os.path.join(options.folder, fname)
186
+            if os.path.exists(fname) and not options.overwrite:
187
+                if options.debug: print " -- skipped"
188
+                num_skipped += 1
189
+                continue
190
+
191
+            #try:
192
+            #im = Image.open(StringIO(urllib2.urlopen(icon_url).read()))
193
+            data = get_page(icon_url)
194
+            im = Image.open(StringIO(data))
195
+            #im = im.crop((0,10,132,89))
196
+    
197
+            im = im.resize((options.w,options.h), Image.ANTIALIAS)
198
+            im = im.convert('P', palette=Image.ADAPTIVE)
199
+            #except Exception:
200
+            #    im = None
201
+            if not im:
202
+                if options.debug: print " -- NOK (no picon image)"
203
+                continue
204
+
205
+            if options.debug: print " -- downloaded"
206
+            im.save(fname,"png")
207
+            num_picons += 1
208
+
209
+    print "%i picons created, %i skipped"%(num_picons,num_skipped)
210
+
211
+def get_packages(sat):
212
+    "Get packages list (names) for sattelite from lyngsat.com page"
213
+    global options
214
+    sat= sat.replace(".","")
215
+    num = int(sat)
216
+    if num>1800: num = num - 3600
217
+    if num>0 and num<730: soup = get_soup("europe")
218
+    elif num>730 and num<1600: soup = get_soup("asia")
219
+    elif num<0 and num>-610: soup = get_soup("atlantic")
220
+    elif num<-610 and num>-1600: soup = get_soup("america")
221
+    else:
222
+        return []
223
+    i1,i2 = gr=re.search(r"<table cellspacing=0 border>\s*(?:(?=<tr>))(.+?)</table>", soup, re.DOTALL | re.IGNORECASE).span()
224
+    packages = []
225
+    for s in re.findall("<tr>(.+?)</tr>", soup[i1:i2], re.DOTALL | re.IGNORECASE):
226
+        gr = re.search(r"(\d+.)</font><font size=1>(\d).+#176;([EW])", s,re.DOTALL | re.IGNORECASE).groups()
227
+        pos = int("".join(gr[:-1]).replace(".",""))
228
+        if gr[2] == "W": pos = -pos
229
+        if abs(num - pos) <=2:
230
+            package = re.search(r"www\.lyngsat\.com/packages/(\w.+?)\.html", s, re.DOTALL | re.IGNORECASE).group(1)
231
+            packages.append(package)
232
+    return packages
233
+
234
+soups = {}
235
+def get_soup(region):
236
+    if soups.has_key(region):
237
+        return soups[region]
238
+    url = "http://www.lyngsat.com/packages/%s.html"%region
239
+    if options.debug:
240
+        print "** Downloading and looking %s for packages"%url
241
+    try:
242
+        #html = urllib2.urlopen(url).read().decode("latin1")
243
+        html = get_page(url).decode("latin1")
244
+    except:
245
+        raise Exception("Packege page '%s' does not found"%url)
246
+    soups[region] = html
247
+    return soups[region]
248
+
249
+
250
+def find_sref(ns,freq,polar,sid):
251
+    "Find service reference according to given parameters"
252
+    global services
253
+    tp = services.get_transp_by_pic((ns,freq,polar))
254
+    if tp:
255
+        serv = services.get_service_by_chid((sid,tp["tsid"],tp["onid"]))
256
+        if serv:
257
+            return serv["sref"]
258
+
259
+class DBServices(object):
260
+    """Dreambox services, stored in lamedb (E2)/services(E1) file handling class"""
261
+
262
+    def __init__(self,service_path,enigma=2):
263
+        self.enigma = enigma
264
+        self.service_path = service_path
265
+
266
+        if self.enigma == 2:
267
+            if not "ftp:" in service_path:
268
+                self.service_fname= os.path.join(service_path,"lamedb")
269
+                self.bouquets_fname = os.path.join(service_path, "bouquets.tv")
270
+            else:
271
+                sep = "" if service_path[-1]=="//" else "//"
272
+                self.service_fname= service_path+sep+"lamedb"
273
+                self.bouquets_fname = service_path+sep+"bouquets.tv"
274
+
275
+        else: # ENIGMA === "1":
276
+            self.service_fname = os.path.join(service_path,"services")
277
+            self.bouquets_fname = os.path.join(service_path, "userbouquets.tv.epl")
278
+
279
+        self.services = []
280
+        self.index_sref= {}
281
+        self.index_chid = {}
282
+        self.index_name = {}
283
+        self.index_provider = {}
284
+        self.bouquets = []
285
+        self.bouquets_services = {}
286
+
287
+        self.transp = []
288
+        self.tp_index_tpid = {}
289
+        self.tp_index_pic ={}
290
+
291
+        self._load_services()
292
+        #self._load_bouquets()
293
+
294
+    def _load_services(self):
295
+        #tpref - lamedb/transponders
296
+        # NS:TSID:ONID
297
+        #     s FREQ:SR:POLAR:FREC:49:2:0
298
+        #  X    X   X
299
+        #         D    D  D     D
300
+
301
+        # lref - lamedb/services
302
+        #	SID:NS:TSID:ONID:STYPE:UNUSED(channelnumber in enigma1)
303
+        #	0   1  2    3    4     5
304
+        #	X   X  X    X    D     D
305
+        # wref bouquets/picon
306
+        #   REFTYPE:FLAGS:STYPE:SID:TSID:ONID:NS:PARENT_SID:PARENT_TSID:UNUSED
307
+        #   0       1     2     3   4    5    6  7          8           9
308
+        #   D       D     X     X   X    X    X  X          X           X
309
+
310
+        f_services = open(self.service_fname,"r") if not self.service_fname[0:4] == "ftp:" else urllib2.urlopen(self.service_fname)
311
+
312
+        line = f_services.readline()
313
+        if not "eDVB services" in line:
314
+            raise Exception("no correct lamedb file")
315
+        line = f_services.readline()
316
+
317
+        # Read transponders
318
+        i = 0
319
+        while True:
320
+            line = f_services.readline()
321
+            if  "end" in line: break
322
+            #tp = record.Rec()
323
+            tp = {}
324
+            ff = line.strip().split(":")
325
+            tp["ns"] = ns = pos_str2int(ff[0])
326
+            tp["tsid"] = tsid = int(ff[1],16)
327
+            tp["onid"] = onid = int(ff[2],16)
328
+            line = f_services.readline()
329
+            tp["params"] = params = line.strip().split(" ")[1]
330
+            ff = params.split(":")
331
+            tp["freq"] = freq = int(ff[0][:-3])
332
+            tp["polar"] = polar = int(ff[2])
333
+            tp["tpid"] = tpid = (ns,tsid,onid)
334
+            self.transp.append(tp)
335
+            self.tp_index_tpid[tpid] = i
336
+            self.tp_index_pic[(ns,freq,polar)] = i
337
+
338
+            line = f_services.readline()
339
+            i += 1
340
+
341
+        # Reading services
342
+        i= 0
343
+        line = f_services.readline()
344
+        while True:
345
+
346
+            line = f_services.readline()
347
+            if line[0:3] == "end": break
348
+            if not line: break
349
+            #rec = record.Rec()
350
+            rec = {}
351
+            rec["lref"] = line.lower().strip().decode("utf-8")
352
+
353
+            line = f_services.readline()
354
+            #line = line.replace('\xc2\x87', '').replace('\xc2\x86', '')
355
+            #line = decode_charset(line)
356
+            line = line.decode("utf-8")
357
+            rec["name"] = line.strip()
358
+
359
+            line = f_services.readline()
360
+            pl = line.split(",")
361
+            provider = ""
362
+            for p in pl:
363
+                if p[0:2] == "p:":
364
+                    provider = p[2:].strip()
365
+                    break
366
+            if provider == "":
367
+                provider = "unknown"
368
+            rec["provider"] = provider.decode("utf-8")
369
+
370
+            rec["sref"] = lref2sref(rec["lref"])
371
+            r = lref_parse(rec["lref"])
372
+            rec["stype"] = r["stype"]
373
+            rec["chid"]  = (r["sid"],r["tsid"],r["onid"])
374
+            self.services.append(rec)
375
+
376
+            self.index_sref[rec["sref"]] = i
377
+            self.index_chid[rec["chid"]] = i
378
+            name = rec["name"].lower()
379
+            if not self.index_name.has_key(name): self.index_name[name] = []
380
+            self.index_name[name].append(i)
381
+            provider = rec["provider"].lower()
382
+            if not self.index_provider.has_key(provider): self.index_provider[provider] = []
383
+            self.index_provider[provider].append(i)
384
+
385
+            i += 1
386
+
387
+        f_services.close()
388
+
389
+    def _load_bouquets(self):
390
+        f_bouquets = open(self.bouquets_fname,"r") if not self.bouquets_fname[0:4] == "ftp:" else urllib2.urlopen(self.bouquets_fname)
391
+        for line in f_bouquets.readlines():
392
+            if line[0:9] == "#SERVICE:":
393
+                if self.enigma==1:
394
+                    bn = line.strip().split("/")
395
+                else:
396
+                    bn = line.strip().split(":")
397
+                bfn = bn[-1]
398
+                bf = open(os.path.join(self.service_path,bfn))
399
+                for line2 in bf.readlines():
400
+                    if line2[0:5] == "#NAME":
401
+                        bname = line2.strip()[6:]
402
+                        self.bouquets.append(bname)
403
+                        self.bouquets_services[bname] = []
404
+                    elif line2[0:8] == "#SERVICE":
405
+                        sref = line2.strip()[9:]
406
+                        r = sref_parse(sref)
407
+                        if r["flags"] == 64: continue
408
+                        self.bouquets_services[bname].append(sref)
409
+                bf.close()
410
+        f_bouquets.close()
411
+
412
+    def get_bouquets(self):
413
+        if not self.bouquets:
414
+            self._load_bouquets()
415
+        return self.bouquets
416
+
417
+    def get_bouquet_services(self,bn):
418
+        if not self.bouquets:
419
+            self._load_bouquets()
420
+        return [self.get_service_by_sref(sref) for sref in self.bouquets_services[bn]]
421
+
422
+    def get_service_by_sref(self,sref):
423
+        return self.services[self.index_sref[sref]] if self.index_sref.has_key(sref) else None
424
+
425
+    def get_service_by_chid(self,chid):
426
+        return self.services[self.index_chid[chid]] if self.index_chid.has_key(chid) else None
427
+
428
+    def get_service_by_name(self,name):
429
+        return [self.services[i] for i in self.index_name[name]]
430
+
431
+    def get_service_by_provider(self,provider):
432
+        return [self.services[i] for i in self.index_provider[provider]]
433
+
434
+    def get_transp_by_tpid(self,tpid):
435
+        return self.transp[self.tp_index_tpid[tpid]] if self.tp_index_tpid.has_key(tpid) else None
436
+
437
+    def get_transp_by_pic(self,picid):
438
+        return self.transp[self.tp_index_pic[picid]] if self.tp_index_pic.has_key(picid) else None
439
+
440
+def decode_charset(s):
441
+    u = None
442
+    if isinstance(s,unicode):
443
+        return s
444
+    charset_list=('iso-8859-4','iso-8859-1','iso-8859-2''iso-8859-15')
445
+
446
+    for charset in charset_list:
447
+        try:
448
+            u=unicode(s,charset,"strict")
449
+        except:
450
+            pass
451
+        else:
452
+            break
453
+
454
+    if u == None:
455
+        raise Error, "CHARSET ERROR while decoding lamedb. Aborting !"
456
+    else:
457
+        return(u)
458
+
459
+# lref - lamedb/services
460
+#	SID:NS:TSID:ONID:STYPE:UNUSED(channelnumber in enigma1)
461
+#	0   1  2    3    4     5
462
+#	X   X  X    X    D     D
463
+#
464
+# wref bouquets/picon
465
+#   REFTYPE:FLAGS:STYPE:SID:TSID:ONID:NS:PARENT_SID:PARENT_TSID:UNUSED
466
+#   0       1     2     3   4    5    6  7          8           9
467
+#   D       D     X     X   X    X    X  X          X           X
468
+
469
+def lref2sref(s):
470
+    "Converts service refefence from lamedb format to bouquets/picon (standard) format"
471
+    f = s.split(":")
472
+    sid = int(f[0],16)
473
+    ns = int(f[1], 16)
474
+    tsid = int(f[2],16)
475
+    onid = int(f[3],16)
476
+    stype = int(f[4])
477
+
478
+    s2 = "1:0:%X:%X:%X:%X:%X:0:0:0:" % (stype,sid,tsid,onid,ns)
479
+    return s2
480
+
481
+def lref_parse(s):
482
+    "Parse lamedb/service string, return dictionary of items"
483
+    f = s.split(":")
484
+    r = {}
485
+    r["sid"] = int(f[0],16)
486
+    r["ns"] = int(f[1], 16)
487
+    r["tsid"] = int(f[2],16)
488
+    r["onid"] = int(f[3],16)
489
+    r["stype"] = int(f[4])
490
+    return r
491
+
492
+def sref2lref(s):
493
+    "Converts service refefence from bouquets/picon (standard) format to lamedb format"
494
+    f = s.split(":")
495
+    reftype = int(f[0])
496
+    flags = int(f[1])
497
+    stype = int(f[2],16)
498
+    sid = int(f[3],16)
499
+    tsid = int(f[4],16)
500
+    onid = int(f[5],16)
501
+    ns = int(f[6],16)
502
+
503
+    s2 = "%04x:%08x:%04x:%04x:%i:0" % (sid,ns,tsid,onid,stype)
504
+    return s2
505
+
506
+def sref_parse(s):
507
+    "Parse service refefence string , return dictionary of items"
508
+    f = s.split(":")
509
+    r = {}
510
+    r["reftype"] = int(f[0])
511
+    r["flags"] = int(f[1])
512
+    r["stype"] = int(f[2],16)
513
+    r["sid"] = int(f[3],16)
514
+    r["tsid"] = int(f[4],16)
515
+    r["onid"] = int(f[5],16)
516
+    r["ns"] = int(f[6],16)
517
+    return r
518
+
519
+pos_int2str = lambda pos_num: "%04x0000"%pos_num
520
+pos_str2int = lambda pos: int(pos[0:4],16)
521
+
522
+
523
+def decode_charset(s):
524
+    u = None
525
+    charset_list = ('utf-8','iso-8859-1','iso-8859-2','iso-8859-15')
526
+
527
+    for charset in charset_list:
528
+        try:
529
+            u = unicode(s,charset,"strict")
530
+        except:
531
+            pass
532
+        else:
533
+            break
534
+
535
+    if u == None:
536
+        print("CHARSET ERROR while decoding string")
537
+        sys.exit(1)
538
+    else:
539
+        return(u)
540
+    
541
+headers2dict = lambda  h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
542
+headers = headers2dict("""
543
+User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0
544
+Referer: http://www.lyngsat.com/
545
+""")
546
+
547
+def get_page(url):
548
+    
549
+   r=requests.get(url,headers=headers)
550
+   return r.content
551
+    
552
+    
553
+html_text = lambda html: re.search(r">([^<^\n]+?)<", html, re.DOTALL | re.IGNORECASE)
554
+html_tag = lambda tag, html: re.search(r"<%s\b[^>]*>(.*?)</%s>"%(tag,tag), html, re.DOTALL | re.IGNORECASE)
555
+html_attr = lambda attr,html: re.search("""%s="?([^'" >]+)"""%(attr), html, re.DOTALL | re.IGNORECASE)
556
+html_findall_content = lambda tag,html: re.findall(r"<%s\b[^>]*>(.*?)</%s>"%(tag,tag), html, re.DOTALL | re.IGNORECASE)
557
+html_findall = lambda tag,html: re.findall(r"<%s\b[^>]*>.*?</%s>"%(tag,tag), html, re.DOTALL | re.IGNORECASE)
558
+
559
+import UserDict
560
+class Rec(UserDict.DictMixin):
561
+    "Dict like class allowing a.x instead of a['x']"
562
+    def __init__(self, dict=None, **kwargs):
563
+        self.__dict__ = {}
564
+        if dict is not None:
565
+            self.update(dict)
566
+        if len(kwargs):
567
+            self.update(kwargs)
568
+    def __setitem__(self, name, value): setattr(self, name, value)
569
+    def __getitem__(self, name): return getattr(self,name,None)
570
+    def __getattr__(self,key): return None
571
+    def has_key(self,key): return True if self.__dict__.has_key(key) else False
572
+    def keys(self): return list(self.__dict__)
573
+
574
+if __name__ == "__main__":
575
+    #print "** Starting..."
576
+    sys.exit(main(sys.argv))

+ 5
- 0
get_picons.sh View File

@@ -0,0 +1,5 @@
1
+#!/bin/sh
2
+#DESCRIPTION=Get picons from lyngsat.com
3
+DIR="/usr/lib/enigma2/python/Plugins/Extensions/GetPicons"
4
+python -u $DIR/get_picons.py $@
5
+exit 0

+ 25
- 0
get_picons.txt View File

@@ -0,0 +1,25 @@
1
+Dowload and create Enigma2 channels' picons files form lyngsat.com
2
+You can run it both from Dreambox or computer
3
+ipk install file is provided, which install python script in Extensions folder as well as shell scipt in /user/script folder.
4
+Windows exe file is provided too.
5
+Prerequisites:
6
+	- Python 2.x
7
+	- Python libraries-  Imaging (PIL) (usually part of standart python)
8
+
9
+Usage [options]
10
+Options:
11
+    -p PACKAGE_LIST, --package=PACKAGE_LIST     list of package names (html file name in lyngsat),
12
+                                                e.g "viasat,ntvplus36"
13
+    -s  SAT_LIST, --sat=SAT_LIST                list of sattelite positions, e.g. "4.9,-0.8"
14
+    -f PATH, --folder PATH                      picon files output folder (piconHD added), default - "/hdd"
15
+    -e PATH, --enigma PATH                      enigma2 folder whera lamedb,settings are located, default - "/etc/enigma2"
16
+                                                you can use urls, e.g. "ftp://root@receiver_address/etc/enigma2"
17
+    -d, -debug                                  display work progress an	d write debug info to file for not found services
18
+    -h, --help                                  this help file
19
+
20
+(c)Ivars 2013, v0.2
21
+
22
+RELEASE NOTES:
23
+*** 13.10.2013, version 0.2 ***
24
+- html parsing is done wit regex instead of BeautifulSoup
25
+- initial public release

+ 19
- 0
get_picons.wpr View File

@@ -0,0 +1,19 @@
1
+#!wing
2
+#!version=5.0
3
+##################################################################
4
+# Wing IDE project file                                          #
5
+##################################################################
6
+[project attributes]
7
+proj.directory-list = [{'dirloc': loc('.'),
8
+                        'excludes': (),
9
+                        'filter': '*',
10
+                        'include_hidden': False,
11
+                        'recursive': True,
12
+                        'watch_for_changes': True}]
13
+proj.file-type = 'shared'
14
+proj.launch-config = {loc('get_picons.py'): ('project',
15
+        (u'-e enigma2 -f  picon  -s 49  -o \n\n\n',
16
+         '')),
17
+                      loc('get_sats.py'): ('project',
18
+        (u'-e E2 -f  E2',
19
+         ''))}

+ 544
- 0
get_picons.wpu View File

@@ -0,0 +1,544 @@
1
+#!wing
2
+#!version=5.0
3
+##################################################################
4
+# Wing IDE project file : User-specific branch                   #
5
+##################################################################
6
+[user attributes]
7
+debug.recent-run-args = {loc('get_picons.py'): [u'-e enigma2 -f  picon  -s 49  -o \n\n\n',
8
+        u'-e enigma2 -f  picon  -s 49  -o\n\n\n',
9
+        u'-e enigma2 -f  picon  -s 49  -d\n\n\n',
10
+        u'-e enigma2 -f  piconHD  -s 3592 -d\n\n\n',
11
+        u'-e enigma2 -f  piconHD  -s 3592 \n\n',
12
+        u'-e enigma2 -f  piconHD  -s 3592 -o\n',
13
+        u'-e enigma2 -f  piconHD  -s 3592\n',
14
+        u'-e enigma2 -f  piconsHD  -s 3592\n',
15
+        u'-e enigma2 -f  .  -s 3592\n',
16
+        u'-e enigma2 -f  .  -s 49\n',
17
+        u'-e enigma2 -f  .  -s 4.9\n',
18
+        u'-e enigma2 -f  .  -d -s 4.9\n',
19
+        u'-e enigma2 -f  .  -d\n']}
20
+guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
21
+                            'windows': [{'name': 'hO050WdOTcAgrxElFPSuy7htEQ'\
22
+        'RSpUFE',
23
+        'size-state': 'maximized',
24
+        'type': 'dock',
25
+        'view': {'area': 'tall',
26
+                 'constraint': None,
27
+                 'current_pages': [0,
28
+                                   0],
29
+                 'full-screen': False,
30
+                 'notebook_display': 'normal',
31
+                 'notebook_percent': 0.25,
32
+                 'override_title': None,
33
+                 'pagelist': [('project',
34
+                               'tall',
35
+                               0,
36
+                               {'tree-state': {'file-sort-method': 'by name',
37
+        'list-files-first': False,
38
+        'tree-states': {'deep': {'expanded-nodes': [],
39
+                                 'selected-nodes': [(10,)],
40
+                                 'top-node': (0,)}},
41
+        'tree-style': 'deep'}}),
42
+                              ('browser',
43
+                               'tall',
44
+                               0,
45
+                               {}),
46
+                              ('snippets',
47
+                               'tall',
48
+                               0,
49
+                               {}),
50
+                              ('source-assistant',
51
+                               'tall',
52
+                               2,
53
+                               {}),
54
+                              ('debug-stack',
55
+                               'tall',
56
+                               1,
57
+                               {}),
58
+                              ('indent',
59
+                               'tall',
60
+                               2,
61
+                               {})],
62
+                 'primary_view_state': {'area': 'wide',
63
+        'constraint': None,
64
+        'current_pages': [1,
65
+                          0],
66
+        'notebook_display': 'normal',
67
+        'notebook_percent': 0.30000000000000004,
68
+        'override_title': None,
69
+        'pagelist': [('batch-search',
70
+                      'wide',
71
+                      0,
72
+                      {'fScope': {'fFileSetName': u'All Source Files',
73
+                                  'fLocation': None,
74
+                                  'fRecursive': True,
75
+                                  'fType': 'project-files'},
76
+                       'fSearchSpec': {'fEndPos': None,
77
+                                       'fIncludeLinenos': True,
78
+                                       'fInterpretBackslashes': False,
79
+                                       'fMatchCase': False,
80
+                                       'fOmitBinary': True,
81
+                                       'fRegexFlags': 46,
82
+                                       'fReplaceText': u'',
83
+                                       'fReverse': False,
84
+                                       'fSearchText': u'',
85
+                                       'fStartPos': 0,
86
+                                       'fStyle': 'text',
87
+                                       'fWholeWords': False,
88
+                                       'fWrap': True},
89
+                       'fUIOptions': {'fAutoBackground': True,
90
+                                      'fFilePrefix': 'short-file',
91
+                                      'fFindAfterReplace': True,
92
+                                      'fInSelection': False,
93
+                                      'fIncremental': True,
94
+                                      'fReplaceOnDisk': False,
95
+                                      'fShowFirstMatch': False,
96
+                                      'fShowLineno': True,
97
+                                      'fShowReplaceWidgets': False},
98
+                       'replace-entry-expanded': False,
99
+                       'search-entry-expanded': False}),
100
+                     ('interactive-search',
101
+                      'wide',
102
+                      0,
103
+                      {'fScope': {'fFileSetName': u'All Source Files',
104
+                                  'fLocation': None,
105
+                                  'fRecursive': True,
106
+                                  'fType': 'project-files'},
107
+                       'fSearchSpec': {'fEndPos': None,
108
+                                       'fIncludeLinenos': True,
109
+                                       'fInterpretBackslashes': False,
110
+                                       'fMatchCase': False,
111
+                                       'fOmitBinary': True,
112
+                                       'fRegexFlags': 46,
113
+                                       'fReplaceText': u'',
114
+                                       'fReverse': False,
115
+                                       'fSearchText': u'headers',
116
+                                       'fStartPos': 0,
117
+                                       'fStyle': 'text',
118
+                                       'fWholeWords': False,
119
+                                       'fWrap': True},
120
+                       'fUIOptions': {'fAutoBackground': True,
121
+                                      'fFilePrefix': 'short-file',
122
+                                      'fFindAfterReplace': True,
123
+                                      'fInSelection': False,
124
+                                      'fIncremental': True,
125
+                                      'fReplaceOnDisk': False,
126
+                                      'fShowFirstMatch': False,
127
+                                      'fShowLineno': True,
128
+                                      'fShowReplaceWidgets': False},
129
+                       'replace-entry-expanded': False,
130
+                       'search-entry-expanded': False}),
131
+                     ('debug-data',
132
+                      'wide',
133
+                      0,
134
+                      {}),
135
+                     ('debug-exceptions',
136
+                      'wide',
137
+                      0,
138
+                      {}),
139
+                     ('debug-breakpoints',
140
+                      'wide',
141
+                      0,
142
+                      {}),
143
+                     ('testing',
144
+                      'wide',
145
+                      0,
146
+                      {}),
147
+                     ('debug-io',
148
+                      'wide',
149
+                      1,
150
+                      {}),
151
+                     ('debug-probe',
152
+                      'wide',
153
+                      2,
154
+                      {'active-range': (None,
155
+        -1,
156
+        -1),
157
+                       'attrib-starts': [],
158
+                       'first-line': 1125,
159
+                       'folded-linenos': [],
160
+                       'history': {u'file:C:/Data/Programming/enigma2/GetPicons/get_picons.py': ['i'\
161
+        'con_url\n',
162
+        '  http://www.lyngsat.com/logo/tv/vv/viasat_history.png\n',
163
+        'print url\n',
164
+        'data\n',
165
+        'print icon_url\n',
166
+        'url_package\n'],
167
+                                   u'file:C:/Data/Programming/enigma2/PlayStream2/ContentSources.py': ["r"\
168
+        "2.find('itemprop=\"name\"')\n",
169
+        'print r2\n',
170
+        'ex\n',
171
+        'print headers\n',
172
+        'url\n',
173
+        'print r\n',
174
+        'print js\n',
175
+        'print path\n',
176
+        'data\n',
177
+        "s=re.search(\"titlePlayer = '([^']+)'\", r, re.DOTALL).group(1)\n",
178
+        's.decode("utf8")\n',
179
+        's.decode("cp1251")\n',
180
+        'h.unescape(s.decode("cp1251"))\n',
181
+        'h.unescape("&#252;")\n',
182
+        'HTMLParser.HTMLParser().unescape(u"&#252;")\n',
183
+        'HTMLParser.HTMLParser().unescape(s)\n',
184
+        'import re\n',
185
+        're.sub("&#\\d;","aaa",s)\n',
186
+        're.sub("&#\\w+;","aaa",s)\n',
187
+        're.sub("&#\\w+;","#\\1#",s)\n',
188
+        '2=re.sub("&#\\w+;",HTMLParser.HTMLParser().unescape("\\1"),s)\n',
189
+        's2=re.sub("&#\\w+;",HTMLParser.HTMLParser().unescape("\\1"),s)\n',
190
+        's2\n',
191
+        'print s2\n',
192
+        'print s2.decode("utf8")\n',
193
+        'print s2.decode("cp1252")\n',
194
+        'print s2.decode("cp1251")\n',
195
+        'print s2.decode("cp1257")\n',
196
+        'title\n',
197
+        'HTMLParser.HTMLParser().unescape(&#252;)\n\n\n""\n"\n',
198
+        'HTMLParser.HTMLParser().unescape("&#252;")\n',
199
+        'HTMLParser.HTMLParser().unescape("&#252;")re.sub("&#\\w+;",HTMLPars'\
200
+        'er.HTMLParser().unescape("\\1").enode("utf8"),s)\n',
201
+        're.sub("&#\\w+;",HTMLParser.HTMLParser().unescape("\\1").enode("utf'\
202
+        '8"),s)\n',
203
+        're.sub("&#\\w+;",HTMLParser.HTMLParser().unescape("\\1"),s)\n',
204
+        's\n'],
205
+                                   u'file:C:/Data/Programming/enigma2/PlayStream2/viaplay/vialib.py': ['p'\
206
+        'rint req.content\n']},
207
+                       'launch-id': None,
208
+                       'sel-line': 1130,
209
+                       'sel-line-start': 99702,
210
+                       'selection_end': 99747,
211
+                       'selection_start': 99704}),
212
+                     ('debug-watch',
213
+                      'wide',
214
+                      1,
215
+                      {'node-states': [('eval',
216
+        u'item'),
217
+                                       ('eval',
218
+        u'data'),
219
+                                       ('eval',
220
+        u'r2'),
221
+                                       ('eval',
222
+        u'streams')],
223
+                       'tree-state': {'expanded-nodes': [],
224
+                                      'selected-nodes': [(1,)],
225
+                                      'top-node': (0,)}}),
226
+                     ('debug-modules',
227
+                      'wide',
228
+                      1,
229
+                      {}),
230
+                     ('python-shell',
231
+                      'wide',
232
+                      2,
233
+                      {'active-range': (None,
234
+        -1,
235
+        -1),
236
+                       'attrib-starts': [],
237
+                       'first-line': 0,
238
+                       'folded-linenos': [],
239
+                       'history': {},
240
+                       'launch-id': None,
241
+                       'sel-line': 2,
242
+                       'sel-line-start': 146,
243
+                       'selection_end': 146,
244
+                       'selection_start': 146}),
245
+                     ('bookmarks',
246
+                      'wide',
247
+                      1,
248
+                      {}),
249
+                     ('messages',
250
+                      'wide',
251
+                      2,
252
+                      {}),
253
+                     ('os-command',
254
+                      'wide',
255
+                      1,
256
+                      {})],
257
+        'primary_view_state': {'editor_states': ({'bookmarks': ([[loc('get_picons.py'),
258
+        {'attrib-starts': [('DBServices',
259
+                            251),
260
+                           ('DBServices._load_services',
261
+                            286)],
262
+         'first-line': 279,
263
+         'folded-linenos': [],
264
+         'sel-line': 302,
265
+         'sel-line-start': 11889,
266
+         'selection_end': 11992,
267
+         'selection_start': 11985},
268
+        1477834935.091],
269
+        [loc('get_picons.py'),
270
+         {'attrib-starts': [('DBServices',
271
+                             251),
272
+                            ('DBServices._load_bouquets',
273
+                             381)],
274
+          'first-line': 359,
275
+          'folded-linenos': [],
276
+          'sel-line': 382,
277
+          'sel-line-start': 14693,
278
+          'selection_end': 14798,
279
+          'selection_start': 14791},
280
+         1477834944.262],
281
+        [loc('../../../../Python27/Lib/urllib2.py'),
282
+         {'attrib-starts': [('HTTPDefaultErrorHandler',
283
+                             555),
284
+                            ('HTTPDefaultErrorHandler.http_error_default',
285
+                             556)],
286
+          'first-line': 552,
287
+          'folded-linenos': [],
288
+          'sel-line': 557,
289
+          'sel-line-start': 18972,
290
+          'selection_end': 18972,
291
+          'selection_start': 18972},
292
+         1477834953.465],
293
+        [loc('get_picons.py'),
294
+         {'attrib-starts': [],
295
+          'first-line': 0,
296
+          'folded-linenos': [],
297
+          'sel-line': 15,
298
+          'sel-line-start': 709,
299
+          'selection_end': 837,
300
+          'selection_start': 733},
301
+         1477835348.547],
302
+        [loc('get_picons.py'),
303
+         {'attrib-starts': [],
304
+          'first-line': 0,
305
+          'folded-linenos': [],
306
+          'sel-line': 17,
307
+          'sel-line-start': 936,
308
+          'selection_end': 999,
309
+          'selection_start': 996},
310
+         1477835350.435],
311
+        [loc('get_picons.py'),
312
+         {'attrib-starts': [],
313
+          'first-line': 13,
314
+          'folded-linenos': [],
315
+          'sel-line': 27,
316
+          'sel-line-start': 1425,
317
+          'selection_end': 1440,
318
+          'selection_start': 1433},
319
+         1477835351.336],
320
+        [loc('get_picons.py'),
321
+         {'attrib-starts': [],
322
+          'first-line': 0,
323
+          'folded-linenos': [],
324
+          'sel-line': 27,
325
+          'sel-line-start': 1425,
326
+          'selection_end': 1425,
327
+          'selection_start': 1425},
328
+         1477835375.066],
329
+        [loc('get_picons.py'),
330
+         {'attrib-starts': [],
331
+          'first-line': 13,
332
+          'folded-linenos': [],
333
+          'sel-line': 27,
334
+          'sel-line-start': 1425,
335
+          'selection_end': 1439,
336
+          'selection_start': 1432},
337
+         1477835376.016],
338
+        [loc('get_picons.py'),
339
+         {'attrib-starts': [('main',
340
+                             57)],
341
+          'first-line': 76,
342
+          'folded-linenos': [],
343
+          'sel-line': 99,
344
+          'sel-line-start': 3975,
345
+          'selection_end': 3998,
346
+          'selection_start': 3991},
347
+         1477835381.829],
348
+        [loc('get_picons.py'),
349
+         {'attrib-starts': [('create_picons',
350
+                             109)],
351
+          'first-line': 96,
352
+          'folded-linenos': [],
353
+          'sel-line': 113,
354
+          'sel-line-start': 4460,
355
+          'selection_end': 4481,
356
+          'selection_start': 4481},
357
+         1477835443.285],
358
+        [loc('get_picons.py'),
359
+         {'attrib-starts': [('create_picons',
360
+                             109)],
361
+          'first-line': 96,
362
+          'folded-linenos': [],
363
+          'sel-line': 119,
364
+          'sel-line-start': 4611,
365
+          'selection_end': 4641,
366
+          'selection_start': 4634},
367
+         1477835443.785],
368
+        [loc('get_picons.py'),
369
+         {'attrib-starts': [('create_picons',
370
+                             109)],
371
+          'first-line': 168,
372
+          'folded-linenos': [],
373
+          'sel-line': 188,
374
+          'sel-line-start': 7664,
375
+          'selection_end': 7688,
376
+          'selection_start': 7688},
377
+         1477835499.137],
378
+        [loc('get_picons.py'),
379
+         {'attrib-starts': [('create_picons',
380
+                             109)],
381
+          'first-line': 168,
382
+          'folded-linenos': [],
383
+          'sel-line': 191,
384
+          'sel-line-start': 7708,
385
+          'selection_end': 7753,
386
+          'selection_start': 7746},
387
+         1477835501.356],
388
+        [loc('get_picons.py'),
389
+         {'attrib-starts': [('get_soup',
390
+                             233)],
391
+          'first-line': 217,
392
+          'folded-linenos': [],
393
+          'sel-line': 240,
394
+          'sel-line-start': 9684,
395
+          'selection_end': 9715,
396
+          'selection_start': 9700},
397
+         1477835556.15],
398
+        [loc('get_picons.py'),
399
+         {'attrib-starts': [('DBServices',
400
+                             257),
401
+                            ('DBServices._load_services',
402
+                             292)],
403
+          'first-line': 285,
404
+          'folded-linenos': [],
405
+          'sel-line': 308,
406
+          'sel-line-start': 12046,
407
+          'selection_end': 12157,
408
+          'selection_start': 12142},
409
+         1477835565.274],
410
+        [loc('get_picons.py'),
411
+         {'attrib-starts': [('DBServices',
412
+                             257),
413
+                            ('DBServices._load_bouquets',
414
+                             387)],
415
+          'first-line': 365,
416
+          'folded-linenos': [],
417
+          'sel-line': 388,
418
+          'sel-line-start': 14850,
419
+          'selection_end': 14963,
420
+          'selection_start': 14948},
421
+         1477835568.181],
422
+        [loc('get_picons.py'),
423
+         {'attrib-starts': [('get_packages',
424
+                             209)],
425
+          'first-line': 198,
426
+          'folded-linenos': [],
427
+          'sel-line': 221,
428
+          'sel-line-start': 8810,
429
+          'selection_end': 8810,
430
+          'selection_start': 8810},
431
+         1477835615.894],
432
+        [loc('get_picons.py'),
433
+         {'attrib-starts': [('get_soup',
434
+                             233)],
435
+          'first-line': 229,
436
+          'folded-linenos': [],
437
+          'sel-line': 234,
438
+          'sel-line-start': 9472,
439
+          'selection_end': 9472,
440
+          'selection_start': 9472},
441
+         1477835701.102],
442
+        [loc('../../../../Python27/Lib/site-packages/PIL/Image.py'),
443
+         {'attrib-starts': [('open',
444
+                             2240)],
445
+          'first-line': 2285,
446
+          'folded-linenos': [],
447
+          'sel-line': 2308,
448
+          'sel-line-start': 76151,
449
+          'selection_end': 76151,
450
+          'selection_start': 76151},
451
+         1477835713.764],
452
+        [loc('get_picons.py'),
453
+         {'attrib-starts': [],
454
+          'first-line': 517,
455
+          'folded-linenos': [],
456
+          'sel-line': 540,
457
+          'sel-line-start': 19568,
458
+          'selection_end': 19575,
459
+          'selection_start': 19568},
460
+         1477849965.895]],
461
+        20),
462
+        'current-loc': loc('get_picons.py'),
463
+        'editor-state-list': [(loc('get_picons.py'),
464
+                               {'attrib-starts': [('create_picons',
465
+        109)],
466
+                                'first-line': 0,
467
+                                'folded-linenos': [],
468
+                                'sel-line': 193,
469
+                                'sel-line-start': 7819,
470
+                                'selection_end': 7819,
471
+                                'selection_start': 7819}),
472
+                              (loc('plugin.py'),
473
+                               {'attrib-starts': [('MainScreen',
474
+        16),
475
+        ('MainScreen.about',
476
+         86)],
477
+                                'first-line': 81,
478
+                                'folded-linenos': [],
479
+                                'sel-line': 96,
480
+                                'sel-line-start': 5152,
481
+                                'selection_end': 5173,
482
+                                'selection_start': 5173}),
483
+                              (loc('../../../../Python27/Lib/site-packages/PIL/Image.py'),
484
+                               {'attrib-starts': [('open',
485
+        2240)],
486
+                                'first-line': 2285,
487
+                                'folded-linenos': [],
488
+                                'sel-line': 2308,
489
+                                'sel-line-start': 76151,
490
+                                'selection_end': 76151,
491
+                                'selection_start': 76151})],
492
+        'has-focus': True,
493
+        'locked': False},
494
+        [loc('get_picons.py'),
495
+         loc('plugin.py'),
496
+         loc('../../../../Python27/Lib/site-packages/PIL/Image.py')]),
497
+                               'open_files': [u'plugin.py',
498
+        u'get_picons.py']},
499
+        'saved_notebook_display': None,
500
+        'split_percents': {0: 0.5},
501
+        'splits': 2,
502
+        'tab_location': 'top',
503
+        'user_data': {}},
504
+                 'saved_notebook_display': None,
505
+                 'split_percents': {0: 0.5},
506
+                 'splits': 2,
507
+                 'tab_location': 'left',
508
+                 'user_data': {}},
509
+        'window-alloc': (106,
510
+                         -12,
511
+                         2418,
512
+                         1374)}]}
513
+guimgr.recent-documents = [loc('get_picons.py'),
514
+                           loc('../../../../Python27/Lib/site-packages/PIL/Image.py'),
515
+                           loc('plugin.py')]
516
+proj.build-cmd = {None: ('default',
517
+                         None)}
518
+proj.env-vars = {None: ('default',
519
+                        [u''])}
520
+proj.pypath = {None: ('custom',
521
+                      u'c:\\Data\\Programming\\enigma2\\python;')}
522
+search.search-history = [u'headers',
523
+                         u'urllib2.urlopen',
524
+                         u'urllib2',
525
+                         u'url_icon',
526
+                         u'url_ic',
527
+                         u'about',
528
+                         u'config.plugins.getpicons',
529
+                         u'getconfig',
530
+                         u'size',
531
+                         u'print ',
532
+                         u'starting',
533
+                         u'Downloading and looking',
534
+                         u'Downloading and looking htt',
535
+                         u'overwrite',
536
+                         u'fname',
537
+                         u'fnmae',
538
+                         u'write',
539
+                         u'options',
540
+                         u'piconHD',
541
+                         u'piconhd']
542
+testing.stored-results = (1,
543
+                          [],
544
+                          {})

+ 76
- 0
imake.bat View File

@@ -0,0 +1,76 @@
1
+@echo off
2
+:=== Parameters ===
3
+set ver=0.4
4
+set prog=GetPicons
5
+set pack_name=enigma2-plugin-extensions-getpicons
6
+set pack_prefix=enigma2-plugin-extensions-
7
+set desc=Download/create channels picons from lyngsat.com
8
+
9
+set ext_dir=usr\lib\enigma2\python\Plugins\Extensions\
10
+set script_dir=usr\script\
11
+set ipk_dir=ipkg\
12
+set release_dir=release\
13
+
14
+set AR=\MinGW\bin\ar.exe
15
+set TAR=\MinGW\msys\1.0\bin\tar.exe
16
+
17
+:=== data files
18
+if exist %ipk_dir% rm -r -f %ipk_dir%
19
+mkdir %ipk_dir%
20
+for %%f in (readme.txt,__init__.py,plugin.py,get_picons.py) do xcopy /q  /y %%f %ipk_dir%data\%ext_dir%%prog%\
21
+for %%f in (get_picons.sh ) do xcopy  /q /y %%f %ipk_dir%data\%script_dir%
22
+
23
+:=== control file ===
24
+mkdir %ipk_dir%CONTROL\
25
+rem xcopy  /v /d /y control %ipk_dir%CONTROL\
26
+echo 2.0 >%ipk_dir%debian-binary
27
+(
28
+echo Version: %ver%
29
+echo Package: %pack_name%
30
+echo Description: %desc%
31
+echo Architecture: all
32
+echo Section: 
33
+echo Priority: optional
34
+echo Maintainer: ivars777@gmail.com
35
+echo Homepage: 
36
+echo Depends: python-xml python-imaging requests
37
+echo Source:
38
+) >%ipk_dir%CONTROL\control
39
+dos2unix %ipk_dir%CONTROL\control
40
+
41
+:=== preinst file ===
42
+(
43
+echo #!/bin/sh
44
+echo if [ -d %ext_dir%%prog% ]; then
45
+echo   rm -rf %ext_dir%%prog% ^> /dev/null 2^>^&1
46
+echo fi
47
+echo if [ -e %script_dir%get_picons.sh ]; then
48
+echo   rm %script_dir%get_picons.sh ^> /dev/null 2^>^&1
49
+echo fi
50
+echo exit 0
51
+) >%ipk_dir%CONTROL\preinst
52
+dos2unix %ipk_dir%CONTROL\preinst
53
+
54
+:=== postrm file ===
55
+(
56
+echo #!/bin/sh
57
+echo if [ -d %ext_dir%%prog% ]; then
58
+echo   rm -rf %ext_dir%%prog% ^> /dev/null 2^>^&1
59
+echo fi
60
+echo if [ -e %script_dir%get_picons.sh ]; then
61
+echo   rm %script_dir%get_picons.sh ^> /dev/null 2^>^&1
62
+echo fi
63
+echo exit 0
64
+) >%ipk_dir%CONTROL\postrm
65
+dos2unix %ipk_dir%CONTROL\postrm
66
+
67
+:=== create ipk file ===
68
+if not exist %release_dir% mkdir %release_dir%
69
+%TAR% -C ipkg\data --mode=777 -czf ipkg\data.tar.gz .
70
+%TAR% -C ipkg\CONTROL --mode=777 -czf ipkg\control.tar.gz .
71
+if exist %release_dir%%pack_name%_%ver%.ipk del %release_dir%%pack_name%_%ver%.ipk
72
+%AR% -r %release_dir%%pack_name%_%ver% ipkg\debian-binary ipkg\data.tar.gz ipkg\control.tar.gz
73
+@echo on
74
+mv %release_dir%%pack_name%_%ver% %release_dir%%pack_name%_%ver%.ipk
75
+
76
+

+ 195
- 0
plugin.py View File

@@ -0,0 +1,195 @@
1
+#
2
+# This file is part of GetPicons - enigma2 plugin to download picons from lyngsat.com
3
+# Copyright (c) 2016 ivars777 (ivars777@gmail.com)
4
+# Distributed under the GNU GPL v3. For full terms see http://www.gnu.org/licenses/gpl-3.0.en.html
5
+
6
+from Screens.Screen import Screen
7
+from Screens.Console import Console
8
+from Components.MenuList import MenuList
9
+from Components.Sources.StaticText import StaticText
10
+from Components.Button import Button
11
+from Components.ActionMap import ActionMap
12
+from Screens.MessageBox import MessageBox
13
+from Plugins.Plugin import PluginDescriptor
14
+import os,os.path
15
+
16
+###########################################################################
17
+class MainScreen(Screen):
18
+    skin = """
19
+<screen position="center,center" size="560,400" title="GetPicons" >
20
+	<widget name="content" position="10,40" size="540,350" scrollbarMode="showOnDemand" />
21
+
22
+	<ePixmap name="red"    position="0,0"   zPosition="2" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
23
+	<ePixmap name="green"  position="140,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
24
+	<ePixmap name="yellow" position="280,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
25
+	<ePixmap name="blue"   position="420,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
26
+	<widget name="key_red" position="0,0" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
27
+	<widget name="key_green" position="140,0" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
28
+	<widget name="key_yellow" position="280,0" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
29
+	<widget name="key_blue" position="420,0" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
30
+</screen>"""
31
+
32
+    def __init__(self, session, args = 0):
33
+        self.session = session
34
+        menu_list = [("Download picons for all satellites","all")]
35
+        for line in open("/etc/enigma2/settings"):
36
+            if not "config.Nims.0.advanced.sat." in line: continue
37
+            s = line.strip().split(".")
38
+            sat_num = int(s[5])
39
+            if sat_num>1800: sat_num = sat_num - 3600
40
+            sat_pos = "%s.%s%s"%(abs(sat_num)/10,abs(sat_num)%10,"E" if sat_num>0 else "W")
41
+            menu_list.append( ("Download for %s (%s)"%(sat_pos,s[6]), sat_num) )
42
+        menu_list.append(("Exit","exit"))
43
+
44
+        Screen.__init__(self, session)
45
+        self["content"] = MenuList(menu_list)
46
+        self["key_red"] = Button("Exit")
47
+        self["key_green"] = Button("Select")
48
+        self["key_yellow"] = Button("Options")
49
+        self["key_blue"] = Button("About")
50
+        self["action_map"] = ActionMap(["OkCancelActions", "ColorActions"],
51
+                                       {
52
+                                           "ok": self.go,
53
+                                           "cancel": self.cancel,
54
+                                           "green":self.go,
55
+                                           "red":self.cancel,
56
+                                           "yellow":self.options,
57
+                                           "blue":self.about
58
+                                           }, -1)
59
+
60
+    def go(self):
61
+        item = self["content"].l.getCurrentSelection()[1]
62
+
63
+        if item == "exit":
64
+            self.close(None)
65
+        else:
66
+            print "picon folder = %s size = %s overwrite=%s"%(config.plugins.getpicons.folder.value,config.plugins.getpicons.folder.value,config.plugins.getpicons.overwrite.value)
67
+            param = ""
68
+            param += " -s %s"%(item) if item <> "all" 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 ""
71
+            cur_directory = os.path.dirname(os.path.realpath(__file__))
72
+            name = os.path.join(cur_directory,"get_picons.py")
73
+            cmd = "python -u %s -f %s %s"%(name,config.plugins.getpicons.folder.value,param,)
74
+            #print "[GetPicons] Execute '%s'"%cmd
75
+            #os.chmod(name, 493)
76
+            if config.plugins.getpicons.folder.value:
77
+                self.session.open(Console, "Download picons from lyngsat.com", cmdlist=[cmd])
78
+
79
+    def cancel(self):
80
+        print "\n[GetPicons] cancel\n"
81
+        self.close(None)
82
+
83
+    def options(self):
84
+        print "\n[GetPicons] options\n"
85
+        self.session.open(ConfigScreen)
86
+
87
+    def about(self):
88
+        txt = """
89
+GetPicons plugin
90
+
91
+Download channels picon files from lyngsat.com for all/selected satellites
92
+
93
+Could be run from terminal too:
94
+/usr/script/get_picons.sh -h
95
+
96
+Version 0.3
97
+(c) 2013-2016 ivars777@gmail.com"""
98
+        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)
100
+        return
101
+
102
+
103
+##########################################################################
104
+from Components.config import config, ConfigSubsection, \
105
+     ConfigYesNo, getConfigListEntry, \
106
+     ConfigSelection, ConfigNumber, ConfigDirectory,ConfigText
107
+from Components.ConfigList import ConfigListScreen
108
+from Screens.LocationBox import LocationBox
109
+
110
+config.plugins.getpicons = ConfigSubsection()
111
+config.plugins.getpicons.folder = ConfigDirectory(default="/media/hdd")
112
+config.plugins.getpicons.size = ConfigSelection({"400x240":"400x240","220x132":"220x132","100x60":"100x60"}, default="220x132")
113
+config.plugins.getpicons.overwrite = ConfigYesNo(default = True)
114
+
115
+class ConfigScreen(ConfigListScreen,Screen):
116
+    skin = """
117
+<screen position="center,center" size="560,400" title="Options" >
118
+	<ePixmap name="red"    position="0,0"   zPosition="2" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
119
+	<ePixmap name="green"  position="140,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
120
+	<ePixmap name="yellow" position="280,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
121
+	<ePixmap name="blue"   position="420,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
122
+
123
+	<widget name="key_red" position="0,0" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
124
+	<widget name="key_green" position="140,0" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
125
+	<widget name="key_yellow" position="280,0" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
126
+	<widget name="key_blue" position="420,0" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
127
+
128
+	<widget name="config" position="10,40" size="540,340" scrollbarMode="showOnDemand" />
129
+</screen>"""
130
+
131
+    def __init__(self, session, args = 0):
132
+        self.session = session
133
+        self.setup_title = "Options"
134
+        Screen.__init__(self, session)
135
+        cfg = config.plugins.getpicons
136
+        self.list = [
137
+            getConfigListEntry(_("Picons folder"), cfg.folder),
138
+            getConfigListEntry(_("Picon size"), cfg.size),
139
+            getConfigListEntry(_("Overwrite existing picon files"), cfg.overwrite),
140
+        ]
141
+        ConfigListScreen.__init__(self, self.list, session = self.session)
142
+        self["key_red"] = Button(_("Cancel"))
143
+        self["key_green"] = Button(_("Save"))
144
+        self["key_yellow"] = Button("")
145
+        self["key_blue"] = Button("")
146
+        self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
147
+                                         {
148
+                                             "red": self.cancel,
149
+                                             "green": self.save,
150
+                                             "save": self.save,
151
+                                             "cancel": self.cancel,
152
+                                             "ok": self.ok,
153
+                                             }, -2)
154
+
155
+    def getCurrentEntry(self):
156
+        return self["config"].getCurrent()[0]
157
+    
158
+    def getCurrentValue(self):
159
+        return str(self["config"].getCurrent()[1].getText())
160
+
161
+    def ok(self):
162
+        if self["config"].getCurrent()[1] == config.plugins.getpicons.folder:
163
+            folder  = config.plugins.getpicons.folder.value
164
+            self.session.openWithCallback(self.change_dir, LocationBox,"Select Folder")
165
+        else:
166
+            self.save()
167
+
168
+    def change_dir(self, folder, select=None):
169
+        if folder:
170
+            #print "change_dir to %s"%folder
171
+            config.plugins.getpicons.folder.value = folder
172
+
173
+    def save(self):
174
+        print "saving"
175
+        self.saveAll()
176
+        self.close(True,self.session)
177
+
178
+    def cancel(self):
179
+        #print "cancel"
180
+        self.close(False,self.session)
181
+
182
+
183
+###########################################################################
184
+def start(session, **kwargs):
185
+    print "\n[GetPicons] start\n"
186
+    session.open(MainScreen)
187
+    #session.openWithCallback(done_config, Config)
188
+
189
+def Plugins(**kwargs):
190
+    return PluginDescriptor(
191
+        name="Get Picons",
192
+        description="Download picons from lyngsat.com",
193
+        where = [PluginDescriptor.WHERE_PLUGINMENU,PluginDescriptor.WHERE_EXTENSIONSMENU],
194
+        icon="plugin.png",
195
+        fnc=start)

+ 7
- 0
readme.txt View File

@@ -0,0 +1,7 @@
1
+=== GetSatellitesXML ===
2
+Enigma2 plugin to dowload and create channels picons files form lyngsat.com
3
+
4
+Version 0.2
5
+Copyright (c) 2015-2016 ivars777 (ivars777@gmail.com)
6
+Distributed under the GNU GPL v3. For full terms see http://www.gnu.org/licenses/gpl-3.0.en.html
7
+