from imports import *
from about import *
from StringIO import StringIO
import gzip
PLUGIN_PATH = '/usr/lib/enigma2/python/Plugins/Extensions/Albatros'
cj = {}

class m2list(MenuList):

    def __init__(self, list):
        MenuList.__init__(self, list, False, eListboxPythonMultiContent)
        self.l.setFont(0, gFont('Regular', 14))
        self.l.setFont(1, gFont('Regular', 16))
        self.l.setFont(2, gFont('Regular', 18))
        self.l.setFont(3, gFont('Regular', 20))
        self.l.setFont(4, gFont('Regular', 22))
        self.l.setFont(5, gFont('Regular', 24))
        self.l.setFont(6, gFont('Regular', 26))
        self.l.setFont(7, gFont('Regular', 28))
        self.l.setFont(8, gFont('Regular', 32))


def show_(name, link, image,index):
    res = [(name, link, image,index)]
    res.append(MultiContentEntryText(pos=(0, 0), size=(800, 40), font=6, text=name, flags=RT_HALIGN_CENTER | RT_VALIGN_CENTER))
    return res


def episodes_(name, link, image, info):
    res = [(name,
      link,
      image,
      info)]
    res.append(MultiContentEntryText(pos=(0, 0), size=(800, 40), font=8, text=name, flags=RT_HALIGN_CENTER | RT_VALIGN_CENTER))
    return res


def cat_(letter, link):
    res = [(letter, link)]
    res.append(MultiContentEntryText(pos=(0, 0), size=(800, 40), font=8, text=letter, flags=RT_HALIGN_CENTER | RT_VALIGN_CENTER))
    return res


