class Host:
    currList = []
    MAIN_URL = ''
    PREMIUM = False
    konto = ''
    COOKIEFILE = ''
    HOST = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110621 Mandriva Linux/1.9.2.18-0.1mdv2010.2 (2010.2) Firefox/3.6.18'

    def __init__(self):
        printDBG('Host __init__ begin')
        self.exSession = MainSessionWrapper()
        self.COOKIEFILE = GetCookieDir('scseriale.cookie')
        self.cm = common()
        self.currList = []
        self.up = urlparser()
        self.history = CSearchHistoryHelper('wspolne')
        printDBG('Host __init__ end')

    def setCurrList(self, list):
        printDBG('Host setCurrList begin')
        self.currList = list
        printDBG('Host setCurrList end')
        return

    def getInitList(self):
        printDBG('Host getInitList begin')
        ####################################
        # logowanie
        ####################################
        self.PREMIUM = self.listsItems(-1, 'zaloguj', 'zaloguj')
        ####################################
        self.currList = self.listsItems(-1, 'main-menu', 'main-menu')
        printDBG('Host getInitList end')
        return self.currList

    def getListForItem(self, Index=0, refresh=0, selItem=None):
        printDBG('Host getListForItem begin')
        valTab = []
        if len(self.currList[Index].urlItems) == 0:
            return valTab
        valTab = self.listsItems(Index, self.currList[Index].urlItems[0],
                                 self.currList[Index].urlSeparateRequest)
        self.currList = valTab
        printDBG('Host getListForItem end')
        return self.currList

    def getSearchResults(self, pattern, searchType=None):
        printDBG("Host getSearchResults begin")
        printDBG("Host getSearchResults pattern: " + pattern)
        valTab = []
        valTab = self.listsItems(-1, pattern, 'search')
        self.currList = valTab
        printDBG("Host getSearchResults end")
        return self.currList

    def listsItems(self, Index, url, name=''):
        printDBG('Host listsItems begin')
        printDBG('Host listsItems url: ' + url)
        valTab = []
        # ########## #
        if name == 'main-menu':
            printDBG('Host listsItems begin name=' + name)
            self.MAIN_URL = 'http://scs.pl'
            valTab.append(
                CDisplayListItem("Seriale wg. kategorii" + self.konto,
                                 'http://scs.pl/seriale.html',
                                 CDisplayListItem.TYPE_CATEGORY,
                                 ['http://scs.pl/seriale.html'],
                                 'seriale-kategorie', '', None))
            valTab.append(
                CDisplayListItem("Seriale alfabetycznie",
                                 'http://scs.pl/seriale.html',
                                 CDisplayListItem.TYPE_CATEGORY,
                                 ['http://scs.pl/seriale.html'], 'seriale-abc',
                                 '', None))
            valTab.append(
                CDisplayListItem(
                    "Ostatnio aktualizowane seriale",
                    'http://scs.pl/ostatnio_aktualizowane_seriale.html',
                    CDisplayListItem.TYPE_CATEGORY,
                    ['http://scs.pl/ostatnio_aktualizowane_seriale.html'],
                    'seriale-last', '', None))
            valTab.append(
                CDisplayListItem('Szukaj', 'Szukaj',
                                 CDisplayListItem.TYPE_SEARCH,
                                 ['http://scs.pl/serial,szukaj.html'],
                                 'search', '', None))
            valTab.append(
                CDisplayListItem('Historia wyszukiwania',
                                 'Historia wyszukiwania',
                                 CDisplayListItem.TYPE_CATEGORY, [''],
                                 'history', '', None))
            printDBG('Host listsItems end')
            return valTab

        # ########## #
        if 'zaloguj' == name:
            printDBG('Host listsItems begin name=' + name)
            if config.plugins.iptvplayer.scserialePREMIUM.value:
                url = 'http://scs.pl/logowanie.html'
                try:
                    data = self.cm.getURLRequestData(
                        {
                            'url': url,
                            'use_host': True,
                            'host': self.HOST,
                            'use_cookie': True,
                            'save_cookie': True,
                            'load_cookie': False,
                            'cookiefile': self.COOKIEFILE,
                            'use_post': True,
                            'return_data': True
                        }, {
                            'email':
                            config.plugins.iptvplayer.scseriale_login.value,
                            'password':
                            config.plugins.iptvplayer.scseriale_password.value
                        })
                except:
                    printDBG('Host listsItems query error')
                    printDBG('Host listsItems query error url:' + url)
                    printDBG(
                        'Host listsItems query error: Uzywam Player z limitami'
                    )
                    data = None
                if data:
                    self.PREMIUM = True
                    printDBG('Host listsItems: chyba zalogowano do premium...')
                    url = 'http://scs.pl/premium.html'
                    try:
                        data = self.cm.getURLRequestData({
                            'url': url,
                            'use_host': True,
                            'host': self.HOST,
                            'use_cookie': True,
                            'save_cookie': False,
                            'load_cookie': True,
                            'cookiefile': self.COOKIEFILE,
                            'use_post': False,
                            'return_data': True
                        })
                        printDBG('Host listsItems data: ' + data)
                        parse = re.search(
                            'Konto premium ważne do(.*?)".*?;(.*?)<', data,
                            re.S)
                        if parse:
                            self.konto = ' - Twoje konto: ' + parse.group(
                                2) + parse.group(1)
                        else:
                            self.konto = ''
                    except:
                        printDBG(
                            'Host listsItems: blad pobrania danych o koncie premium'
                        )

                if '' == self.konto:
                    self.exSession.open(
                        MessageBox,
                        'Problem z zalogowaniem użytkownika \n"%s" jako VIP.' %
                        config.plugins.iptvplayer.scseriale_login.value,
                        type=MessageBox.TYPE_INFO,
                        timeout=10)

            printDBG('Host listsItems end')
            return self.PREMIUM

        # ########## #
        if 'history' == name:
            printDBG('Host listsItems begin name=' + name)
            for histItem in self.history.getHistoryList():
                valTab.append(
                    CDisplayListItem(histItem['pattern'], 'Szukaj ',
                                     CDisplayListItem.TYPE_CATEGORY,
                                     [histItem['pattern'], histItem['type']],
                                     'search', '', None))
            printDBG('Host listsItems end')
            return valTab

        # ########## #
        if 'search' == name:
            printDBG('Host listsItems begin name=' + name)
            pattern = url
            if Index == -1:
                self.history.addHistoryItem(pattern, 'seriale')
            url = 'http://scs.pl/serial,szukaj.html'
            postdata = {'search': pattern}
            try:
                data = self.cm.getURLRequestData(
                    {
                        'url': url,
                        'use_host': False,
                        'use_cookie': False,
                        'use_post': True,
                        'return_data': True
                    }, postdata)
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            match = re.findall(
                '<div class="img_box"><a href="(.*?)">.*?<img src="(.*?)" alt="(.*?)"',
                data, re.S)
            if len(match) > 0:
                for i in range(len(match)):
                    phImage = match[i][1]
                    phUrl = self.MAIN_URL + '/' + match[i][0]
                    phTitle = match[i][2]
                    printDBG('Host listsItems phImage: ' + phImage)
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    valTab.append(
                        CDisplayListItem(phTitle, phTitle,
                                         CDisplayListItem.TYPE_CATEGORY,
                                         [phUrl], 'seriale-sezony', phImage,
                                         None))
            printDBG('Host listsItems end')
            return valTab

        # ########## #
        if 'seriale-last' == name:
            printDBG('Host listsItems begin name=' + name)
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            match = re.compile(
                'online">(.+?)</a></div></div><span class="newest_ep" id=".+?">Ostatnio dodany:<br/><a href="odcinek,(.+?),(.+?),(.+?),(.+?).html">'
            ).findall(data)
            if len(match) > 0:
                for i in range(len(match)):
                    phImage = 'http://static.scs.pl/static/serials/' + match[
                        i][1].replace('.html', '.jpg') + '.jpg'
                    phTitleS = match[i][1]
                    phTitle = match[i][0] + ' - ' + match[i][
                        4] + ' - ' + match[i][2].capitalize().replace(
                            '-', ' ')
                    phUrlS = self.MAIN_URL + '/serial,' + match[i][0]
                    phUrl = self.MAIN_URL + '/odcinek,' + match[i][
                        1] + ',' + match[i][2] + ',' + match[i][
                            3] + ',' + match[i][4] + '.html'
                    printDBG('Host listsItems phImage: ' + phImage)
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    valTab.append(
                        CDisplayListItem(phTitleS, phTitleS,
                                         CDisplayListItem.TYPE_CATEGORY,
                                         [phUrlS], 'seriale-sezony', phImage,
                                         None))
                    valTab.append(
                        CDisplayListItem(phTitle, phTitle,
                                         CDisplayListItem.TYPE_VIDEO,
                                         [CUrlItem('', phUrl, 1)], 0, phImage,
                                         None))
            printDBG('Host listsItems end')
            return valTab
        if 'seriale-kategorie' == name:
            printDBG('Host listsItems begin name=' + name)
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            phMovies = re.findall(
                '<span class="title1">(.*?)</span>(.*?)<.*?href="(.*?)"', data,
                re.S)
            if phMovies:
                for (phTitle, phCount, phUrl) in phMovies:
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    printDBG('Host listsItems phCount: ' + phCount)
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    valTab.append(
                        CDisplayListItem(phTitle + phCount, phTitle,
                                         CDisplayListItem.TYPE_CATEGORY,
                                         [self.MAIN_URL + '/' + phUrl],
                                         'seriale-kategoria', '', None))
            printDBG('Host listsItems end')
            return valTab
        if 'seriale-kategoria' == name:
            printDBG('Host listsItems begin name=' + name)
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            match = re.compile(
                'class="serial_green" href="serial,(.+?)">(.+?)</a><br/>'
            ).findall(data)
            if len(match) > 0:
                for i in range(len(match)):
                    phImage = 'http://static.scs.pl/static/serials/' + match[
                        i][0].replace('.html', '.jpg')
                    phTitle = match[i][1]
                    phUrl = self.MAIN_URL + '/serial,' + match[i][0]
                    printDBG('Host listsItems phImage: ' + phImage)
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    valTab.append(
                        CDisplayListItem(phTitle, phTitle,
                                         CDisplayListItem.TYPE_CATEGORY,
                                         [phUrl], 'seriale-sezony', phImage,
                                         None))
            printDBG('Host listsItems end')
            return valTab
        if 'seriale-abc' == name:
            printDBG('Host listsItems begin name=' + name)
            abcTab = self.cm.makeABCList()
            for i in range(len(abcTab)):
                phTitle = abcTab[i]
                valTab.append(
                    CDisplayListItem(phTitle, phTitle,
                                     CDisplayListItem.TYPE_CATEGORY,
                                     [url, phTitle], 'seriale-alfabet', '',
                                     None))
            printDBG('Host listsItems end')
            return valTab
        if 'seriale-alfabet' == name:
            printDBG('Host listsItems begin name=' + name)
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            letter = self.currList[Index].urlItems[1]
            match = re.compile(
                ' <a class="serial_green" href="serial,(.+?)">(.+?)</a><br/>'
            ).findall(data)
            if len(match) > 0:
                for i in range(len(match)):
                    addItem = False
                    if letter == '0 - 9' and (ord(match[i][1][0]) < 65
                                              or ord(match[i][1][0]) > 91):
                        addItem = True
                    if (letter == match[i][1][0].upper()): addItem = True
                    if (addItem):
                        phImage = 'http://static.scs.pl/static/serials/' + match[
                            i][0].replace('.html', '.jpg')
                        phTitle = match[i][1]
                        phUrl = self.MAIN_URL + '/serial,' + match[i][0]
                        printDBG('Host listsItems phImage: ' + phImage)
                        printDBG('Host listsItems phUrl: ' + phUrl)
                        printDBG('Host listsItems phTitle: ' + phTitle)
                        valTab.append(
                            CDisplayListItem(phTitle, phTitle,
                                             CDisplayListItem.TYPE_CATEGORY,
                                             [phUrl], 'seriale-sezony',
                                             phImage, None))
            printDBG('Host listsItems end')
            return valTab
        if 'seriale-sezony' == name:
            printDBG('Host listsItems begin name=' + name)
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            phMovies = re.compile(
                '<meta itemprop="seasonNumber" content="(.+?)">').findall(data)
            if phMovies:
                phImage = url.replace(
                    self.MAIN_URL + '/serial,',
                    'http://static.scs.pl/static/serials/').replace(
                        '.html', '.jpg')
                printDBG('Host listsItems phImage: ' + phImage)
                for (phTitle) in phMovies:
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    valTab.append(
                        CDisplayListItem('Sezon ' + phTitle,
                                         'Sezon ' + phTitle,
                                         CDisplayListItem.TYPE_CATEGORY,
                                         [url, phTitle], 'seriale-odcinki',
                                         phImage, None))
            printDBG('Host listsItems end')
            return valTab
        if 'seriale-odcinki' == name:
            printDBG('Host listsItems begin name=' + name)
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            sezon = self.currList[Index].urlItems[1]
            r = re.compile(
                '<meta itemprop="seasonNumber" content="' + sezon +
                '">(.+?)</ul></div>', re.DOTALL).findall(data)
            if not r: return []
            phMovies = re.compile(
                'itemprop="episodeNumber">(.+?)<.+?class="aLink " href="(odcinek,.+?,.+?,.+?,.+?.html)"><span itemprop="name">(.+?)</span></a>'
            ).findall(r[0])
            if phMovies:
                phImage = url.replace(
                    self.MAIN_URL + '/serial,',
                    'http://static.scs.pl/static/serials/').replace(
                        '.html', '.jpg')
                serial = url.replace(self.MAIN_URL + '/serial,',
                                     '').replace('.html', '')
                printDBG('Host listsItems phImage: ' + phImage)
                for (phEpizod, phUrl, phName) in phMovies:
                    printDBG('Host listsItems phEpizod: ' + phEpizod)
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    phTitle = '%s S%sE%s - %s' % (serial, sezon, phEpizod,
                                                  phName)
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    valTab.append(
                        CDisplayListItem(
                            phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY,
                            [self.MAIN_URL + '/' + phUrl, phTitle],
                            'seriale-odcinki-wersje', phImage, None))
            printDBG('Host listsItems end')
            return valTab
        if 'seriale-odcinki-wersje' == name:
            printDBG('Host listsItems begin name=' + name)
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            parse = re.search('Wersje:(.*?)Kopie:', data, re.S)
            if not parse: return []
            phMovies = re.findall('<a href="(.+?)">(.+?)<', parse.group(1),
                                  re.S)
            if phMovies:
                phImage = url.replace(
                    self.MAIN_URL + '/serial,',
                    'http://static.scs.pl/static/serials/').replace(
                        '.html', '.jpg')
                printDBG('Host listsItems phImage: ' + phImage)
                for (phUrl, phWersja) in phMovies:
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phWersja: ' + phWersja)
                    valTab.append(
                        CDisplayListItem(phWersja, phWersja,
                                         CDisplayListItem.TYPE_CATEGORY,
                                         [self.MAIN_URL + '/' + phUrl],
                                         'seriale-odcinki-kopie', phImage,
                                         None))
            printDBG('Host listsItems end')
            return valTab
        if 'seriale-odcinki-kopie' == name:
            printDBG('Host listsItems begin name=' + name)
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            parse = re.search('class="mirrors"(.*?)class="switch"', data, re.S)
            if not parse: return []
            phMovies = re.findall(
                '= "(.+?)"; ccc.+?;.+?"(.+?)";.+?"(.+?)";.+?"(.+?)";',
                parse.group(1), re.S)
            if phMovies:
                for (phUrl, phTime, phUser, phComment) in phMovies:
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phTime: ' + phTime)
                    printDBG('Host listsItems phUser: '******' ' + phUser,
                            phTime + ' ' + phUser + ' ' + phComment,
                            CDisplayListItem.TYPE_VIDEO,
                            [CUrlItem('', phUrl, 1)], 0, '', None))
            printDBG('Host listsItems end')
            return valTab

        return valTab

    def getResolvedURL(self, url):
        printDBG('Host getResolvedURL begin')
        printDBG('Host getResolvedURL url: ' + url)
        postdata = {'f': url}
        if self.PREMIUM:
            query_data = {
                'url': 'http://scs.pl/getVideo.html',
                'use_host': True,
                'host': self.HOST,
                'use_cookie': True,
                'save_cookie': False,
                'load_cookie': True,
                'cookiefile': self.COOKIEFILE,
                'use_post': True,
                'return_data': True
            }
        else:
            query_data = {
                'url': 'http://scs.pl/getVideo.html',
                'use_host': False,
                'use_cookie': False,
                'use_post': True,
                'return_data': True
            }
        try:
            data = self.cm.getURLRequestData(query_data, postdata)
        except:
            printDBG('Host getResolvedURL query error premium')
            printDBG('Host getResolvedURL query error premium url: ' + url)
            return ''
        #printDBG( 'Host getResolvedURL premium data: ' +data)
        match = re.compile("url: '(.+?)',").findall(data)
        if len(match) > 0:
            linkVideo = match[0]
            printDBG('Host getResolvedURL linkVideo: ' + linkVideo)
            printDBG('Host getResolvedURL end premium')
            return linkVideo
        printDBG('Host getResolvedURL end')
        return ''
