Esempio n. 1
0
def getTrakt(url, post=None):
    try:
        trakt_base = 'http://api-v2launch.trakt.tv'
        headers = {
            'Content-Type':
            'application/json',
            'trakt-api-key':
            base64.urlsafe_b64decode(
                'ZWI0MWU5NTI0M2Q4Yzk1MTUyZWQ3MmExZmMwMzk0YzkzY2I3ODVjYjMzYWVkNjA5ZmRkZTFhMDc0NTQ1ODRiNA=='
            ),
            'trakt-api-version':
            '2'
        }
        user, password = getTraktCredentials()
        token = cache.get(authTrakt,
                          24,
                          urlparse.urljoin(trakt_base, '/auth/login'),
                          json.dumps({
                              'login': user,
                              'password': password
                          }),
                          headers,
                          table='rel_trakt')
        headers.update({'trakt-user-login': user, 'trakt-user-token': token})
    except:
        pass
    try:
        if not post == None: post = json.dumps(post)
        result = client.request(urlparse.urljoin(trakt_base, url),
                                post=post,
                                headers=headers)
        return result
    except:
        pass
Esempio n. 2
0
def syncMovies(timeout=0):
    try:
        user, password = getTraktCredentials()
        return cache.get(getTrakt,
                         timeout,
                         '/users/%s/watched/movies' % user,
                         table='rel_trakt')
    except:
        pass
Esempio n. 3
0
def syncTVShows(timeout=0):
    try:
        user, password = getTraktCredentials()
        return cache.get(getTrakt,
                         timeout,
                         '/users/%s/watched/shows?extended=full' % user,
                         table='rel_trakt')
    except:
        pass
Esempio n. 4
0
def getHosts():
    try:
        user, password = getCredentials()
        url = 'http://api.premiumize.me/pm-api/v1.php?method=hosterlist&params[login]=%s&params[pass]=%s' % (user, password)
        result = cache.get(client.request, 24, url)
        hosts = json.loads(result)['result']['hosterlist']
        hosts = [i.rsplit('.' ,1)[0].lower() for i in hosts]
        return hosts
    except:
        return []
Esempio n. 5
0
def getHosts():
    try:
        user, password = getCredentials()
        url = 'http://real-debrid.com/api/hosters.php'
        result = cache.get(client.request, 24, url)
        hosts = json.loads('[%s]' % result)
        hosts = [i.rsplit('.' ,1)[0].lower() for i in hosts]
        return hosts
    except:
        return []
Esempio n. 6
0
def getHosts():
    try:
        user, password = getCredentials()
        url = 'http://real-debrid.com/api/hosters.php'
        result = cache.get(client.request, 24, url)
        hosts = json.loads('[%s]' % result)
        hosts = [i.rsplit('.', 1)[0].lower() for i in hosts]
        return hosts
    except:
        return []
Esempio n. 7
0
def getHosts():
    try:
        user, password = getCredentials()
        url = 'http://api.premiumize.me/pm-api/v1.php?method=hosterlist&params[login]=%s&params[pass]=%s' % (user, password)
        result = cache.get(client.request, 24, url)
        hosts = json.loads(result)['result']['hosterlist']
        hosts = [i.rsplit('.' ,1)[0].lower() for i in hosts]
        return hosts
    except:
        return []
Esempio n. 8
0
def getSearch():
    addDirectoryItem('Search...', '0', 'searchDirectory', '0', '0', '0', '0', '0', {})
    addDirectoryItem('Clear History', '0', 'clearSearch', '0', '0', '0', '0', '0', {})

    try:
        def search(): return
        result = cache.get(search, 600000000, table='rel_srch')
        for q in result:
                try: addDirectoryItem('%s...' % q, q, 'searchDirectory2', '0', '0', '0', '0', '0', {})
                except: pass
    except:
        pass

    control.directory(int(sys.argv[1]), cacheToDisc=True)