class elitehd(Screen):

    def __init__(self, session):
        self.session = session
        sz_w = getDesktop(0).size().width()
        if sz_w == 1920:
            if config.Albatros.skin.value=='1':
                path = "/usr/lib/enigma2/python/Plugins/Extensions/Albatros/skin/defaultListScreen_new.xml"
            elif config.Albatros.skin.value=='2':
                path = "/usr/lib/enigma2/python/Plugins/Extensions/Albatros/skin2/defaultListScreen_new.xml"
            elif config.Albatros.skin.value=='3':
                path = "/usr/lib/enigma2/python/Plugins/Extensions/Albatros/skin3/defaultListScreen_new.xml"
        else:
            if config.Albatros.skin.value=='1':
                path = "/usr/lib/enigma2/python/Plugins/Extensions/Albatros/skin/defaultListScreen.xml"
            elif config.Albatros.skin.value=='2':
                path = "/usr/lib/enigma2/python/Plugins/Extensions/Albatros/skin2/defaultListScreen.xml"
            elif config.Albatros.skin.value=='3':
                path = "/usr/lib/enigma2/python/Plugins/Extensions/Albatros/skin3/defaultListScreen.xml"
        with open(path, "r") as f:
            self.skin = f.read()
            f.close()
        Screen.__init__(self, session)
        self['actions'] = ActionMap(['OkCancelActions',
         'ColorActions',
         'DirectionActions',
         'MovieSelectionActions'], {'up': self.up,
         'down': self.down,
         'left': self.left,
         'right': self.right,
         'ok': self.ok,
         'cancel': self.exit,
         'red': self.exit,
         'blue': self.dnitnow}, -1)
        self['menulist'] = m2list([])
        self['red'] = Label(_('Exit'))
        self['green'] = Label('')
        self['yellow'] = Label(_('About'))
        self['blue'] = Label('')
        self['Menu'] = Label('')
        self['text'] = Label('')
        self['name'] = Label(' ')
        self['poster'] = Pixmap()
        self['title'] = Label('showsports')
        self.dnfile = 'False'
        self.currentList = 'menulist'
        self.menulist = []
        self.loading_ok = False
        self.check = 'abc'
        self.count = 0
        self.loading = 0
        self.dir()
        global old_ref
        old_ref=self.session.nav.getCurrentlyPlayingServiceReference()
        self.onLayoutFinish.append(self.list_cat)

    def about(self):
        self.session.open(AboutScreen)

    def dnitnow(self):
        if JobManagerInstalled and self.check == 'letter_movie':
            self.dnfile = 'True'
            link = self['menulist'].getCurrent()[0][1]
            self.filmname = self['menulist'].getCurrent()[0][0]

    def up(self):
        self[self.currentList].up()
        auswahl = self['menulist'].getCurrent()[0][0]
        self['name'].setText(auswahl)
        if self.info == 'list_shows':
            try:
                self.load_poster()
            except:
                print 'error loading poster'
        elif self.info == 'list_channels' or self.info == 'list_live':
            try:
                self.load_poster()
            except:
                print 'error loading poster'

    def down(self):
        self[self.currentList].down()
        auswahl = self['menulist'].getCurrent()[0][0]
        self['name'].setText(auswahl)
        if self.info == 'list_shows':
            try:
                self.load_poster()
            except:
                print 'error loading poster'
        elif self.info == 'list_channels' or self.info == 'list_live':
            try:
                self.load_poster()
            except:
                print 'error loading poster'

    def left(self):
        self[self.currentList].pageUp()
        auswahl = self['menulist'].getCurrent()[0][0]
        self['name'].setText(auswahl)
        if self.info == 'list_shows':
            try:
                self.load_poster()
            except:
                print 'error loading poster'
        elif self.info == 'list_channels' or self.info == 'list_live':
            try:
                self.load_poster()
            except:
                print 'error loading poster'


    def right(self):
        self[self.currentList].pageDown()
        auswahl = self['menulist'].getCurrent()[0][0]
        self['name'].setText(auswahl)
        if self.info == 'list_shows':
            try:
                self.load_poster()
            except:
                print 'error loading poster'
        elif self.info == 'list_episodes' or self.info == 'list_live':
            try:
                self.load_poster()
            except:
                print 'error loading poster'


    def list_cat(self):
        self.info = 'list_cat'
        self.cat_list = []
        cat = [('1.Sport'),('2.Tring'),('3.Digialb'),('4.Shqiptare'),('5.Nderkombetare'),('6.TV EST'),('7.Tv Kosovare'),('8.Tv Maqedoni'),('9.Tv Kinema'),('10.Femije')]
        for category in cat:
            self.cat_list.append(show_(category, None, None,None))
        self['menulist'].l.setList(self.cat_list)
        self['menulist'].l.setItemHeight(40)
        self['menulist'].moveToIndex(0)
        auswahl = self['menulist'].getCurrent()[0][0]
        self['name'].setText(auswahl)
        return

    def list_channels(self):
        self.info = 'list_channels'
        self.show_list = []
        self.ch_list = []
        selected = self['menulist'].getCurrent()[0][0]
        if selected =='1.Sport':
            ch_list=[('Tring Sport','http://85.25.218.196:8081/streamrtmp/tringsport/playlist.m3u8','http://www.livep2ptvstream.com/logo/tring_sportnews.jpg'),
            ('Tring Sport 1','http://188.138.1.82:8081/streamrtmp/tringsport1/playlist.m3u8','http://vizionplus.al/wp-content/uploads/2014/09/tring-sport.jpg'),
            ('Tring Sport 1-2','http://85.25.43.14:8081/streamrtmp/tringsport1/playlist.m3u8','http://vizionplus.al/wp-content/uploads/2014/09/tring-sport.jpg'),
            ('Tring Sport 1-3','http://85.25.218.196:8081/streamrtmp/tringsport1/playlist.m3u8','http://vizionplus.al/wp-content/uploads/2014/09/tring-sport.jpg'),
            ('Tring Sport 2-1','http://85.25.218.196:8081/streamrtmp/tringsport2/playlist.m3u8','http://www.lyngsat-logo.com/hires/tt/tring_sport2.png'),
            ('Tring Sport 2-2','http://85.25.43.14:8081/streamrtmp/tringsport2/playlist.m3u8','http://www.lyngsat-logo.com/hires/tt/tring_sport2.png'),
            ('Tring Sport 2-3','http://85.25.218.196:8081/streamrtmp/tringsport2/playlist.m3u8','http://www.lyngsat-logo.com/hires/tt/tring_sport2.png'),
            ('Tring Sport 3','http://85.25.218.196:8081/streamrtmp/tringsport3/playlist.m3u8','http://www.lyngsat-logo.com/hires/tt/tring_sport3.png'),
            ('Tring Sport 3-2','http://188.138.1.82:8081/streamrtmp/tringsport3/playlist.m3u8','http://www.lyngsat-logo.com/hires/tt/tring_sport3.png'),
            ('Tring Sport 3-3','http://188.138.9.87:8081/streamrtmp/tringsport3/playlist.m3u8','http://www.lyngsat-logo.com/hires/tt/tring_sport3.png'),
            ('Super Sport 1','http://85.25.218.196:8081/streamrtmp/ss1/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_supersport1.jpg'),
            ('Super Sport 2','http://188.138.1.82:8081/streamrtmp/ss2/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_supersport2.jpg'),
            ('Super Sport 2-2','http://188.138.9.87:8081/streamrtmp/ss2/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_supersport2.jpg'),
            ('Super Sport 2-3','http://85.25.218.196:8081/streamrtmp/ss2/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_supersport2.jpg'),
            ('Super Sport 3','http://188.138.1.82:8081/streamrtmp/ss3/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_supersport3.jpg'),
            ('Super Sport 3-2','http://85.25.43.14:8081/streamrtmp/ss3/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_supersport3.jpg'),
            ('Super Sport 3-3','http://85.25.218.196:8081/streamrtmp/ss3/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_supersport3.jpg'),
            ('Super Sport 4','http://85.25.43.14:8081/streamrtmp/ss4/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_supersport4.jpg'),]
        if selected =='2.Tring':
            ch_list=[('Tring Tring','http://85.25.218.196:8081/streamrtmp/tringtring/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_tring.jpg'),
            ('Jolly HD','http://188.138.1.82:8081/streamrtmp/jollyhd/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_jolly_hd.jpg'),
            ('Tring Max','http://188.138.1.82:8081/streamrtmp/tringmax/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_max.jpg'),
            ('Tring Super','http://85.25.218.196:8081/streamrtmp/tringsuper/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_super.jpg'),
            ('Tring Fantasy','http://85.25.218.196:8081/streamrtmp/tringfantasy/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_fantasy.jpg'),
            ('Tring Comedy','http://188.138.1.82:8081/streamrtmp/tringcomedy/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_comedy.jpg'),
            ('Tring 3Plus','http://85.25.218.196:8081/streamrtmp/tring3plus/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_3plus.jpg'),
            ('Tring Shqip','http://188.138.1.82:8081/streamrtmp/tringshqip/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_shqip.jpg'),
            ('Tring Planet','http://85.25.218.196:8081/streamrtmp/tringplanet/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_planet.jpg'),
            ('Tring Histori','http://188.138.9.87:8081/streamrtmp/tringhistori/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_history.jpg'),]
        if selected =='3.Digialb':
            ch_list=[('PLUS HD','http://85.25.43.14:8081/streamrtmp/plushd/playlist.m3u8','http://www.sat-address.com/f/pics/logotipi/Plus-HD-DigitAlb_o.jpg'),
            ('Stinet','http://85.25.218.196:8081/streamrtmp/stinet/playlist.m3u8','http://www.satlogo.com/logo/tv/dd/digit_alb_serial_stinet.png'),
            ('T HD','http://85.25.43.14:8081/streamrtmp/thd/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_t.jpg'),
            ('Film Autor','http://85.25.218.196:8081/streamrtmp/filmautor/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_autor.jpg'),
            ('Film Aksion','http://85.25.218.196:8081/streamrtmp/aksion/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_aksion.jpg'),
            ('Film Hits + 1','http://85.25.218.196:8081/streamrtmp/hits+/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_hits_plus1.jpg'),
            ('Film Komedi','http://85.25.218.196:8081/streamrtmp/komedi/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_komedi.jpg'),
            ('Film 1 HD','http://188.138.1.82:8081/streamrtmp/film1hd/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_hd1.jpg'),
            ('Film 2 HD','http://188.138.1.82:8081/streamrtmp/filmhd2/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_hd2.jpg'),
            ('Junior TV','http://85.25.218.196:8081/streamrtmp/junior/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_junior_tv.jpg'),
            ('Beng Beng','http://188.138.1.82:8081/streamrtmp/BengBeng/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/bang_bang.jpg'),
            ('Cufo TV','http://188.138.1.82:8081/streamrtmp/cufo/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/cufo_tv.jpg'),
            ('Explorer Natyre','http://85.25.218.196:8081/streamrtmp/expnatyre/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_explorer_natyra.jpg'),
            ('Explorer Shkence','http://85.25.218.196:8081/streamrtmp/expshkence/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_explorer_shkence.jpg'),
            ('Top News','http://188.138.1.82:8081/streamrtmp/topnews/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/top_news.jpg'),
            ('Super Sport 1','http://85.25.218.196:8081/streamrtmp/ss1/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_supersport1.jpg'),
            ('Super Sport 2','http://188.138.1.82:8081/streamrtmp/ss2/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_supersport2.jpg'),
            ('Super Sport 3','http://188.138.1.82:8081/streamrtmp/ss3/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_supersport3.jpg'),
            ('Super Sport 4','http://85.25.43.14:8081/streamrtmp/ss4/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_supersport4.jpg'),]
        if selected =='4.Shqiptare':
            ch_list=[('Tv Klan','http://85.25.43.14:8081/streamrtmp/tvklan/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tv_klan_hd.jpg'),
            ('Top Channel','http://188.138.1.82:8081/streamrtmp/topchannel/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/top_channel.jpg'),
            ('Vizion Plus','http://188.138.9.87:8081/streamrtmp/vizionplus/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/vizion_plus.jpg'),
            ('Alb Film','http://str105mb.setplex.net:1935/str2iosmd5/alb_film/playlist.m3u8','http://i.ytimg.com/vi/dSiq7tNAzYQ/maxresdefault.jpg'),
            ('News 24','http://85.25.218.196:8081/streamrtmp/news24/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/news24_al.jpg'),
            ('Super Sonic','http://str103.setplex.net:1935/228/stv_online/playlist.m3u8','http://oklivetv.com/wp-content/uploads/2015/03/supersonic_tv_al.png'),
            ('STV FOLK','http://str103.setplex.net:1935/228/stv_folk/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/supersonic_tv_folk.jpg'),
            ('A1 Report','rtmp://66.55.93.204/livepkgr/a1stream?adbe-live-event=a1report','http://www.tv-logo.com/pt-data/uploads/images/logo/a1_report_al.jpg'),]
        if selected =='5.Nderkombetare':
            ch_list=[('Rai News','http://85.25.43.14:8081/streamrtmp/rainews/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/rai_news_24.jpg'),
            ('Rai 1','http://85.25.43.14:8081/streamrtmp/rai1/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/rai_1.jpg'),
            ('Rai 2','http://85.25.43.14:8081/streamrtmp/rai2/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/rai_2.jpg'),
            ('RTL DE','http://85.25.43.14:8081/streamrtmp/rtl/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/rtl_ch.jpg'),
            ('RTL2 DE','http://85.25.43.14:8081/streamrtmp/rtl2/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/rtl2_de.jpg'),
            ('Super RTL','http://85.25.43.14:8081/streamrtmp/superrtl/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/super_rtl.jpg'),
            ('Pro7','http://85.25.43.14:8081/streamrtmp/pro7/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/pro_sieben_de.jpg'),]
        if selected =='6.TV EST':
            ch_list=[('Tv Klan EST','http://188.138.9.87:8081/streamrtmp/klanest/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tv_klan_hd.jpg'),
            ('Top Channel EST','http://188.138.9.87:8081/streamrtmp/topchannelest/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/top_channel.jpg'),
            ('Vizion Plus EST','http://188.138.9.87:8081/streamrtmp/vizionest/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/vizion_plus.jpg'),
            ('RTK EST','http://188.138.9.87:8081/streamrtmp/rtkest/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/rtk1.jpg'),
            ('Klan Kosova EST','http://188.138.9.87:8081/streamrtmp/klanksest/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/klan_kosova.jpg'),
            ('KTV EST','http://188.138.9.87:8081/streamrtmp/ktvest/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/koha_vision.jpg'),
            ('RTV EST','http://188.138.9.87:8081/streamrtmp/rtv21est/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/rtv21.jpg'),
            ('Alsat M','http://188.138.9.87:8081/streamrtmp/alsatest/playlist.m3u8','http://3.bp.blogspot.com/-2oNVpLEFO_s/USN3hibqppI/AAAAAAAABvE/M_BL522bgSw/s320/ALSAT+M.png'),]
        if selected =='7.Tv Kosovare':
            ch_list=[('RTK','http://85.25.43.14:8081/streamrtmp/rtk/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/rtk1.jpg'),
            ('Klan Kosova','http://85.25.43.14:8081/streamrtmp/klankosova/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/klan_kosova.jpg'),
            ('KTV','http://31.24.224.77:8081/streamrtmp/ktv/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/koha_vision.jpg'),
            ('KTV','http://188.138.1.82:8081/streamrtmp/ktv/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/koha_vision.jpg'),
            ('RTV 21 PLUS','http://188.138.9.87:8081/streamrtmp/rtv21plus/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/rtv21_plus.jpg'),
            ('RTV21 Popullore','http://188.138.9.87:8081/streamrtmp/rtv21popullore/playlist.m3u8','http://www.smartworldtv.com/repository/images/path/21popullore_438962.png'),
            ('RTV','http://188.138.9.87:8081/streamrtmp/rtv/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/rtv21.jpg'),
            ('Opoja TV','http://109.123.114.178:1935/8000/8000/playlist.m3u8','http://freeiptv.weightlosstoday.org/wp-content/uploads/2015/07/tv-opoja.png'),
            ('Jug TV','http://84.20.77.50:554/live/rtmp.stream/playlist.m3u8','http://shqipal.altervista.org/storage/tv/jugtv.png'),]
        if selected =='8.Tv Maqedoni':
            ch_list=[('RTV 21 MK','http://188.138.9.87:8081/streamrtmp/rtv21mk/playlist.m3u8','http://rtv21.tv/web/wp-content/uploads/2015/09/tv21-maqedoni1-640x580.jpg'),
            ('Alsat M','http://31.24.224.77:8081/streamrtmp/alsatm/playlist.m3u8','http://3.bp.blogspot.com/-2oNVpLEFO_s/USN3hibqppI/AAAAAAAABvE/M_BL522bgSw/s320/ALSAT+M.png'),
            ('Alsat M','http://188.138.1.82:8081/streamrtmp/alsatm/playlist.m3u8','http://3.bp.blogspot.com/-2oNVpLEFO_s/USN3hibqppI/AAAAAAAABvE/M_BL522bgSw/s320/ALSAT+M.png'),
            ('Tv Koha','rtmp://live.tvkoha.tv/live/koha/livestream','http://www.tvkoha.tv/dizajn/logo.jpg'),]
        if selected =='9.Tv Kinema':
            ch_list=[('Film Aksion','http://85.25.218.196:8081/streamrtmp/aksion/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_aksion.jpg'),
            ('Film Autor','http://85.25.218.196:8081/streamrtmp/filmautor/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_autor.jpg'),
            ('Film Hits + 1','http://85.25.218.196:8081/streamrtmp/hits+/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_hits_plus1.jpg'),
            ('Stinet','http://85.25.218.196:8081/streamrtmp/stinet/playlist.m3u8','http://www.satlogo.com/logo/tv/dd/digit_alb_serial_stinet.png'),
            ('Film Komedi','http://85.25.218.196:8081/streamrtmp/komedi/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_komedi.jpg'),
            ('Film 1 HD','http://188.138.1.82:8081/streamrtmp/film1hd/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_hd1.jpg'),
            ('Film 2 HD','http://188.138.1.82:8081/streamrtmp/filmhd2/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_hd2.jpg'),
            ('Junior TV','http://85.25.218.196:8081/streamrtmp/junior/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_junior_tv.jpg'),
            ('Jolly HD','http://188.138.1.82:8081/streamrtmp/jollyhd/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_jolly_hd.jpg'),
            ('Tring Max','http://188.138.1.82:8081/streamrtmp/tringmax/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_max.jpg'),
            ('Tring Super','http://85.25.218.196:8081/streamrtmp/tringsuper/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_super.jpg'),
            ('Tring Fantasy','http://85.25.218.196:8081/streamrtmp/tringfantasy/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_fantasy.jpg'),
            ('Tring Comedy','http://188.138.1.82:8081/streamrtmp/tringcomedy/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_comedy.jpg'),
            ('Tring 3Plus','http://85.25.218.196:8081/streamrtmp/tring3plus/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_3plus.jpg'),
            ('Tring Shqip','http://188.138.1.82:8081/streamrtmp/tringshqip/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_shqip.jpg'),]
        if selected =='10.Femije':
            ch_list=[('Junior TV','http://85.25.218.196:8081/streamrtmp/junior/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/digit_alb_junior_tv.jpg'),
            ('Beng Beng','http://188.138.1.82:8081/streamrtmp/BengBeng/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/bang_bang.jpg'),
            ('Cufo TV','http://188.138.1.82:8081/streamrtmp/cufo/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/cufo_tv.jpg'),
            ('Tring Tring','http://85.25.218.196:8081/streamrtmp/tringtring/playlist.m3u8','http://www.tv-logo.com/pt-data/uploads/images/logo/tring_tring.jpg'),
            ('Alb Kids','http://str105mb.setplex.net:1935/str2iosmd5/alb_kids/playlist.m3u8','https://i.ytimg.com/vi/834iWBnqx0w/hqdefault.jpg'),]

        for each in ch_list:
            title,url,img=each
            self.show_list.append(show_(title, url, img,None))
        self['menulist'].l.setList(self.show_list)
        self['menulist'].l.setItemHeight(40)
        self['menulist'].moveToIndex(0)
        self.load_poster()
        auswahl = self['menulist'].getCurrent()[0][0]
        self['name'].setText(auswahl)
		
    def get_auth(self):
        req = urllib2.Request('http://85.25.43.14/nusoap/generateCodeJSON.php?method=generate&format=json')
        post='password=xh%4068&username=xhilda&'
        resp = urllib2.urlopen(req,data=post)
        body = resp.read()
        print body
        auth=re.findall('"data":"(.*?)"',body)
        if auth:
            print auth[0]
            return auth[0]
		
    def play_movie(self, link):
        self.info='player'
        if link:
            selectedName = self['menulist'].l.getCurrentSelection()[0][0]
            sref = eServiceReference(4097, 0, link)
            sref.setName(selectedName)
            self.session.nav.playService(sref)
            self.hide()

    def ok(self):
        selectedEntry = self['menulist'].l.getCurrentSelection()[0][1]
        selectedName = self['menulist'].l.getCurrentSelection()[0][0]
        selectedIndex= self['menulist'].l.getCurrentSelection()[0][3]
        if self.info == 'list_cat':
            url = str(selectedEntry)
            self.list_channels()
        elif self.info=='list_channels':
            url = str(selectedEntry)
            auth=self.get_auth()
            data='http://127.0.0.1:88/hls://'+url+'?nimblesessionid=309774&'+auth.replace('?','')+' http-headers={"User-Agent":"Iphone/4.1 (Linux;Android 4.2.2) ExoPlayerLib/1.5.2"}'
            print data
            self.play_movie(data)
           

    def exit(self):
        print self.info
        if re.match('(list_cat)', self.info, re.S | re.I):
            if fileExists('/tmp/hayyes_poster.jpg'):
                os.system('rm -r /tmp/hayyes_poster.jpg')
            self.close(self.session, 'exit')
        elif self.info == 'list_channels':
            self.list_cat()
        elif self.info=='player':
            self.show()
            self.session.nav.playService(old_ref)
            self.info='list_channels'
            self['menulist'].l.setList(self.show_list)
            self['menulist'].l.setItemHeight(40)
            self['menulist'].moveToIndex(0)
            self.load_poster()

    def load_poster(self):
        jp_link = self['menulist'].getCurrent()[0][2]
        tmp_image = jpg_store = '/tmp/hayyes_poster.jpg'
        try:
            downloadPage(jp_link, tmp_image).addCallback(self.downloadPic, tmp_image)
        finally:
            print "Error: can't find file or read data"

    def show_cover(self):
        jpg_link = '/usr/lib/enigma2/python/Plugins/Extensions/hayyes/images/'
        jpg_name = 'no_cover.png'
        jpg_store = jpg_link + jpg_name
        if not os.path.exists(jpg_store):
            self.downloadPic(file_name, jpg_store)
        else:
            self.poster_resize(jpg_store)

    def downloadPic(self, data, jpg_store):
        if fileExists(jpg_store):
            self.poster_resize(jpg_store)
        else:
            print '[hayyes] logo not found'

    def poster_resize(self, poster_path):
        self['poster'].instance.setPixmap(None)
        self['poster'].hide()
        sc = AVSwitch().getFramebufferScale()
        self.picload = ePicLoad()
        size = self['poster'].instance.size()
        self.picload.setPara((size.width(),
         size.height(),
         sc[0],
         sc[1],
         False,
         1,
         '#FF000000'))
        if self.picload.startDecode(poster_path, 0, 0, False) == 0:
            ptr = self.picload.getData()
            if ptr != None:
                self['poster'].instance.setPixmap(ptr)
                self['poster'].show()
            else:
                print '[hayyes] no cover.. error'
        return

    def dir(self):
        if not pathExists('/tmp/hayyes/'):
            os.system('mkdir /tmp/hayyes/')
        else:
            print '[hayyes] /tmp/hayyes/ allready present'
			