class serialeo:
    SERVICE = 'serialeo'
    mainUrl = 'http://serialeonline.org.pl/'
    NewUrl = 'http://serialeonline.org.pl/nowe-odcinki'
    SerchUrl = 'http://serialeonline.org.pl/index.php?menu=search&query='

    SERVICE_MENU_TABLE =  {
        1: "Kategorie seriali",
        2: "Ostatnio uzupełnione seriale",
        3: "Wyszukaj",
        4: "Historia wyszukiwania"
    }

    def __init__(self):

        
        printDBG('Loading ' + serialeo.SERVICE)
        

        self.cm = common()
        self.up = urlparser.urlparser()
        self.history = CSearchHistoryHelper('serialeo')
        

        self.tabMenu = []
        self.currList = []

    def getCurrList(self):
        return self.currList

    def setCurrList(self, list):
        self.currList = list
        return
    
    def setTable(self):
        return self.SERVICE_MENU_TABLE

    def listsMainMenu(self, table):
        tabMenu = []
        for num, val in table.items():
            tabMenu.append(val)
        for i in range(len(tabMenu)):
            type = CListItem.TYPE_CATEGORY
            if tabMenu[i] == 'Wyszukaj':
                type = CListItem.TYPE_SEARCH
                
            item = CListItem( name = 'main-menu',
                              title = tabMenu[i],
                              category = tabMenu[i],
                              iconimage = '',
                              type = type )
            
            self.currList.append(item)
        self.tabMenu = tabMenu

    def listsKATMenu(self, url):
        sts,data = self.cm.getPage(url)
        if not sts: return
        match = re.compile(self.mainUrl + 'tv-tagi/(.+?)">(.+?)</a>').findall(data)
        if len(match) > 0:
            for i in range(len(match)):
                page = self.mainUrl + 'tv-tagi/' + match[i][0]
                item = CListItem(   name = 'kat-menu',
                                    title = match[i][1],
                                    page = page,
                                    type = CListItem.TYPE_CATEGORY )
                self.currList.append(item)

    def getLastParts(self, url):
        sts,data = self.cm.getPage(url)
        if not sts: return
        match = re.compile('portfolio(.+?)pagination', re.DOTALL).findall(data)
        if len(match) > 0:
                match2 = re.compile('href="(.+?)" class="spec-border-ie.+?\n.+?php.+?src=(.+?)&amp').findall(match[0])
                match3 = re.compile('href="http://serialeonline.org.pl/index.php.+?title="(.+?)">').findall(match[0])
                match4 = re.compile('<p class="left">(.+?)</p>').findall(match[0])
                if len(match2) and len (match3) > 0:
                        for i in range(len(match2)):
                                item = CListItem(   title = match3[i] + ' - ' + match4[i],
                                                    page = match2[i][0],
                                                    iconimage = match2[i][1],
                                                    type =  CListItem.TYPE_VIDEO )
                                self.currList.append(item)

    def showKATParts(self, page , url, pager):
        sts,data = self.cm.getPage(url)
        if not sts: return
        match = re.compile('poster(.+?)clear:both', re.DOTALL).findall(data)
        if len(match) > 0:
                match2 = re.compile('href="(.+?)" title="(.+?)">').findall(match[0])
                match3 = re.compile('timthumb.+?src=(.+?)&amp').findall(match[0])
                if len(match2) and len (match3) > 0:
                        for i in range(len(match2)):
                            item = CListItem(   title = match2[i][1],
                                                name = 'kat-parts',
                                                page = match2[i][0],
                                                iconimage = match3[i],
                                                type =  CListItem.TYPE_CATEGORY )
                            self.currList.append(item)
        match = re.compile('<li><a href="(.+?)">&raquo;</a></li>').findall(data)
        if len(match) > 0:
            item = CListItem(   title = 'Następna strona',
                                name = 'kat-menu',
                                page = page,
                                season = str(int(pager) + 1),
                                type =  CListItem.TYPE_CATEGORY )
            self.currList.append(item)

    def listsSerial(self, url, img, sezon):
        sts,data = self.cm.getPage(url)
        if not sts: return
        match = re.compile(sezon+'(.+?)tv_container', re.DOTALL).findall(data.replace('stylesheet', 'tv_container'))
        if len(match) > 0:
                match2 = re.compile('href="(.+?)">(.+?) <span class="tv_episode_name">(.+?)</span></a>').findall(match[0])
                if len(match2) > 0:
                        for i in range(len(match2)):
                                item = CListItem(   title = match2[i][1] + match2[i][2],
                                                    page = match2[i][0],
                                                    iconimage = img,
                                                    type =  CListItem.TYPE_VIDEO )
                                self.currList.append(item)

    def showSeason(self, url, img):
        sts,data = self.cm.getPage(url)
        if not sts: return
        r = re.compile('<h2>Sezon(.+?)</h2>').findall(data)
        if len(r)>0:
                for i in range(len(r)):
                    item = CListItem(   title = 'Sezon' + r[i],
                                        name = 'sezon',
                                        page = url,
                                        iconimage = img,
                                        type =  CListItem.TYPE_CATEGORY )
                    self.currList.append(item)

    def getListsSearch(self, text):
        sts,data = self.cm.getPage(self.SerchUrl + text)
        if not sts: return
        match = re.compile('<a class="link" href="(.+?)/season.+?" title="(.+?)">').findall(data)
        match2 = re.compile('timthumb.+?src=(.+?)&amp').findall(data)
        if len(match) and len (match2) > 0:
                for i in range(len(match)):
                    item = CListItem(   title = match[i][1],
                                        name = 'kat-parts',
                                        page = match[i][0],
                                        iconimage = match2[i],
                                        type =  CListItem.TYPE_CATEGORY )
                    self.currList.append(item)

    def listsHistory(self):
        list = self.history.getHistoryList()
        for item in list:
            item = CListItem(   title = item,
                                name = 'history',
                                plot = 'Szukaj: "%s"' % item,
                                type =  CListItem.TYPE_CATEGORY )
            self.currList.append(item)

    def getPlayTable(self,url):
        valTab = []
        sts,data = self.cm.getPage(url)
        if not sts: return valTab
        r = re.compile('row-pages-wrapper(.+?)disqus_thread', re.DOTALL).findall(data)
        if len(r)>0:
            r2 = re.compile('href="(.+?)" target="_blank">Oglądaj').findall(r[0])
            r3 = re.compile('http://serialeonline.org.pl/templates/trakt/images/(.+?).gif').findall(r[0])
            if len(r2)>0:
                for i in range(len(r2)):
                    title = r3[i].replace('pl1', 'Napisy').replace('eng', 'Oryginał').replace('pol', 'Lektor') + ' - ' + self.up.getHostName(r2[i])
                    valTab.append(self.cm.setLinkTable(r2[i], title))
                return valTab
        return valTab

    def handleService(self, index, refresh = 0, searchPattern = ''):
        if 0 == refresh:
            if len(self.currList) <= index:
                printDBG( "handleService wrond index: %s, len(self.currList): %d" % (index, len(self.currList)) )
                return
        
            if -1 == index:
                self.name        = None
                self.seltitle    = ''
                self.category    = ''
                self.page        = ''
                self.icon        = ''
                self.link        = ''
                self.service     = ''
                self.action      = ''
                self.sezon       = ''
                self.epizod      = ''
                self.serial      = ''
                self.searchPattern = ''


                printDBG("serialeo: handleService for first self.category")
            else:
                item             = self.currList[index]
                
                self.name        = item.name
                self.title       = item.title
                self.category    = item.category
                self.page        = item.page
                self.icon        = item.iconimage
                self.link        = item.page
                self.sezon       = item.season
                self.epizod      = item.episode
                self.serial      = item.tvshowtitle
                self.searchPattern = item.searchPattern

                
                printDBG("serialeo: |||||||||||||||||||||||||||||||||||| %s " % item.name)
        self.currList = []

        if str(self.sezon)=='None' or self.sezon=='':
            self.sezon = '1'


        if self.name == None:
            self.listsMainMenu(self.SERVICE_MENU_TABLE)
        elif self.category == self.setTable()[1]:
            self.listsKATMenu(self.mainUrl)
        elif self.category == self.setTable()[2]:
            self.getLastParts(self.NewUrl)
        elif self.category == self.setTable()[3]:
            if self.searchPattern == '':
                text = searchPattern
            else:
                text = self.searchPattern
            self.history.addHistoryItem(text)
            self.getListsSearch(text)
        elif self.category == self.setTable()[4]:
            self.listsHistory()
        elif self.name == 'kat-menu':
            self.showKATParts(self.page ,self.page + '/abc/' + str(self.sezon), self.sezon)
        elif self.name == 'kat-parts':
            self.showSeason(self.page, self.icon)
        elif self.name == 'sezon':
            self.listsSerial(self.page, self.icon, self.title)
        elif self.name == 'history':
            self.getListsSearch(self.title)