Esempio n. 9
0
def getTrakt(url, post=None):
    try:
        trakt_base = 'http://api-v2launch.trakt.tv'
        headers = {'Content-Type': 'application/json', 'trakt-api-key': base64.urlsafe_b64decode('ZWI0MWU5NTI0M2Q4Yzk1MTUyZWQ3MmExZmMwMzk0YzkzY2I3ODVjYjMzYWVkNjA5ZmRkZTFhMDc0NTQ1ODRiNA=='), 'trakt-api-version': '2'}
        user, password = getTraktCredentials()
        token = cache.get(authTrakt, 24, urlparse.urljoin(trakt_base, '/auth/login'), json.dumps({'login': user, 'password': password}), headers, table='rel_trakt')
        headers.update({'trakt-user-login': user, 'trakt-user-token': token})
    except:
        pass
    try:
        if not post == None: post = json.dumps(post)
        result = client.request(urlparse.urljoin(trakt_base, url), post=post, headers=headers)
        return result
    except:
        pass
Esempio n. 10
0
def getSearch():
    addDirectoryItem('Search...', '0', 'searchDirectory', '0', '0', '0', '0',
                     '0', {})
    addDirectoryItem('Clear History', '0', 'clearSearch', '0', '0', '0', '0',
                     '0', {})

    try:

        def search():
            return

        result = cache.get(search, 600000000, table='rel_srch')
        for q in result:
            try:
                addDirectoryItem('%s...' % q, q, 'searchDirectory2', '0', '0',
                                 '0', '0', '0', {})
            except:
                pass
    except:
        pass

    control.directory(int(sys.argv[1]), cacheToDisc=True)
Esempio n. 11
0
def searchDirectory(query=None):
    if (query == None or query == ''):
        keyboard = control.keyboard('', 'Search')
        keyboard.doModal()
        if not (keyboard.isConfirmed()): return
        query = keyboard.getText()

    if (query == None or query == ''): return

    def search():
        return [query]

    result = cache.get(search, 600000000, table='rel_srch')

    def search():
        return [
            x for y, x in enumerate((result + [query]))
            if x not in (result + [query])[:y]
        ]

    result = cache.get(search, 0, table='rel_srch')

    global global_search
    global_search = []

    def worker(url):
        global_search.append(str(client.request(url)))

    servers = client.request(phLink)
    servers = str(servers).replace('\n', '')
    servers = re.findall('</name><link>(.+?)</link>', servers)
    servers = [urlparse.urlparse(i).netloc for i in servers]
    servers = [phSearch % i for i in servers if not 'mecca' in i]

    threads = []
    for server in servers:
        threads.append(Thread(worker, server))
    [i.start() for i in threads]
    [i.join() for i in threads]

    urls = global_search
    global_search = []
    urls = [str(i).replace('\n', '') for i in urls]
    urls = [re.findall('<link>(.+?)</link>', i)[:30] for i in urls]
    urls = sum(urls, [])

    threads = []
    for url in urls:
        threads.append(Thread(worker, url))
    [i.start() for i in threads]
    [i.join() for i in threads]

    links = global_search
    global_search = []

    for link in links:
        try:
            link = str(link).replace('\r', '').replace('\n', '').replace(
                '\t', '').replace('&nbsp;', '')

            try:
                fanart = re.findall('<fanart>(.+?)</fanart>', link)[0]
            except:
                fanart = '0'

            try:
                vip = re.findall('<poster>(.+?)</poster>', link)[0]
            except:
                vip = ''

            if vip == 'Team Phoenix': vip = ''

            try:
                content = re.findall('<meta>(.+?)</meta>', link)[0]
            except:
                content = '0'

            try:
                tvshow = re.findall('<tvshow>(.+?)</tvshow>', link)[0]
            except:
                tvshow = '0'

            if content in ['seasons', 'episodes'] and tvshow == '0':
                content = '0'

            dirs = re.compile('<dir>(.+?)</dir>').findall(link)

            for dir in dirs:
                try:
                    data = {}

                    name = re.findall('<name>(.+?)</name>', dir)[0]
                    name = cleantitle(name)

                    if not query.lower() in name.lower(): raise Exception()

                    url = re.findall('<link>(.+?)</link>', dir)[0]

                    try:
                        image = re.findall('<thumbnail>(.+?)</thumbnail>',
                                           dir)[0]
                    except:
                        image = '0'

                    try:
                        fanart2 = re.findall('<fanart>(.+?)</fanart>', dir)[0]
                    except:
                        fanart2 = fanart

                    if content == 'tvshows':
                        try:
                            title = cleantitle(name).encode('utf-8')
                            data = {'title': title, 'tvshowtitle': title}
                        except:
                            pass

                    if re.search('[a-zA-Z]', vip):
                        name += ' [COLOR orange]%s[/COLOR]' % vip

                    addDirectoryItem(name, url, 'ndmode', image, image,
                                     fanart2, '0', content, data)
                except:
                    pass

            items = re.compile('<item>(.+?)</item>').findall(link)

            for item in items:
                try:

                    data = {}

                    name = re.findall('<title>(.+?)</title>', item)[0]
                    name = cleantitle(name)

                    if not query.lower() in name.lower(): raise Exception()

                    url = re.findall('<link>(.+?)</link>', item)[0]

                    try:
                        image = re.findall('<thumbnail>(.+?)</thumbnail>',
                                           item)[0]
                    except:
                        image = '0'

                    try:
                        fanart2 = re.findall('<fanart>(.+?)</fanart>', item)[0]
                    except:
                        fanart2 = fanart

                    if content == 'movies':
                        try:
                            title = cleantitle(name).encode('utf-8')
                            data = {'title': title}

                            title, year = re.compile(
                                '(.+?)[(](\d{4})[)]').findall(name)[0]
                            title = cleantitle(title).encode('utf-8')
                            data = {'title': title, 'year': year}
                        except:
                            pass

                    if re.search('[a-zA-Z]', vip):
                        name += ' [COLOR orange]%s[/COLOR]' % vip

                    if 'sublink' in url:
                        addDirectoryItem(name,
                                         url,
                                         'subDirectory',
                                         image,
                                         image,
                                         fanart2,
                                         '0',
                                         content,
                                         data,
                                         isFolder=True)
                    else:
                        addDirectoryItem(name,
                                         url,
                                         'resolveUrl',
                                         image,
                                         image,
                                         fanart2,
                                         '0',
                                         content,
                                         data,
                                         isFolder=False)
                except:
                    pass
        except:
            pass

    control.directory(int(sys.argv[1]), cacheToDisc=True)