class unwise:
    def worker(self, str_eval):
        page_value=""
        try:        
            ss="w,i,s,e=("+str_eval+')' 
            exec (ss)
            page_value=self.__unwise(w,i,s,e)
        except: return
        return page_value

    def __unwise(self,  w, i, s, e):
        lIll = 0;
        ll1I = 0;
        Il1l = 0;
        ll1l = [];
        l1lI = [];
        while True:
            if (lIll < 5):
                l1lI.append(w[lIll])
            elif (lIll < len(w)):
                ll1l.append(w[lIll]);
            lIll+=1;
            if (ll1I < 5):
                l1lI.append(i[ll1I])
            elif (ll1I < len(i)):
                ll1l.append(i[ll1I])
            ll1I+=1;
            if (Il1l < 5):
                l1lI.append(s[Il1l])
            elif (Il1l < len(s)):
                ll1l.append(s[Il1l]);
            Il1l+=1;
            if (len(w) + len(i) + len(s) + len(e) == len(ll1l) + len(l1lI) + len(e)):
                break;
            
        lI1l = ''.join(ll1l)
        I1lI = ''.join(l1lI)
        ll1I = 0;
        l1ll = [];
        for lIll in range(0,len(ll1l),2):
            ll11 = -1;
            if ( ord(I1lI[ll1I]) % 2):
                ll11 = 1;
            l1ll.append(chr(    int(lI1l[lIll: lIll+2], 36) - ll11));
            ll1I+=1;
            if (ll1I >= len(l1lI)):
                ll1I = 0;
        ret=''.join(l1ll)
        if 'eval(function(w,i,s,e)' in ret:
            ret=re.compile('eval\(function\(w,i,s,e\).*}\((.*?)\)').findall(ret)[0] 
            return self.worker(ret)
        else:
            return ret