Beispiel #3
0
class serialeo:
    SERVICE = 'serialeo'
    mainUrl = 'http://serialeonline.org.pl/'
    NewUrl = 'http://serialeonline.org.pl/nowe-odcinki'
    SerchUrl = 'http://serialeonline.org.pl/index.php?menu=search&query='

    SERVICE_MENU_TABLE = {
        1: "Kategorie seriali",
        2: "Ostatnio uzupełnione seriale",
        3: "Wyszukaj",
        4: "Historia wyszukiwania"
    }

    def __init__(self):

        printDBG('Loading ' + serialeo.SERVICE)

        self.cm = common()
        self.up = urlparser.urlparser()
        self.history = CSearchHistoryHelper('serialeo')

        self.tabMenu = []
        self.currList = []

    def getCurrList(self):
        return self.currList

    def setCurrList(self, list):
        self.currList = list
        return

    def setTable(self):
        return self.SERVICE_MENU_TABLE

    def listsMainMenu(self, table):
        tabMenu = []
        for num, val in table.items():
            tabMenu.append(val)
        for i in range(len(tabMenu)):
            type = CListItem.TYPE_CATEGORY
            if tabMenu[i] == 'Wyszukaj':
                type = CListItem.TYPE_SEARCH

            item = CListItem(name='main-menu',
                             title=tabMenu[i],
                             category=tabMenu[i],
                             iconimage='',
                             type=type)

            self.currList.append(item)
        self.tabMenu = tabMenu

    def listsKATMenu(self, url):
        sts, data = self.cm.getPage(url)
        if not sts: return
        match = re.compile(self.mainUrl +
                           'tv-tagi/(.+?)">(.+?)</a>').findall(data)
        if len(match) > 0:
            for i in range(len(match)):
                page = self.mainUrl + 'tv-tagi/' + match[i][0]
                item = CListItem(name='kat-menu',
                                 title=match[i][1],
                                 page=page,
                                 type=CListItem.TYPE_CATEGORY)
                self.currList.append(item)

    def getLastParts(self, url):
        sts, data = self.cm.getPage(url)
        if not sts: return
        match = re.compile('portfolio(.+?)pagination', re.DOTALL).findall(data)
        if len(match) > 0:
            match2 = re.compile(
                'href="(.+?)" class="spec-border-ie.+?\n.+?php.+?src=(.+?)&amp'
            ).findall(match[0])
            match3 = re.compile(
                'href="http://serialeonline.org.pl/index.php.+?title="(.+?)">'
            ).findall(match[0])
            match4 = re.compile('<p class="left">(.+?)</p>').findall(match[0])
            if len(match2) and len(match3) > 0:
                for i in range(len(match2)):
                    item = CListItem(title=match3[i] + ' - ' + match4[i],
                                     page=match2[i][0],
                                     iconimage=match2[i][1],
                                     type=CListItem.TYPE_VIDEO)
                    self.currList.append(item)

    def showKATParts(self, page, url, pager):
        sts, data = self.cm.getPage(url)
        if not sts: return
        match = re.compile('poster(.+?)clear:both', re.DOTALL).findall(data)
        if len(match) > 0:
            match2 = re.compile('href="(.+?)" title="(.+?)">').findall(
                match[0])
            match3 = re.compile('timthumb.+?src=(.+?)&amp').findall(match[0])
            if len(match2) and len(match3) > 0:
                for i in range(len(match2)):
                    item = CListItem(title=match2[i][1],
                                     name='kat-parts',
                                     page=match2[i][0],
                                     iconimage=match3[i],
                                     type=CListItem.TYPE_CATEGORY)
                    self.currList.append(item)
        match = re.compile('<li><a href="(.+?)">&raquo;</a></li>').findall(
            data)
        if len(match) > 0:
            item = CListItem(title='Następna strona',
                             name='kat-menu',
                             page=page,
                             season=str(int(pager) + 1),
                             type=CListItem.TYPE_CATEGORY)
            self.currList.append(item)

    def listsSerial(self, url, img, sezon):
        sts, data = self.cm.getPage(url)
        if not sts: return
        match = re.compile(sezon + '(.+?)tv_container', re.DOTALL).findall(
            data.replace('stylesheet', 'tv_container'))
        if len(match) > 0:
            match2 = re.compile(
                'href="(.+?)">(.+?) <span class="tv_episode_name">(.+?)</span></a>'
            ).findall(match[0])
            if len(match2) > 0:
                for i in range(len(match2)):
                    item = CListItem(title=match2[i][1] + match2[i][2],
                                     page=match2[i][0],
                                     iconimage=img,
                                     type=CListItem.TYPE_VIDEO)
                    self.currList.append(item)

    def showSeason(self, url, img):
        sts, data = self.cm.getPage(url)
        if not sts: return
        r = re.compile('<h2>Sezon(.+?)</h2>').findall(data)
        if len(r) > 0:
            for i in range(len(r)):
                item = CListItem(title='Sezon' + r[i],
                                 name='sezon',
                                 page=url,
                                 iconimage=img,
                                 type=CListItem.TYPE_CATEGORY)
                self.currList.append(item)

    def getListsSearch(self, text):
        sts, data = self.cm.getPage(self.SerchUrl + text)
        if not sts: return
        match = re.compile(
            '<a class="link" href="(.+?)/season.+?" title="(.+?)">').findall(
                data)
        match2 = re.compile('timthumb.+?src=(.+?)&amp').findall(data)
        if len(match) and len(match2) > 0:
            for i in range(len(match)):
                item = CListItem(title=match[i][1],
                                 name='kat-parts',
                                 page=match[i][0],
                                 iconimage=match2[i],
                                 type=CListItem.TYPE_CATEGORY)
                self.currList.append(item)

    def listsHistory(self):
        list = self.history.getHistoryList()
        for item in list:
            item = CListItem(title=item,
                             name='history',
                             plot='Szukaj: "%s"' % item,
                             type=CListItem.TYPE_CATEGORY)
            self.currList.append(item)

    def getPlayTable(self, url):
        valTab = []
        sts, data = self.cm.getPage(url)
        if not sts: return valTab
        r = re.compile('row-pages-wrapper(.+?)disqus_thread',
                       re.DOTALL).findall(data)
        if len(r) > 0:
            r2 = re.compile('href="(.+?)" target="_blank">Oglądaj').findall(
                r[0])
            r3 = re.compile(
                'http://serialeonline.org.pl/templates/trakt/images/(.+?).gif'
            ).findall(r[0])
            if len(r2) > 0:
                for i in range(len(r2)):
                    title = r3[i].replace('pl1', 'Napisy').replace(
                        'eng', 'Oryginał').replace(
                            'pol', 'Lektor') + ' - ' + self.up.getHostName(
                                r2[i])
                    valTab.append(self.cm.setLinkTable(r2[i], title))
                return valTab

    def handleService(self, index, refresh=0, searchPattern=''):
        if 0 == refresh:
            if len(self.currList) <= index:
                printDBG(
                    "handleService wrond index: %s, len(self.currList): %d" %
                    (index, len(self.currList)))
                return

            if -1 == index:
                self.name = None
                self.seltitle = ''
                self.category = ''
                self.page = ''
                self.icon = ''
                self.link = ''
                self.service = ''
                self.action = ''
                self.sezon = ''
                self.epizod = ''
                self.serial = ''
                self.searchPattern = ''

                printDBG("serialeo: handleService for first self.category")
            else:
                item = self.currList[index]

                self.name = item.name
                self.title = item.title
                self.category = item.category
                self.page = item.page
                self.icon = item.iconimage
                self.link = item.page
                self.sezon = item.season
                self.epizod = item.episode
                self.serial = item.tvshowtitle
                self.searchPattern = item.searchPattern

                printDBG("serialeo: |||||||||||||||||||||||||||||||||||| %s " %
                         item.name)
        self.currList = []

        if str(self.sezon) == 'None' or self.sezon == '':
            self.sezon = '1'

        if self.name == None:
            self.listsMainMenu(self.SERVICE_MENU_TABLE)
        elif self.category == self.setTable()[1]:
            self.listsKATMenu(self.mainUrl)
        elif self.category == self.setTable()[2]:
            self.getLastParts(self.NewUrl)
        elif self.category == self.setTable()[3]:
            if self.searchPattern == '':
                text = searchPattern
            else:
                text = self.searchPattern
            self.history.addHistoryItem(text)
            self.getListsSearch(text)
        elif self.category == self.setTable()[4]:
            self.listsHistory()
        elif self.name == 'kat-menu':
            self.showKATParts(self.page, self.page + '/abc/' + str(self.sezon),
                              self.sezon)
        elif self.name == 'kat-parts':
            self.showSeason(self.page, self.icon)
        elif self.name == 'sezon':
            self.listsSerial(self.page, self.icon, self.title)
        elif self.name == 'history':
            self.getListsSearch(self.title)