Esempio n. 12
0
def getDirectory(name,
                 url,
                 audio,
                 image,
                 fanart,
                 playable,
                 content,
                 close=True):
    result = cache.get(client.request, 0, url)
    result = str(result).replace('\r', '').replace('\n', '').replace(
        '\t', '').replace('&nbsp;', '')

    try:
        fanart = re.findall('<fanart>(.+?)</fanart>', result)[0]
    except:
        fanart = '0'

    try:
        notify = re.compile('<notify>(.+?)</notify>').findall(result)[0]

        vip = re.findall('<poster>(.+?)</poster>', result)[0]
        if not re.search('[a-zA-Z]', vip): raise Exception()

        def message(vip):
            return (vip + version)

        check = cache.get(message, 600000000, vip, table='rel_vip')

        version = re.findall('<new>(.+?)</new>', notify)[0]
        if not version.isdigit(): raise Exception()

        if check == (vip + version): raise Exception()

        title = '[B]Announcement From %s![/B]' % vip
        msg1 = re.findall('<message1>(.+?)</message1>', notify)[0]
        msg2 = re.findall('<message2>(.+?)</message2>', notify)[0]
        msg3 = re.findall('<message3>(.+?)</message3>', notify)[0]

        check = cache.get(message, 0, vip, table='rel_vip')

        control.dialog.ok(str(title), str(msg1), str(msg2), str(msg3))
    except:
        pass

    infos = re.compile('<info>(.+?)</info>').findall(result)

    for info in infos:
        try:
            name = re.findall('<message>(.+?)</message>', info)[0]

            try:
                image = re.findall('<thumbnail>(.+?)</thumbnail>', info)[0]
            except:
                image = '0'

            addDirectoryItem(name, '0', '0', image, image, fanart, '0', '0',
                             {})
        except:
            pass

    popups = re.compile('<popup>(.+?)</popup>').findall(result)

    for popup in popups:
        try:
            name = re.findall('<name>(.+?)</name>', popup)[0]

            url = re.findall('<popImage>(.+?)</popImage>', popup)[0]

            try:
                image = re.findall('<thumbnail>(.+?)</thumbnail>', popup)[0]
            except:
                image = '0'

            try:
                audio = re.findall('<sound>(.+?)</sound>', popup)[0]
            except:
                audio = '0'

            addDirectoryItem(name, url, 'openDialog', image, image, fanart,
                             audio, '0', {})
        except:
            pass

    special = re.compile(
        '<name>([^<]+)</name><link>([^<]+)</link><thumbnail>([^<]+)</thumbnail><date>([^<]+)</date>'
    ).findall(result)
    for name, url, image, date in special:
        if re.search(r'\d+', date):
            name += ' [COLOR red] Updated %s[/COLOR]' % date
        addDirectoryItem(name, url, 'ndmode', image, image, fanart, '0', '0',
                         {})

    special = re.compile(
        '<name>([^<]+)</name><link>([^<]+)</link><thumbnail>([^<]+)</thumbnail><mode>([^<]+)</mode>'
    ).findall(result)
    for name, url, image, action in special:
        addDirectoryItem(name, url, action, image, image, fanart, '0', '0', {})

    meta = False

    try:
        content = re.findall('<meta>(.+?)</meta>', result)[0]
    except:
        content = '0'

    try:
        tvshow = re.findall('<tvshow>(.+?)</tvshow>', result)[0]
    except:
        tvshow = '0'

    if content in ['seasons', 'episodes'] and tvshow == '0':
        content = '0'

    if content in ['movies', 'tvshows'] and control.setting('meta') == 'true':
        try:
            from metahandler import metahandlers
            metaget = metahandlers.MetaData(preparezip=False)
            meta = True
        except:
            meta = False

    elif content in ['seasons', 'episodes']:
        try:
            from metahandler import metahandlers
            metaget = metahandlers.MetaData(preparezip=False)
            #tvd = metaget.get_meta('tvshow', tvshow)
            tvd = cachemeta.get(metaget.get_meta, 24, 'tvshow', tvshow, '', '',
                                '')
        except:
            tvd = {}

    dirs = re.compile('<dir>(.+?)</dir>').findall(result)

    totalItems = len(dirs)

    for dir in dirs:
        try:
            data = {}

            name = re.findall('<name>(.+?)</name>', dir)[0]

            url = re.findall('<link>(.+?)</link>', dir)[0]

            try:
                image = re.findall('<thumbnail>(.+?)</thumbnail>', dir)[0]
            except:
                image = '0'

            try:
                fanart2 = re.findall('<fanart>(.+?)</fanart>', dir)[0]
            except:
                fanart2 = fanart

            if meta == True and content == 'tvshows':
                try:
                    title = cleantitle(name).encode('utf-8')
                    data = {'title': title, 'tvshowtitle': title}

                    #data = metaget.get_meta('tvshow', title)
                    data = cachemeta.get(metaget.get_meta, 24, 'tvshow', title,
                                         '', '', '')

                    metafanart = data['backdrop_url']
                    if not metafanart == '': fanart2 = metafanart
                except:
                    pass

            elif content == 'tvshows':
                try:
                    title = cleantitle(name).encode('utf-8')
                    data = {'title': title, 'tvshowtitle': title}
                except:
                    pass

            elif content == 'seasons':
                try:
                    title = cleantitle(tvshow).encode('utf-8')
                    data = {'title': title, 'tvshowtitle': title}

                    data.update(tvd)

                    metafanart = tvd['backdrop_url']
                    if not metafanart == '': fanart2 = metafanart
                except:
                    pass

            addDirectoryItem(name,
                             url,
                             'ndmode',
                             image,
                             image,
                             fanart2,
                             '0',
                             content,
                             data,
                             totalItems=totalItems)
        except:
            pass

    items = re.compile('<item>(.+?)</item>').findall(result)

    try:
        sort = re.findall('<sort>(.+?)</sort>', result)[0]
    except:
        sort = ''
    if sort == 'yes': items = sorted(items)
    totalItems = len(items)

    for item in items:
        try:

            data = {}

            name = re.findall('<title>(.+?)</title>', item)[0]

            url = re.findall('<link>(.+?)</link>', item)[0]

            try:
                image = image2 = re.findall('<thumbnail>(.+?)</thumbnail>',
                                            item)[0]
            except:
                image = image2 = '0'

            try:
                fanart2 = re.findall('<fanart>(.+?)</fanart>', item)[0]
            except:
                fanart2 = fanart

            if meta == True and content == 'movies':
                try:
                    title = cleantitle(name).encode('utf-8')
                    data = {'title': title}

                    title, year = re.compile('(.+?)[(](\d{4})[)]').findall(
                        name)[0]
                    title = cleantitle(title).encode('utf-8')
                    data = {'title': title, 'year': year}

                    #data = metaget.get_meta('movie', title, year=year)
                    data = cachemeta.get(metaget.get_meta, 24, 'movie', title,
                                         '', '', year)

                    metaimage = data['cover_url']
                    if not metaimage == '': image = metaimage
                    metafanart = data['backdrop_url']
                    if not metafanart == '': fanart2 = metafanart
                except:
                    pass

            elif content == 'movies':
                try:
                    title = cleantitle(name).encode('utf-8')
                    data = {'title': title}

                    title, year = re.compile('(.+?)[(](\d{4})[)]').findall(
                        name)[0]
                    title = cleantitle(title).encode('utf-8')
                    data = {'title': title, 'year': year}
                except:
                    pass

            elif content == 'episodes':
                try:
                    title = cleantitle(name).encode('utf-8')
                    data = {'title': title, 'tvshowtitle': tvshow}
                except:
                    pass
                try:
                    i = cleaneptitle(tvshow, title)
                    title, season, episode = i[0].encode('utf-8'), i[1], i[2]
                    data = {
                        'title': title,
                        'tvshowtitle': tvshow,
                        'season': season,
                        'episode': episode
                    }
                except:
                    pass
                try:
                    data.update({
                        'year': tvd['year'],
                        'imdb_id': tvd['imdb_id'],
                        'tvdb_id': tvd['tvdb_id'],
                        'tvshowtitle': tvd['TVShowTitle'],
                        'genre': tvd['genre'],
                        'studio': tvd['studio'],
                        'status': tvd['status'],
                        'duration': tvd['duration'],
                        'rating': tvd['rating'],
                        'mpaa': tvd['mpaa'],
                        'plot': tvd['plot'],
                        'cast': tvd['cast']
                    })

                    metafanart = tvd['backdrop_url']
                    if not metafanart == '': image = fanart2 = metafanart
                except:
                    pass

            if 'sublink' in url:
                addDirectoryItem(name,
                                 url,
                                 'subDirectory',
                                 image,
                                 image2,
                                 fanart2,
                                 '0',
                                 content,
                                 data,
                                 tvshow=tvshow,
                                 totalItems=totalItems,
                                 isFolder=True)
            else:
                addDirectoryItem(name,
                                 url,
                                 'resolveUrl',
                                 image,
                                 image2,
                                 fanart2,
                                 '0',
                                 content,
                                 data,
                                 totalItems=totalItems,
                                 isFolder=False)
        except:
            pass

    endDirectory(content, close)
Esempio n. 13
0
def syncTVShows(timeout=0):
    try:
        user, password = getTraktCredentials()
        return cache.get(getTrakt, timeout, '/users/%s/watched/shows?extended=full' % user, table='rel_trakt')
    except:
        pass
Esempio n. 14
0
def syncMovies(timeout=0):
    try:
        user, password = getTraktCredentials()
        return cache.get(getTrakt, timeout, '/users/%s/watched/movies' % user, table='rel_trakt')
    except:
        pass
Esempio n. 15
0
def getDirectory(name, url, audio, image, fanart, playable, content, close=True):
    result = cache.get(client.request, 0, url)
    result = str(result).replace('\r','').replace('\n','').replace('\t','').replace('&nbsp;','')

    try: fanart = re.findall('<fanart>(.+?)</fanart>', result)[0]
    except: fanart = '0'


    try:
        notify = re.compile('<notify>(.+?)</notify>').findall(result)[0]

        vip = re.findall('<poster>(.+?)</poster>', result)[0]
        if not re.search('[a-zA-Z]', vip): raise Exception()

        def message(vip): return (vip+version)

        check = cache.get(message, 600000000, vip, table='rel_vip')

        version = re.findall('<new>(.+?)</new>', notify)[0]
        if not version.isdigit(): raise Exception()

        if check == (vip+version): raise Exception()

        title = '[B]Announcement From %s![/B]' % vip
        msg1 = re.findall('<message1>(.+?)</message1>', notify)[0]
        msg2 = re.findall('<message2>(.+?)</message2>', notify)[0]
        msg3 = re.findall('<message3>(.+?)</message3>', notify)[0]

        check = cache.get(message, 0, vip, table='rel_vip')

        control.dialog.ok(str(title), str(msg1), str(msg2), str(msg3))
    except:
        pass


    infos = re.compile('<info>(.+?)</info>').findall(result)

    for info in infos:
        try:
            name = re.findall('<message>(.+?)</message>', info)[0]

            try: image = re.findall('<thumbnail>(.+?)</thumbnail>', info)[0]
            except: image = '0'

            addDirectoryItem(name, '0', '0', image, image, fanart, '0', '0', {})
        except:
            pass


    popups = re.compile('<popup>(.+?)</popup>').findall(result)

    for popup in popups:
        try:
            name = re.findall('<name>(.+?)</name>', popup)[0]

            url = re.findall('<popImage>(.+?)</popImage>', popup)[0]

            try: image = re.findall('<thumbnail>(.+?)</thumbnail>', popup)[0]
            except: image = '0'

            try: audio = re.findall('<sound>(.+?)</sound>', popup)[0]
            except: audio = '0'

            addDirectoryItem(name, url, 'openDialog', image, image, fanart, audio, '0', {})
        except:
            pass


    special = re.compile('<name>([^<]+)</name><link>([^<]+)</link><thumbnail>([^<]+)</thumbnail><date>([^<]+)</date>').findall(result)
    for name, url, image, date in special:
        if re.search(r'\d+', date): name += ' [COLOR red] Updated %s[/COLOR]' % date
        addDirectoryItem(name, url, 'ndmode', image, image, fanart, '0', '0', {})

    special = re.compile('<name>([^<]+)</name><link>([^<]+)</link><thumbnail>([^<]+)</thumbnail><mode>([^<]+)</mode>').findall(result)
    for name, url, image, action in special:
        addDirectoryItem(name, url, action, image, image, fanart, '0', '0', {})



    meta = False

    try: content = re.findall('<meta>(.+?)</meta>', result)[0]
    except: content = '0'

    try: tvshow = re.findall('<tvshow>(.+?)</tvshow>', result)[0]
    except: tvshow = '0'

    if content in ['seasons', 'episodes'] and tvshow == '0':
        content = '0'

    if content in ['movies', 'tvshows'] and control.setting('meta') == 'true':
        try:
            from metahandler import metahandlers
            metaget = metahandlers.MetaData(preparezip=False)
            meta = True
        except:
            meta = False

    elif content in ['seasons', 'episodes']:
        try:
            from metahandler import metahandlers
            metaget = metahandlers.MetaData(preparezip=False)
            #tvd = metaget.get_meta('tvshow', tvshow)
            tvd = cachemeta.get(metaget.get_meta, 24, 'tvshow', tvshow, '', '', '')
        except:
            tvd = {}


    dirs = re.compile('<dir>(.+?)</dir>').findall(result)

    totalItems = len(dirs)

    for dir in dirs:
        try:
            data = {}

            name = re.findall('<name>(.+?)</name>', dir)[0]

            url = re.findall('<link>(.+?)</link>', dir)[0]

            try: image = re.findall('<thumbnail>(.+?)</thumbnail>', dir)[0]
            except: image = '0'

            try: fanart2 = re.findall('<fanart>(.+?)</fanart>', dir)[0]
            except: fanart2 = fanart

            if meta == True and content =='tvshows':
                try:
                    title = cleantitle(name).encode('utf-8')
                    data = {'title': title, 'tvshowtitle': title}

                    #data = metaget.get_meta('tvshow', title)
                    data = cachemeta.get(metaget.get_meta, 24, 'tvshow', title, '', '', '')

                    metafanart = data['backdrop_url']
                    if not metafanart == '': fanart2 = metafanart
                except:
                    pass

            elif content =='tvshows':
                try:
                    title = cleantitle(name).encode('utf-8')
                    data = {'title': title, 'tvshowtitle': title}
                except:
                    pass

            elif content =='seasons':
                try:
                    title = cleantitle(tvshow).encode('utf-8')
                    data = {'title': title, 'tvshowtitle': title}

                    data.update(tvd)

                    metafanart = tvd['backdrop_url']
                    if not metafanart == '': fanart2 = metafanart
                except:
                    pass

            addDirectoryItem(name, url, 'ndmode', image, image, fanart2, '0', content, data, totalItems=totalItems)
        except:
            pass

    items = re.compile('<item>(.+?)</item>').findall(result)

    try: sort = re.findall('<sort>(.+?)</sort>', result)[0]
    except: sort = ''
    if sort == 'yes': items = sorted(items)
    totalItems = len(items)

    for item in items:
        try:

            data = {}

            name = re.findall('<title>(.+?)</title>', item)[0]

            url = re.findall('<link>(.+?)</link>', item)[0]

            try: image = image2 = re.findall('<thumbnail>(.+?)</thumbnail>', item)[0]
            except: image = image2 = '0'

            try: fanart2 = re.findall('<fanart>(.+?)</fanart>', item)[0]
            except: fanart2 = fanart

            if meta == True and content == 'movies':
                try:
                    title = cleantitle(name).encode('utf-8')
                    data = {'title': title}

                    title, year = re.compile('(.+?)[(](\d{4})[)]').findall(name)[0]
                    title = cleantitle(title).encode('utf-8')
                    data = {'title': title, 'year': year}

                    #data = metaget.get_meta('movie', title, year=year)
                    data = cachemeta.get(metaget.get_meta, 24, 'movie', title, '', '', year)

                    metaimage = data['cover_url']
                    if not metaimage == '': image = metaimage
                    metafanart = data['backdrop_url']
                    if not metafanart == '': fanart2 = metafanart
                except:
                    pass

            elif content =='movies':
                try:
                    title = cleantitle(name).encode('utf-8')
                    data = {'title': title}

                    title, year = re.compile('(.+?)[(](\d{4})[)]').findall(name)[0]
                    title = cleantitle(title).encode('utf-8')
                    data = {'title': title, 'year': year}
                except:
                    pass

            elif content == 'episodes':
                try:
                    title = cleantitle(name).encode('utf-8')
                    data = {'title': title, 'tvshowtitle': tvshow}
                except:
                    pass
                try:
                    i = cleaneptitle(tvshow, title)
                    title, season, episode = i[0].encode('utf-8'), i[1], i[2]
                    data = {'title': title, 'tvshowtitle': tvshow, 'season': season, 'episode': episode}
                except:
                    pass
                try:
                    data.update({'year': tvd['year'], 'imdb_id' : tvd['imdb_id'], 'tvdb_id' : tvd['tvdb_id'], 'tvshowtitle': tvd['TVShowTitle'], 'genre' : tvd['genre'], 'studio': tvd['studio'], 'status': tvd['status'], 'duration' : tvd['duration'], 'rating': tvd['rating'], 'mpaa' : tvd['mpaa'], 'plot': tvd['plot'], 'cast': tvd['cast']})

                    metafanart = tvd['backdrop_url']
                    if not metafanart == '': image = fanart2 = metafanart
                except:
                    pass


            if 'sublink' in url:
                addDirectoryItem(name, url, 'subDirectory', image, image2, fanart2, '0', content, data, tvshow=tvshow, totalItems=totalItems, isFolder=True)
            else:
                addDirectoryItem(name, url, 'resolveUrl', image, image2, fanart2, '0', content, data, totalItems=totalItems, isFolder=False)
        except:
            pass

    endDirectory(content, close)