class Host:
    currList = []
    MAIN_URL = ''
    PREMIUM = False
    konto = ''
    HOST = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110621 Mandriva Linux/1.9.2.18-0.1mdv2010.2 (2010.2) Firefox/3.6.18'

    def __init__(self):
        printDBG( 'Host __init__ begin' )
        self.exSession = MainSessionWrapper()
        self.COOKIEFILE = GetCookieDir('zalukajtv.cookie')
        self.cm = common()
        self.up = urlparser()
        self.history = CSearchHistoryHelper('wspolne')
        self.currList = []
        printDBG( 'Host __init__ end' )
        
    def setCurrList(self, list):
        printDBG( 'Host setCurrList begin' )
        self.currList = list
        printDBG( 'Host setCurrList end' )
        return 
        
    def fullUrl(self, phUrl):
        if not phUrl.startswith('http'):
            if '/' == phUrl[0]:
                phUrl = '/' + phUrl
            phUrl = self.MAIN_URL + phUrl
        return phUrl

    def getInitList(self):
        printDBG( 'Host getInitList begin' )
        ####################################
        # logowanie
        ####################################
        if config.plugins.iptvplayer.zalukajtvPREMIUM.value:
           url = 'http://zalukaj.tv/account.php'
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': True, 'load_cookie': False, 'cookiefile': self.COOKIEFILE, 'use_post': True, 'return_data': True },{'login': config.plugins.iptvplayer.zalukajtv_login.value, 'password': config.plugins.iptvplayer.zalukajtv_password.value})
           except:
              printDBG( 'Host getInitList query error' )
              printDBG( 'Host getInitList query error url:'+url )
              printDBG( 'Host getInitList query error: Uzywam Player z limitami')
              data = None
           if data:
              self.PREMIUM = True
              printDBG( 'Host getInitList: chyba zalogowano do premium...' )
              url = 'http://zalukaj.tv/libs/ajax/login.php?login=1'
              try: 
                 data = self.cm.getURLRequestData({ 'url': url, 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': False, 'return_data': True })
                 printDBG( 'Host listsItems data: '+data )
                 parse = re.search('Typ Konta:.*?>(.*?)<.*?>(.*?)<', data, re.S)
                 if parse:
                    self.konto = '- Typ Konta: '+parse.group(1)+parse.group(2)
                 else: 
                    self.konto = ''
              except:
                 printDBG( 'Host getInitList: blad pobrania danych o koncie premium' )
                 
           if '' == self.konto:
              self.exSession.open(MessageBox, 'Problem z zalogowaniem użytkownika \n"%s" jako VIP.' % config.plugins.iptvplayer.zalukajtv_login.value, type = MessageBox.TYPE_INFO, timeout = 10)

              #if 'Wyloguj' in data:
              #   self.PREMIUM = True 
              #   printDBG('Host getInitList:' + config.plugins.iptvplayer.zalukajtv_login.value + ', Zostales poprawnie zalogowany')
              #else:
              #   printDBG('Host getInitList: Blad logowania, uzywam Player z limitami')
        ####################################
        self.currList = self.listsItems(-1, '', 'main-menu')
        printDBG( 'Host getInitList end' )
        return self.currList

    def getListForItem(self, Index = 0, refresh = 0, selItem = None):
        printDBG( 'Host getListForItem begin' )
        valTab = []
        if len(self.currList[Index].urlItems) == 0:
           return valTab
        valTab = self.listsItems(Index, self.currList[Index].urlItems[0], self.currList[Index].urlSeparateRequest)
        self.currList = valTab
        printDBG( 'Host getListForItem end' )
        return self.currList

    def getSearchResults(self, pattern, searchType = None):
        printDBG( "Host getSearchResults begin" )
        printDBG( "Host getSearchResults pattern: " +pattern)
        valTab = []
        valTab = self.listsItems(-1, pattern, 'search')
        #valTab = [] #test       
        self.currList = valTab
        printDBG( "Host getSearchResults end" )
        return self.currList

    def listsItems(self, Index, url, name = ''):
        printDBG( 'Host listsItems begin' )
        printDBG( 'Host listsItems url: '+url )
        valTab = []
        if name == 'main-menu':
           printDBG( 'Host listsItems begin name='+name )
           self.MAIN_URL = 'http://zalukaj.tv'
           valTab.append(CDisplayListItem('Filmy '+self.konto,   'http://zalukaj.tv',         CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/'],          'filmy', '', None)) 
           valTab.append(CDisplayListItem('Seriale', 'http://zalukaj.tv/seriale', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/seriale'],   'seriale', '', None)) 
           valTab.append(CDisplayListItem('Szukaj',  'Szukaj filmów',             CDisplayListItem.TYPE_SEARCH,   ['http://szukaj.zalukaj.tv/szukaj'],   'seriale', '', None)) 
           valTab.append(CDisplayListItem('Historia wyszukiwania', 'Historia wyszukiwania', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/seriale'],   'history', '', None)) 
           printDBG( 'Host listsItems end' )
           return valTab

        # ########## #
        if 'history' == name:
           printDBG( 'Host listsItems begin name='+name )
           for histItem in self.history.getHistoryList():
               valTab.append(CDisplayListItem(histItem['pattern'], 'Szukaj ', CDisplayListItem.TYPE_CATEGORY, [histItem['pattern'],histItem['type']], 'search', '', None))          
           printDBG( 'Host listsItems end' )
           return valTab
           
        # ########## #
        if 'search' == name:
           printDBG( 'Host listsItems begin name='+name )
           pattern = url 
           if Index==-1: 
              self.history.addHistoryItem( pattern, 'video')
           url = 'http://k.zalukaj.tv/szukaj'
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': True, 'return_data': True },{'searchinput': pattern})
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           phMovies = re.findall('class="tivief4".*?src="(.*?)".*?<a href="(.*?)".*?title="(.*?)".*?div style.*?">(.*?)<.*?class="few_more">(.*?)<', data, re.S)
           if phMovies:
              for (phImage, phUrl, phTitle, phDescr, phMore) in phMovies:
                  printDBG( 'Host listsItems phImage: '  +phImage )
                  printDBG( 'Host listsItems phUrl: '    +phUrl )
                  printDBG( 'Host listsItems phTitle: '  +phTitle )
                  printDBG( 'Host listsItems phDescr: '  +phDescr )
                  printDBG( 'Host listsItems phMore: '   +phMore )
                  valTab.append(CDisplayListItem(phTitle, phMore+' | '+decodeHtml(phDescr), CDisplayListItem.TYPE_VIDEO, [CUrlItem('', phUrl, 1)], 0, phImage, None)) 
           printDBG( 'Host listsItems end' )
           return valTab
           
        # ########## #
        if 'seriale' == name:
           printDBG( 'Host listsItems begin name='+name )
           self.MAIN_URL = 'http://zalukaj.tv' 
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           parse = re.search('<div id="two"(.*?)</table>', data, re.S)
           if not parse: return ''
           phMovies = re.findall('<td class="wef32f"><a href="(.*?)" title="(.*?)"', parse.group(1), re.S)
           if phMovies:
              for (phUrl, phTitle) in phMovies:
                  printDBG( 'Host listsItems phUrl: '  +phUrl )
                  printDBG( 'Host listsItems phTitle: '+phTitle )
                  valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], 'seriale-sezony', '', None))          
           valTab.insert(0,CDisplayListItem('--Ostatnio zaktualizowane seriale--',   'Ostatnio zaktualizowane seriale', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/seriale'], 'seriale-last', '', None))
           printDBG( 'Host listsItems end' )
           return valTab
        if 'seriale-last' == name:
           printDBG( 'Host listsItems begin name='+name )
           self.MAIN_URL = 'http://zalukaj.tv' 
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           phMovies = re.findall('<div class="latest tooltip".*?href="(.*?)" title="(.*?)".*?src="(.*?)"', data, re.S)
           if phMovies:
              for (phUrl, phTitle, phImage) in phMovies:
                  printDBG( 'Host listsItems phUrl: '  +phUrl )
                  printDBG( 'Host listsItems phTitle: '+phTitle )
                  printDBG( 'Host listsItems phImage: '+phImage )
                  valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], 'seriale-sezon', phImage, None))          
           printDBG( 'Host listsItems end' )
           return valTab
        if 'seriale-sezony' == name:
           printDBG( 'Host listsItems begin name='+name )
           self.MAIN_URL = 'http://zalukaj.tv' 
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           phImage = ''
           parse = re.search('<div id="sezony".*?img src="(.*?)"', data, re.S)
           if parse: phImage = parse.group(1)
           printDBG( 'Host listsItems phImage: '  +phImage )
           phMovies = re.findall('<a class="sezon" href="(.*?)".*?>(.*?)<', data, re.S)
           if phMovies:
              for (phUrl, phTitle) in phMovies:
                  printDBG( 'Host listsItems phUrl: '  +phUrl )
                  printDBG( 'Host listsItems phTitle: '+phTitle )
                  valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], 'seriale-sezon', phImage, None))          
           printDBG( 'Host listsItems end' )
           return valTab
        if 'seriale-sezon' == name:
           printDBG( 'Host listsItems begin name='+name )
           self.MAIN_URL = 'http://zalukaj.tv' 
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           phImage = ''
           parse = re.search('<img src="(.*?)"', data, re.S)
           if parse: phImage = parse.group(1)
           printDBG( 'Host listsItems phImage: '  +phImage )
           phMovies = re.findall('id="sezony".*?>(.*?)<.*?href="(.*?)" title="(.*?)"', data, re.S)
           if phMovies:
              for (phEpisode, phUrl, phTitle) in phMovies:
                  printDBG( 'Host listsItems phEpizod: '  +phEpisode )
                  printDBG( 'Host listsItems phUrl: '  +phUrl )
                  printDBG( 'Host listsItems phTitle: '+phTitle )
                  valTab.append(CDisplayListItem(phEpisode+' - '+phTitle, phTitle, CDisplayListItem.TYPE_VIDEO, [CUrlItem('', self.fullUrl(phUrl), 1)], 0, phImage, None))          
                  printDBG( 'Host listsItems end' )
           return valTab
        if 'filmy' == name:
           printDBG( 'Host listsItems begin name='+name )
           self.MAIN_URL = 'http://zalukaj.tv' 
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           sts,parse = CParsingHelper.getDataBeetwenMarkers(data, '<table id="one"', '</table>', False)
           phMovies = re.findall('<td class="wef32f"><a href="([^"]+?)">([^<]+?)</a>', parse, re.S)
           if phMovies:
              for (phUrl, phTitle) in phMovies:
                  printDBG( 'Host listsItems phUrl: '   + phUrl )
                  printDBG( 'Host listsItems phTitle: ' + phTitle )
                  valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [ self.fullUrl(phUrl) ], 'filmy-clip', '', None))          
           #valTab.insert(0,CDisplayListItem('--Najpopularniejsze--', 'Najpopularniejsze wyswietlenia-miesiac', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/#wyswietlenia-miesiac'], 'filmy-last', '', None))          
           #valTab.insert(0,CDisplayListItem('--Ostatnio oglądane--', 'Ostatnio oglądane',                      CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/#lastseen'],             'filmy-last', '', None))          
           valTab.insert(0,CDisplayListItem('--Ostatnio dodane--',   'Ostatnio dodane',                        CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv'],            'filmy-last', '', None))          
           printDBG( 'Host listsItems end' )
           return valTab
        if 'filmy-clip' == name:
           printDBG( 'Host listsItems begin name='+name )
           self.MAIN_URL = 'http://zalukaj.tv' 
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           phMovies = re.findall('background-image:url(.*?);"><p><span>(.*?)</span>.*?<h3><a href="(.*?)".*?">(.*?)<.*?">(.*?)<.*?class="few_more">(.*?)<', data, re.S)
           if phMovies:
              for (phImage, phRok, phUrl, phTitle, phDescr, phMore) in phMovies:
                  printDBG( 'Host listsItems phImage: '  +phImage )
                  printDBG( 'Host listsItems phRok: '    +phRok )
                  printDBG( 'Host listsItems phUrl: '    +phUrl )
                  printDBG( 'Host listsItems phTitle: '  +phTitle )
                  printDBG( 'Host listsItems phDescr: '  +phDescr )
                  printDBG( 'Host listsItems phMore: '   +phMore )
                  valTab.append(CDisplayListItem(phTitle, phRok+' | '+phMore+' | '+decodeHtml(phDescr), CDisplayListItem.TYPE_VIDEO, [CUrlItem('', phUrl, 1)], 0, phImage[1:-1], None)) 
           match = re.findall('class="pc_current">.*?href="(.*?)">(.*?)<', data, re.S)
           if match:               
                  phUrl = match[-1][0]
                  phTitle = match[-1][1]
                  valTab.append(CDisplayListItem('Strona '+phTitle, 'Strona: '+phUrl, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], name, '', None)) 
           printDBG( 'Host listsItems end' )
           return valTab
        if 'filmy-last' == name:
           printDBG( 'Host listsItems begin name='+name )
           self.MAIN_URL = 'http://zalukaj.tv' 
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           phMovies = re.findall('class="tivief4".*?src="(.*?)".*?<h3><a href="(.*?)".*?">(.*?)<.*?">(.*?)<.*?class="few_more">(.*?)<', data, re.S)
           if phMovies:
              for (phImage, phUrl, phTitle, phDescr, phMore) in phMovies:
                  printDBG( 'Host listsItems phImage: '  +phImage )
                  printDBG( 'Host listsItems phUrl: '    +phUrl )
                  printDBG( 'Host listsItems phTitle: '  +phTitle )
                  printDBG( 'Host listsItems phDescr: '  +phDescr )
                  printDBG( 'Host listsItems phMore: '   +phMore )
                  valTab.append(CDisplayListItem(phTitle, phMore+' | '+decodeHtml(phDescr), CDisplayListItem.TYPE_VIDEO, [CUrlItem('', self.fullUrl(phUrl), 1)], 0, phImage, None)) 
           printDBG( 'Host listsItems end' )
           return valTab

        return valTab

    def getResolvedURL(self, url):
        printDBG( 'Host getResolvedURL begin' )
        printDBG( 'Host getResolvedURL url: '+url )
        videoUrl = ''
        valTab = []
        
        if self.PREMIUM:
            sts, data = self.cm.getPage(url, {'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE})
            if sts:
                parse = re.search('/player.php.*?"', data, re.S)
                if parse: 
                    printDBG( 'parse1p: '+parse.group(0) )
                    url2 = self.fullUrl(parse.group(0))
                    sts, data = self.cm.getPage(url2, {'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': False, 'return_data': True })
                    if sts:
                        parse = re.search('<a href="(.*?)"', data, re.S)
                        if parse:
                            printDBG( 'parse2p: '+parse.group(1) )
                            url2 = parse.group(1)
                            sts,data = self.cm.getPage(url2, { 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': False, 'return_data': True })
                            if sts: 
                                printDBG( 'parse3pdata ')
                                match = re.compile("url:'(.+?)'").findall(data)
                                if len(match) > 0:                       
                                    printDBG( 'parse3p: PREMIUM: '+match[0] )
                                    linkvideo = match[0]
                                    return linkvideo
                    else:
                        printDBG( 'Host getResolvedURL query error premium' )
                        printDBG( 'Host getResolvedURL query error premium url: '+url2 )
                else:
                    printDBG( 'Host getResolvedURL query error premium' )
                    printDBG( 'Host getResolvedURL query error premium url: '+url2 )
            else:
                printDBG( 'Host getResolvedURL query error premium' )
                printDBG( 'Host getResolvedURL query error premium url: '+url )
              
        if url[0:30] == 'http://zalukaj.tv/zalukaj-film' or url[0:31] == 'http://zalukaj.tv/serial-online':      
            sts, data = self.cm.getPage(url)
            if not sts:
               printDBG( 'Host getResolvedURL query error' )
               printDBG( 'Host getResolvedURL query error url: '+url )
               return ''
               
            parse = re.search('/player.php.*?"', data, re.S)
            if not parse: return '' 
            printDBG( 'parse1: '+parse.group(0) )
            url2 = self.fullUrl(parse.group(0))
            sts, data = self.cm.getPage(url2)
            if not sts:
               printDBG( 'Host getResolvedURL query error' )
               printDBG( 'Host getResolvedURL query error url: '+ url2 )
               return ''
            parse = re.search('<a href="([^"]+?)"', data, re.S)
            if not parse: 
               return ''
            printDBG( 'parse2: '+parse.group(1) )
            url2 = parse.group(1)
            sts, data = self.cm.getPage(url2)
            if not sts:
               return ''
            parse = re.search('iframe src="([^"]+?)" width=', data)
            if not parse:
               return ''
            ret = self.up.getVideoLink( parse.group(1) )
            if ret:
               return ret
        return ''
class Host:
    currList = []
    MAIN_URL = ''
    PREMIUM = False
    konto = ''
    HOST = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110621 Mandriva Linux/1.9.2.18-0.1mdv2010.2 (2010.2) Firefox/3.6.18'

    def __init__(self):
        printDBG('Host __init__ begin')
        self.exSession = MainSessionWrapper()
        self.COOKIEFILE = GetCookieDir('zalukajtv.cookie')
        self.cm = common()
        self.up = urlparser()
        self.history = CSearchHistoryHelper('wspolne')
        self.currList = []
        printDBG('Host __init__ end')

    def setCurrList(self, list):
        printDBG('Host setCurrList begin')
        self.currList = list
        printDBG('Host setCurrList end')
        return

    def fullUrl(self, phUrl):
        if not phUrl.startswith('http'):
            if '/' == phUrl[0]:
                phUrl = '/' + phUrl
            phUrl = self.MAIN_URL + phUrl
        return phUrl

    def getInitList(self):
        printDBG('Host getInitList begin')
        ####################################
        # logowanie
        ####################################
        if config.plugins.iptvplayer.zalukajtvPREMIUM.value:
            url = 'http://zalukaj.tv/account.php'
            try:
                data = self.cm.getURLRequestData(
                    {
                        'url': url,
                        'use_host': True,
                        'host': self.HOST,
                        'use_cookie': True,
                        'save_cookie': True,
                        'load_cookie': False,
                        'cookiefile': self.COOKIEFILE,
                        'use_post': True,
                        'return_data': True
                    }, {
                        'login':
                        config.plugins.iptvplayer.zalukajtv_login.value,
                        'password':
                        config.plugins.iptvplayer.zalukajtv_password.value
                    })
            except:
                printDBG('Host getInitList query error')
                printDBG('Host getInitList query error url:' + url)
                printDBG(
                    'Host getInitList query error: Uzywam Player z limitami')
                data = None
            if data:
                self.PREMIUM = True
                printDBG('Host getInitList: chyba zalogowano do premium...')
                url = 'http://zalukaj.tv/libs/ajax/login.php?login=1'
                try:
                    data = self.cm.getURLRequestData({
                        'url': url,
                        'use_host': True,
                        'host': self.HOST,
                        'use_cookie': True,
                        'save_cookie': False,
                        'load_cookie': True,
                        'cookiefile': self.COOKIEFILE,
                        'use_post': False,
                        'return_data': True
                    })
                    printDBG('Host listsItems data: ' + data)
                    parse = re.search('Typ Konta:.*?>(.*?)<.*?>(.*?)<', data,
                                      re.S)
                    if parse:
                        self.konto = '- Typ Konta: ' + parse.group(
                            1) + parse.group(2)
                    else:
                        self.konto = ''
                except:
                    printDBG(
                        'Host getInitList: blad pobrania danych o koncie premium'
                    )

            if '' == self.konto:
                self.exSession.open(
                    MessageBox,
                    'Problem z zalogowaniem użytkownika \n"%s" jako VIP.' %
                    config.plugins.iptvplayer.zalukajtv_login.value,
                    type=MessageBox.TYPE_INFO,
                    timeout=10)

                #if 'Wyloguj' in data:
                #   self.PREMIUM = True
                #   printDBG('Host getInitList:' + config.plugins.iptvplayer.zalukajtv_login.value + ', Zostales poprawnie zalogowany')
                #else:
                #   printDBG('Host getInitList: Blad logowania, uzywam Player z limitami')
        ####################################
        self.currList = self.listsItems(-1, '', 'main-menu')
        printDBG('Host getInitList end')
        return self.currList

    def getListForItem(self, Index=0, refresh=0, selItem=None):
        printDBG('Host getListForItem begin')
        valTab = []
        if len(self.currList[Index].urlItems) == 0:
            return valTab
        valTab = self.listsItems(Index, self.currList[Index].urlItems[0],
                                 self.currList[Index].urlSeparateRequest)
        self.currList = valTab
        printDBG('Host getListForItem end')
        return self.currList

    def getSearchResults(self, pattern, searchType=None):
        printDBG("Host getSearchResults begin")
        printDBG("Host getSearchResults pattern: " + pattern)
        valTab = []
        valTab = self.listsItems(-1, pattern, 'search')
        #valTab = [] #test
        self.currList = valTab
        printDBG("Host getSearchResults end")
        return self.currList

    def listsItems(self, Index, url, name=''):
        printDBG('Host listsItems begin')
        printDBG('Host listsItems url: ' + url)
        valTab = []
        if name == 'main-menu':
            printDBG('Host listsItems begin name=' + name)
            self.MAIN_URL = 'http://zalukaj.tv'
            valTab.append(
                CDisplayListItem('Filmy ' + self.konto, 'http://zalukaj.tv',
                                 CDisplayListItem.TYPE_CATEGORY,
                                 ['http://zalukaj.tv/'], 'filmy', '', None))
            valTab.append(
                CDisplayListItem('Seriale', 'http://zalukaj.tv/seriale',
                                 CDisplayListItem.TYPE_CATEGORY,
                                 ['http://zalukaj.tv/seriale'], 'seriale', '',
                                 None))
            valTab.append(
                CDisplayListItem('Szukaj', 'Szukaj filmów',
                                 CDisplayListItem.TYPE_SEARCH,
                                 ['http://szukaj.zalukaj.tv/szukaj'],
                                 'seriale', '', None))
            valTab.append(
                CDisplayListItem('Historia wyszukiwania',
                                 'Historia wyszukiwania',
                                 CDisplayListItem.TYPE_CATEGORY,
                                 ['http://zalukaj.tv/seriale'], 'history', '',
                                 None))
            printDBG('Host listsItems end')
            return valTab

        # ########## #
        if 'history' == name:
            printDBG('Host listsItems begin name=' + name)
            for histItem in self.history.getHistoryList():
                valTab.append(
                    CDisplayListItem(histItem['pattern'], 'Szukaj ',
                                     CDisplayListItem.TYPE_CATEGORY,
                                     [histItem['pattern'], histItem['type']],
                                     'search', '', None))
            printDBG('Host listsItems end')
            return valTab

        # ########## #
        if 'search' == name:
            printDBG('Host listsItems begin name=' + name)
            pattern = url
            if Index == -1:
                self.history.addHistoryItem(pattern, 'video')
            url = 'http://k.zalukaj.tv/szukaj'
            try:
                data = self.cm.getURLRequestData(
                    {
                        'url': url,
                        'use_host': False,
                        'use_cookie': False,
                        'use_post': True,
                        'return_data': True
                    }, {'searchinput': pattern})
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            phMovies = re.findall(
                'class="tivief4".*?src="(.*?)".*?<a href="(.*?)".*?title="(.*?)".*?div style.*?">(.*?)<.*?class="few_more">(.*?)<',
                data, re.S)
            if phMovies:
                for (phImage, phUrl, phTitle, phDescr, phMore) in phMovies:
                    printDBG('Host listsItems phImage: ' + phImage)
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    printDBG('Host listsItems phDescr: ' + phDescr)
                    printDBG('Host listsItems phMore: ' + phMore)
                    valTab.append(
                        CDisplayListItem(phTitle,
                                         phMore + ' | ' + decodeHtml(phDescr),
                                         CDisplayListItem.TYPE_VIDEO,
                                         [CUrlItem('', phUrl, 1)], 0, phImage,
                                         None))
            printDBG('Host listsItems end')
            return valTab

        # ########## #
        if 'seriale' == name:
            printDBG('Host listsItems begin name=' + name)
            self.MAIN_URL = 'http://zalukaj.tv'
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            parse = re.search('<div id="two"(.*?)</table>', data, re.S)
            if not parse: return ''
            phMovies = re.findall(
                '<td class="wef32f"><a href="(.*?)" title="(.*?)"',
                parse.group(1), re.S)
            if phMovies:
                for (phUrl, phTitle) in phMovies:
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    valTab.append(
                        CDisplayListItem(phTitle, phTitle,
                                         CDisplayListItem.TYPE_CATEGORY,
                                         [self.fullUrl(phUrl)],
                                         'seriale-sezony', '', None))
            valTab.insert(
                0,
                CDisplayListItem('--Ostatnio zaktualizowane seriale--',
                                 'Ostatnio zaktualizowane seriale',
                                 CDisplayListItem.TYPE_CATEGORY,
                                 ['http://zalukaj.tv/seriale'], 'seriale-last',
                                 '', None))
            printDBG('Host listsItems end')
            return valTab
        if 'seriale-last' == name:
            printDBG('Host listsItems begin name=' + name)
            self.MAIN_URL = 'http://zalukaj.tv'
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            phMovies = re.findall(
                '<div class="latest tooltip".*?href="(.*?)" title="(.*?)".*?src="(.*?)"',
                data, re.S)
            if phMovies:
                for (phUrl, phTitle, phImage) in phMovies:
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    printDBG('Host listsItems phImage: ' + phImage)
                    valTab.append(
                        CDisplayListItem(phTitle, phTitle,
                                         CDisplayListItem.TYPE_CATEGORY,
                                         [self.fullUrl(phUrl)],
                                         'seriale-sezon', phImage, None))
            printDBG('Host listsItems end')
            return valTab
        if 'seriale-sezony' == name:
            printDBG('Host listsItems begin name=' + name)
            self.MAIN_URL = 'http://zalukaj.tv'
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            phImage = ''
            parse = re.search('<div id="sezony".*?img src="(.*?)"', data, re.S)
            if parse: phImage = parse.group(1)
            printDBG('Host listsItems phImage: ' + phImage)
            phMovies = re.findall('<a class="sezon" href="(.*?)".*?>(.*?)<',
                                  data, re.S)
            if phMovies:
                for (phUrl, phTitle) in phMovies:
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    valTab.append(
                        CDisplayListItem(phTitle, phTitle,
                                         CDisplayListItem.TYPE_CATEGORY,
                                         [self.fullUrl(phUrl)],
                                         'seriale-sezon', phImage, None))
            printDBG('Host listsItems end')
            return valTab
        if 'seriale-sezon' == name:
            printDBG('Host listsItems begin name=' + name)
            self.MAIN_URL = 'http://zalukaj.tv'
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            phImage = ''
            parse = re.search('<img src="(.*?)"', data, re.S)
            if parse: phImage = parse.group(1)
            printDBG('Host listsItems phImage: ' + phImage)
            phMovies = re.findall(
                'id="sezony".*?>(.*?)<.*?href="(.*?)" title="(.*?)"', data,
                re.S)
            if phMovies:
                for (phEpisode, phUrl, phTitle) in phMovies:
                    printDBG('Host listsItems phEpizod: ' + phEpisode)
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    valTab.append(
                        CDisplayListItem(
                            phEpisode + ' - ' + phTitle, phTitle,
                            CDisplayListItem.TYPE_VIDEO,
                            [CUrlItem('', self.fullUrl(phUrl), 1)], 0, phImage,
                            None))
                    printDBG('Host listsItems end')
            return valTab
        if 'filmy' == name:
            printDBG('Host listsItems begin name=' + name)
            self.MAIN_URL = 'http://zalukaj.tv'
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            sts, parse = CParsingHelper.getDataBeetwenMarkers(
                data, '<table id="one"', '</table>', False)
            phMovies = re.findall(
                '<td class="wef32f"><a href="([^"]+?)">([^<]+?)</a>', parse,
                re.S)
            if phMovies:
                for (phUrl, phTitle) in phMovies:
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    valTab.append(
                        CDisplayListItem(phTitle, phTitle,
                                         CDisplayListItem.TYPE_CATEGORY,
                                         [self.fullUrl(phUrl)], 'filmy-clip',
                                         '', None))
            #valTab.insert(0,CDisplayListItem('--Najpopularniejsze--', 'Najpopularniejsze wyswietlenia-miesiac', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/#wyswietlenia-miesiac'], 'filmy-last', '', None))
            #valTab.insert(0,CDisplayListItem('--Ostatnio oglądane--', 'Ostatnio oglądane',                      CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/#lastseen'],             'filmy-last', '', None))
            valTab.insert(
                0,
                CDisplayListItem('--Ostatnio dodane--', 'Ostatnio dodane',
                                 CDisplayListItem.TYPE_CATEGORY,
                                 ['http://zalukaj.tv'], 'filmy-last', '',
                                 None))
            printDBG('Host listsItems end')
            return valTab
        if 'filmy-clip' == name:
            printDBG('Host listsItems begin name=' + name)
            self.MAIN_URL = 'http://zalukaj.tv'
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            phMovies = re.findall(
                'background-image:url(.*?);"><p><span>(.*?)</span>.*?<h3><a href="(.*?)".*?">(.*?)<.*?">(.*?)<.*?class="few_more">(.*?)<',
                data, re.S)
            if phMovies:
                for (phImage, phRok, phUrl, phTitle, phDescr,
                     phMore) in phMovies:
                    printDBG('Host listsItems phImage: ' + phImage)
                    printDBG('Host listsItems phRok: ' + phRok)
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    printDBG('Host listsItems phDescr: ' + phDescr)
                    printDBG('Host listsItems phMore: ' + phMore)
                    valTab.append(
                        CDisplayListItem(
                            phTitle, phRok + ' | ' + phMore + ' | ' +
                            decodeHtml(phDescr), CDisplayListItem.TYPE_VIDEO,
                            [CUrlItem('', phUrl, 1)], 0, phImage[1:-1], None))
            match = re.findall('class="pc_current">.*?href="(.*?)">(.*?)<',
                               data, re.S)
            if match:
                phUrl = match[-1][0]
                phTitle = match[-1][1]
                valTab.append(
                    CDisplayListItem('Strona ' + phTitle, 'Strona: ' + phUrl,
                                     CDisplayListItem.TYPE_CATEGORY,
                                     [self.fullUrl(phUrl)], name, '', None))
            printDBG('Host listsItems end')
            return valTab
        if 'filmy-last' == name:
            printDBG('Host listsItems begin name=' + name)
            self.MAIN_URL = 'http://zalukaj.tv'
            try:
                data = self.cm.getURLRequestData({
                    'url': url,
                    'use_host': False,
                    'use_cookie': False,
                    'use_post': False,
                    'return_data': True
                })
            except:
                printDBG('Host listsItems query error')
                printDBG('Host listsItems query error url:' + url)
                return valTab
            #printDBG( 'Host listsItems data: '+data )
            phMovies = re.findall(
                'class="tivief4".*?src="(.*?)".*?<h3><a href="(.*?)".*?">(.*?)<.*?">(.*?)<.*?class="few_more">(.*?)<',
                data, re.S)
            if phMovies:
                for (phImage, phUrl, phTitle, phDescr, phMore) in phMovies:
                    printDBG('Host listsItems phImage: ' + phImage)
                    printDBG('Host listsItems phUrl: ' + phUrl)
                    printDBG('Host listsItems phTitle: ' + phTitle)
                    printDBG('Host listsItems phDescr: ' + phDescr)
                    printDBG('Host listsItems phMore: ' + phMore)
                    valTab.append(
                        CDisplayListItem(
                            phTitle, phMore + ' | ' + decodeHtml(phDescr),
                            CDisplayListItem.TYPE_VIDEO,
                            [CUrlItem('', self.fullUrl(phUrl), 1)], 0, phImage,
                            None))
            printDBG('Host listsItems end')
            return valTab

        return valTab

    def getResolvedURL(self, url):
        printDBG('Host getResolvedURL begin')
        printDBG('Host getResolvedURL url: ' + url)
        videoUrl = ''
        valTab = []

        if self.PREMIUM:
            sts, data = self.cm.getPage(
                url, {
                    'use_host': True,
                    'host': self.HOST,
                    'use_cookie': True,
                    'save_cookie': False,
                    'load_cookie': True,
                    'cookiefile': self.COOKIEFILE
                })
            if sts:
                parse = re.search('/player.php.*?"', data, re.S)
                if parse:
                    printDBG('parse1p: ' + parse.group(0))
                    url2 = self.fullUrl(parse.group(0))
                    sts, data = self.cm.getPage(
                        url2, {
                            'use_host': True,
                            'host': self.HOST,
                            'use_cookie': True,
                            'save_cookie': False,
                            'load_cookie': True,
                            'cookiefile': self.COOKIEFILE,
                            'use_post': False,
                            'return_data': True
                        })
                    if sts:
                        parse = re.search('<a href="(.*?)"', data, re.S)
                        if parse:
                            printDBG('parse2p: ' + parse.group(1))
                            url2 = parse.group(1)
                            sts, data = self.cm.getPage(
                                url2, {
                                    'use_host': True,
                                    'host': self.HOST,
                                    'use_cookie': True,
                                    'save_cookie': False,
                                    'load_cookie': True,
                                    'cookiefile': self.COOKIEFILE,
                                    'use_post': False,
                                    'return_data': True
                                })
                            if sts:
                                printDBG('parse3pdata ')
                                match = re.compile("url:'(.+?)'").findall(data)
                                if len(match) > 0:
                                    printDBG('parse3p: PREMIUM: ' + match[0])
                                    linkvideo = match[0]
                                    return linkvideo
                    else:
                        printDBG('Host getResolvedURL query error premium')
                        printDBG(
                            'Host getResolvedURL query error premium url: ' +
                            url2)
                else:
                    printDBG('Host getResolvedURL query error premium')
                    printDBG('Host getResolvedURL query error premium url: ' +
                             url2)
            else:
                printDBG('Host getResolvedURL query error premium')
                printDBG('Host getResolvedURL query error premium url: ' + url)

        if url[0:30] == 'http://zalukaj.tv/zalukaj-film' or url[
                0:31] == 'http://zalukaj.tv/serial-online':
            sts, data = self.cm.getPage(url)
            if not sts:
                printDBG('Host getResolvedURL query error')
                printDBG('Host getResolvedURL query error url: ' + url)
                return ''

            parse = re.search('/player.php.*?"', data, re.S)
            if not parse: return ''
            printDBG('parse1: ' + parse.group(0))
            url2 = self.fullUrl(parse.group(0))
            sts, data = self.cm.getPage(url2)
            if not sts:
                printDBG('Host getResolvedURL query error')
                printDBG('Host getResolvedURL query error url: ' + url2)
                return ''
            parse = re.search('<a href="([^"]+?)"', data, re.S)
            if not parse:
                return ''
            printDBG('parse2: ' + parse.group(1))
            url2 = parse.group(1)
            sts, data = self.cm.getPage(url2)
            if not sts:
                return ''
            parse = re.search('iframe src="([^"]+?)" width=', data)
            if not parse:
                return ''
            ret = self.up.getVideoLink(parse.group(1))
            if ret:
                return ret
        return ''
class Host:
    currList = []
    MAIN_URL = ''
    PREMIUM = False
    konto = ''
    COOKIEFILE = ''
    HOST = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110621 Mandriva Linux/1.9.2.18-0.1mdv2010.2 (2010.2) Firefox/3.6.18'

    def __init__(self):
        printDBG( 'Host __init__ begin' )
        self.exSession = MainSessionWrapper()
        self.COOKIEFILE = GetCookieDir('scseriale.cookie')        
        self.cm = common()
        self.currList = []
        self.up = urlparser()
        self.history = CSearchHistoryHelper('wspolne')
        printDBG( 'Host __init__ end' )
        
    def setCurrList(self, list):
        printDBG( 'Host setCurrList begin' )
        self.currList = list
        printDBG( 'Host setCurrList end' )
        return 

    def getInitList(self):
        printDBG( 'Host getInitList begin' )
        ####################################
        # logowanie
        ####################################
        self.PREMIUM = self.listsItems(-1, 'zaloguj', 'zaloguj')
        ####################################
        self.currList = self.listsItems(-1, 'main-menu', 'main-menu')
        printDBG( 'Host getInitList end' )
        return self.currList

    def getListForItem(self, Index = 0, refresh = 0, selItem = None):
        printDBG( 'Host getListForItem begin' )
        valTab = []
        if len(self.currList[Index].urlItems) == 0:
           return valTab
        valTab = self.listsItems(Index, self.currList[Index].urlItems[0], self.currList[Index].urlSeparateRequest)
        self.currList = valTab
        printDBG( 'Host getListForItem end' )
        return self.currList

    def getSearchResults(self, pattern, searchType = None):
        printDBG( "Host getSearchResults begin" )
        printDBG( "Host getSearchResults pattern: " +pattern)
        valTab = []
        valTab = self.listsItems(-1, pattern, 'search')
        self.currList = valTab
        printDBG( "Host getSearchResults end" )
        return self.currList

    def listsItems(self, Index, url, name = ''):
        printDBG( 'Host listsItems begin' )
        printDBG( 'Host listsItems url: '+url )
        valTab = []
        # ########## #
        if name == 'main-menu':
           printDBG( 'Host listsItems begin name='+name )
           self.MAIN_URL = 'http://scs.pl'
           valTab.append(CDisplayListItem("Seriale wg. kategorii"+self.konto,'http://scs.pl/seriale.html', CDisplayListItem.TYPE_CATEGORY, ['http://scs.pl/seriale.html'],       'seriale-kategorie',  '', None)) 
           valTab.append(CDisplayListItem("Seriale alfabetycznie",           'http://scs.pl/seriale.html', CDisplayListItem.TYPE_CATEGORY, ['http://scs.pl/seriale.html'],       'seriale-abc',  '', None)) 
           valTab.append(CDisplayListItem("Ostatnio aktualizowane seriale",  'http://scs.pl/ostatnio_aktualizowane_seriale.html',   CDisplayListItem.TYPE_CATEGORY, ['http://scs.pl/ostatnio_aktualizowane_seriale.html'], 'seriale-last', '', None)) 
           valTab.append(CDisplayListItem('Szukaj',                          'Szukaj',                     CDisplayListItem.TYPE_SEARCH,   ['http://scs.pl/serial,szukaj.html'], 'search',       '', None)) 
           valTab.append(CDisplayListItem('Historia wyszukiwania', 'Historia wyszukiwania', CDisplayListItem.TYPE_CATEGORY, [''],   'history', '', None)) 
           printDBG( 'Host listsItems end' )
           return valTab

        # ########## #
        if 'zaloguj' == name:
           printDBG( 'Host listsItems begin name='+name )
           if config.plugins.iptvplayer.scserialePREMIUM.value:
              url = 'http://scs.pl/logowanie.html'
              try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': True, 'load_cookie': False, 'cookiefile': self.COOKIEFILE, 'use_post': True, 'return_data': True },{'email': config.plugins.iptvplayer.scseriale_login.value, 'password': config.plugins.iptvplayer.scseriale_password.value})
              except:
                 printDBG( 'Host listsItems query error' )
                 printDBG( 'Host listsItems query error url:'+url )
                 printDBG( 'Host listsItems query error: Uzywam Player z limitami')
                 data = None
              if data:
                 self.PREMIUM = True
                 printDBG( 'Host listsItems: chyba zalogowano do premium...' )
                 url = 'http://scs.pl/premium.html'
                 try: 
                    data = self.cm.getURLRequestData({ 'url': url, 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': False, 'return_data': True })
                    printDBG( 'Host listsItems data: '+data )
                    parse = re.search('Konto premium ważne do(.*?)".*?;(.*?)<', data, re.S)
                    if parse:
                       self.konto = ' - Twoje konto: '+parse.group(2)+parse.group(1)
                    else: 
                       self.konto = ''
                 except:
                    printDBG( 'Host listsItems: blad pobrania danych o koncie premium' )
                 
              if '' == self.konto:
                 self.exSession.open(MessageBox, 'Problem z zalogowaniem użytkownika \n"%s" jako VIP.' % config.plugins.iptvplayer.scseriale_login.value, type = MessageBox.TYPE_INFO, timeout = 10)
                 
           printDBG( 'Host listsItems end' )
           return self.PREMIUM

        # ########## #
        if 'history' == name:
           printDBG( 'Host listsItems begin name='+name )
           for histItem in self.history.getHistoryList():
               valTab.append(CDisplayListItem(histItem['pattern'], 'Szukaj ', CDisplayListItem.TYPE_CATEGORY, [histItem['pattern'],histItem['type']], 'search', '', None))          
           printDBG( 'Host listsItems end' )
           return valTab

        # ########## #
        if 'search' == name:
           printDBG( 'Host listsItems begin name='+name )
           pattern = url            
           if Index==-1: 
              self.history.addHistoryItem( pattern, 'seriale')
           url = 'http://scs.pl/serial,szukaj.html'
           postdata = { 'search': pattern }
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': True, 'return_data': True },postdata)
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           match = re.findall('<div class="img_box"><a href="(.*?)">.*?<img src="(.*?)" alt="(.*?)"', data, re.S)
           if len(match) > 0:
              for i in range(len(match)):
                  phImage = match[i][1]
                  phUrl = self.MAIN_URL+'/'+ match[i][0]
                  phTitle = match[i][2]
                  printDBG( 'Host listsItems phImage: '  +phImage )
                  printDBG( 'Host listsItems phUrl: '    +phUrl )
                  printDBG( 'Host listsItems phTitle: '  +phTitle )
                  valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [phUrl], 'seriale-sezony', phImage, None))
           printDBG( 'Host listsItems end' )
           return valTab
           
        # ########## #
        if 'seriale-last' == name:
           printDBG( 'Host listsItems begin name='+name )
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           match = re.compile('online">(.+?)</a></div></div><span class="newest_ep" id=".+?">Ostatnio dodany:<br/><a href="odcinek,(.+?),(.+?),(.+?),(.+?).html">').findall(data)
           if len(match) > 0:
              for i in range(len(match)):
                  phImage='http://static.scs.pl/static/serials/' + match[i][1].replace('.html', '.jpg')+'.jpg'
                  phTitleS = match[i][1]
                  phTitle = match[i][0] + ' - ' + match[i][4] + ' - ' + match[i][2].capitalize().replace('-', ' ')
                  phUrlS = self.MAIN_URL + '/serial,' + match[i][0]
                  phUrl = self.MAIN_URL + '/odcinek,' + match[i][1] + ',' + match[i][2] + ',' + match[i][3] + ',' + match[i][4] + '.html'
                  printDBG( 'Host listsItems phImage: '  +phImage )
                  printDBG( 'Host listsItems phUrl: '  +phUrl )
                  printDBG( 'Host listsItems phTitle: '+phTitle )
                  valTab.append(CDisplayListItem(phTitleS, phTitleS, CDisplayListItem.TYPE_CATEGORY, [phUrlS], 'seriale-sezony', phImage, None))
                  valTab.append(CDisplayListItem(phTitle,  phTitle,  CDisplayListItem.TYPE_VIDEO, [CUrlItem('', phUrl, 1)], 0, phImage, None))
           printDBG( 'Host listsItems end' )
           return valTab
        if 'seriale-kategorie' == name:
           printDBG( 'Host listsItems begin name='+name )
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           phMovies = re.findall('<span class="title1">(.*?)</span>(.*?)<.*?href="(.*?)"', data, re.S)
           if phMovies:
              for (phTitle, phCount, phUrl) in phMovies:
                  printDBG( 'Host listsItems phTitle: '+phTitle )
                  printDBG( 'Host listsItems phCount: '+phCount )
                  printDBG( 'Host listsItems phUrl: '  +phUrl )
                  valTab.append(CDisplayListItem(phTitle+phCount, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.MAIN_URL+'/'+phUrl], 'seriale-kategoria', '', None))          
           printDBG( 'Host listsItems end' )
           return valTab
        if 'seriale-kategoria' == name:
           printDBG( 'Host listsItems begin name='+name )
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           match = re.compile('class="serial_green" href="serial,(.+?)">(.+?)</a><br/>').findall(data)
           if len(match) > 0:
              for i in range(len(match)):
                  phImage='http://static.scs.pl/static/serials/' + match[i][0].replace('.html', '.jpg')
                  phTitle = match[i][1]
                  phUrl = self.MAIN_URL + '/serial,' + match[i][0]
                  printDBG( 'Host listsItems phImage: '  +phImage )
                  printDBG( 'Host listsItems phUrl: '  +phUrl )
                  printDBG( 'Host listsItems phTitle: '+phTitle )
                  valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [phUrl], 'seriale-sezony', phImage, None))
           printDBG( 'Host listsItems end' )
           return valTab
        if 'seriale-abc' == name:
           printDBG( 'Host listsItems begin name='+name )
           abcTab = self.cm.makeABCList()
           for i in range(len(abcTab)):
               phTitle = abcTab[i]
               valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [url,phTitle], 'seriale-alfabet', '', None))          
           printDBG( 'Host listsItems end' )
           return valTab
        if 'seriale-alfabet' == name:
           printDBG( 'Host listsItems begin name='+name )
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           letter = self.currList[Index].urlItems[1]
           match = re.compile(' <a class="serial_green" href="serial,(.+?)">(.+?)</a><br/>').findall(data)
           if len(match) > 0:
              for i in range(len(match)):
                addItem = False
                if letter == '0 - 9' and (ord(match[i][1][0]) < 65 or ord(match[i][1][0]) > 91): addItem = True
                if (letter == match[i][1][0].upper()): addItem = True
                if (addItem):
                    phImage='http://static.scs.pl/static/serials/' + match[i][0].replace('.html', '.jpg')
                    phTitle = match[i][1]
                    phUrl = self.MAIN_URL + '/serial,' + match[i][0]
                    printDBG( 'Host listsItems phImage: '  +phImage )
                    printDBG( 'Host listsItems phUrl: '  +phUrl )
                    printDBG( 'Host listsItems phTitle: '+phTitle )
                    valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [phUrl], 'seriale-sezony', phImage, None))          
           printDBG( 'Host listsItems end' )
           return valTab
        if 'seriale-sezony' == name:
           printDBG( 'Host listsItems begin name='+name )
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           phMovies = re.compile('<meta itemprop="seasonNumber" content="(.+?)">').findall(data)
           if phMovies:
              phImage=url.replace(self.MAIN_URL + '/serial,', 'http://static.scs.pl/static/serials/').replace('.html', '.jpg')
              printDBG( 'Host listsItems phImage: '+phImage )
              for (phTitle) in phMovies:
                  printDBG( 'Host listsItems phTitle: '+phTitle )
                  valTab.append(CDisplayListItem('Sezon '+phTitle, 'Sezon '+phTitle, CDisplayListItem.TYPE_CATEGORY, [url,phTitle], 'seriale-odcinki', phImage, None))          
           printDBG( 'Host listsItems end' )
           return valTab
        if 'seriale-odcinki' == name:
           printDBG( 'Host listsItems begin name='+name )
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           sezon = self.currList[Index].urlItems[1]
           r = re.compile('<meta itemprop="seasonNumber" content="' + sezon + '">(.+?)</ul></div>', re.DOTALL).findall(data)
           if not r: return []
           phMovies = re.compile('itemprop="episodeNumber">(.+?)<.+?class="aLink " href="(odcinek,.+?,.+?,.+?,.+?.html)"><span itemprop="name">(.+?)</span></a>').findall(r[0])
           if phMovies:
              phImage=url.replace(self.MAIN_URL + '/serial,', 'http://static.scs.pl/static/serials/').replace('.html', '.jpg')
              serial=url.replace(self.MAIN_URL + '/serial,','').replace('.html', '')
              printDBG( 'Host listsItems phImage: '+phImage )
              for (phEpizod, phUrl, phName) in phMovies:
                  printDBG( 'Host listsItems phEpizod: '+phEpizod )
                  printDBG( 'Host listsItems phUrl: '+phUrl )
                  phTitle = '%s S%sE%s - %s' % (serial, sezon, phEpizod, phName)
                  printDBG( 'Host listsItems phTitle: '+phTitle )
                  valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.MAIN_URL+'/'+phUrl,phTitle], 'seriale-odcinki-wersje', phImage, None))          
           printDBG( 'Host listsItems end' )
           return valTab
        if 'seriale-odcinki-wersje' == name:
           printDBG( 'Host listsItems begin name='+name )
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           parse = re.search('Wersje:(.*?)Kopie:', data, re.S)
           if not parse: return []
           phMovies = re.findall('<a href="(.+?)">(.+?)<', parse.group(1), re.S)           
           if phMovies:
              phImage=url.replace(self.MAIN_URL + '/serial,', 'http://static.scs.pl/static/serials/').replace('.html', '.jpg')
              printDBG( 'Host listsItems phImage: '+phImage )
              for (phUrl, phWersja) in phMovies:
                  printDBG( 'Host listsItems phUrl: '+phUrl )
                  printDBG( 'Host listsItems phWersja: '+phWersja )
                  valTab.append(CDisplayListItem(phWersja, phWersja, CDisplayListItem.TYPE_CATEGORY, [self.MAIN_URL+'/'+phUrl], 'seriale-odcinki-kopie', phImage, None))          
           printDBG( 'Host listsItems end' )
           return valTab
        if 'seriale-odcinki-kopie' == name:
           printDBG( 'Host listsItems begin name='+name )
           try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
           except:
              printDBG( 'Host listsItems query error' )
              printDBG( 'Host listsItems query error url:'+url )
              return valTab
           #printDBG( 'Host listsItems data: '+data )
           parse = re.search('class="mirrors"(.*?)class="switch"', data, re.S)
           if not parse: return []
           phMovies = re.findall('= "(.+?)"; ccc.+?;.+?"(.+?)";.+?"(.+?)";.+?"(.+?)";', parse.group(1), re.S)           
           if phMovies:
              for (phUrl, phTime, phUser, phComment) in phMovies:
                  printDBG( 'Host listsItems phUrl: '+phUrl )
                  printDBG( 'Host listsItems phTime: '+phTime )
                  printDBG( 'Host listsItems phUser: '******' '+phUser, phTime+' '+phUser+' '+phComment, CDisplayListItem.TYPE_VIDEO, [CUrlItem('', phUrl, 1)], 0, '', None))          
           printDBG( 'Host listsItems end' )
           return valTab

        return valTab

    def getResolvedURL(self, url):
        printDBG( 'Host getResolvedURL begin' )
        printDBG( 'Host getResolvedURL url: '+url )
        postdata = {'f' : url }
        if self.PREMIUM:
           query_data = { 'url': 'http://scs.pl/getVideo.html', 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': True, 'return_data': True }
        else: 
           query_data = { 'url': 'http://scs.pl/getVideo.html', 'use_host': False, 'use_cookie': False, 'use_post': True, 'return_data': True }
        try: data = self.cm.getURLRequestData(query_data, postdata)
        except:
           printDBG( 'Host getResolvedURL query error premium' )
           printDBG( 'Host getResolvedURL query error premium url: '+url )
           return ''
        #printDBG( 'Host getResolvedURL premium data: ' +data)
        match = re.compile("url: '(.+?)',").findall(data)
        if len(match) > 0:
           linkVideo = match[0]
           printDBG( 'Host getResolvedURL linkVideo: ' + linkVideo)
           printDBG( 'Host getResolvedURL end premium' )
           return linkVideo
        printDBG( 'Host getResolvedURL end' )
        return ''