Esempio n. 16
0
def searchDirectory(query=None):
    if (query == None or query == ''):
        keyboard = control.keyboard('', 'Search')
        keyboard.doModal()
        if not (keyboard.isConfirmed()): return
        query = keyboard.getText()

    if (query == None or query == ''): return

    def search(): return [query]
    result = cache.get(search, 600000000, table='rel_srch')
    def search(): return [x for y,x in enumerate((result + [query])) if x not in (result + [query])[:y]]
    result = cache.get(search, 0, table='rel_srch')


    global global_search ; global_search = []

    def worker(url): global_search.append(str(client.request(url)))

    servers = client.request(phLink)
    servers = str(servers).replace('\n','')
    servers = re.findall('</name><link>(.+?)</link>', servers)
    servers = [urlparse.urlparse(i).netloc for i in servers]
    servers = [phSearch % i for i in servers if not 'mecca' in i]

    threads = []
    for server in servers: threads.append(Thread(worker, server))
    [i.start() for i in threads]
    [i.join() for i in threads]

    urls = global_search ; global_search = []
    urls = [str(i).replace('\n','') for i in urls]
    urls = [re.findall('<link>(.+?)</link>', i)[:30] for i in urls]
    urls = sum(urls, [])

    threads = []
    for url in urls: threads.append(Thread(worker, url))
    [i.start() for i in threads]
    [i.join() for i in threads]

    links = global_search ; global_search = []

    for link in links:
        try:
            link = str(link).replace('\r','').replace('\n','').replace('\t','').replace('&nbsp;','')

            try: fanart = re.findall('<fanart>(.+?)</fanart>', link)[0]
            except: fanart = '0'

            try: vip = re.findall('<poster>(.+?)</poster>', link)[0]
            except: vip = ''

            if vip == 'Team Phoenix': vip = ''

            try: content = re.findall('<meta>(.+?)</meta>', link)[0]
            except: content = '0'

            try: tvshow = re.findall('<tvshow>(.+?)</tvshow>', link)[0]
            except: tvshow = '0'

            if content in ['seasons', 'episodes'] and tvshow == '0':
                content = '0'


            dirs = re.compile('<dir>(.+?)</dir>').findall(link)

            for dir in dirs:
                try:
                    data = {}

                    name = re.findall('<name>(.+?)</name>', dir)[0]
                    name = cleantitle(name)

                    if not query.lower() in name.lower() : raise Exception()

                    url = re.findall('<link>(.+?)</link>', dir)[0]

                    try: image = re.findall('<thumbnail>(.+?)</thumbnail>', dir)[0]
                    except: image = '0'

                    try: fanart2 = re.findall('<fanart>(.+?)</fanart>', dir)[0]
                    except: fanart2 = fanart

                    if content =='tvshows':
                        try:
                            title = cleantitle(name).encode('utf-8')
                            data = {'title': title, 'tvshowtitle': title}
                        except:
                            pass

                    if re.search('[a-zA-Z]', vip): name += ' [COLOR orange]%s[/COLOR]' % vip

                    addDirectoryItem(name, url, 'ndmode', image, image, fanart2, '0', content, data)
                except:
                    pass


            items = re.compile('<item>(.+?)</item>').findall(link)

            for item in items:
                try:

                    data = {}

                    name = re.findall('<title>(.+?)</title>', item)[0]
                    name = cleantitle(name)

                    if not query.lower() in name.lower() : raise Exception()

                    url = re.findall('<link>(.+?)</link>', item)[0]

                    try: image = re.findall('<thumbnail>(.+?)</thumbnail>', item)[0]
                    except: image = '0'

                    try: fanart2 = re.findall('<fanart>(.+?)</fanart>', item)[0]
                    except: fanart2 = fanart

                    if content =='movies':
                        try:
                            title = cleantitle(name).encode('utf-8')
                            data = {'title': title}

                            title, year = re.compile('(.+?)[(](\d{4})[)]').findall(name)[0]
                            title = cleantitle(title).encode('utf-8')
                            data = {'title': title, 'year': year}
                        except:
                            pass

                    if re.search('[a-zA-Z]', vip): name += ' [COLOR orange]%s[/COLOR]' % vip

                    if 'sublink' in url:
                        addDirectoryItem(name, url, 'subDirectory', image, image, fanart2, '0', content, data, isFolder=True)
                    else:
                        addDirectoryItem(name, url, 'resolveUrl', image, image, fanart2, '0', content, data, isFolder=False)
                except:
                    pass
        except:
            pass

    control.directory(int(sys.argv[1]), cacheToDisc=True)