Exemplo n.º 1
0
    def papers_index(self):

        # self.data = cache.get(self.front_pages, 12)
        self.data = self.front_pages()

        if not self.data:
            return

        for i in self.data:
            i.update({'action': None, 'isFolder': 'False'})

        self.list = [
            item for item in self.data
            if any(item['group'] == group
                   for group in [int(control.setting('papers_group'))])
        ] if not control.setting('papers_group') == '0' else self.data

        if control.setting('papers_group') == '1':
            integer = 30231
        elif control.setting('papers_group') == '2':
            integer = 30232
        elif control.setting('papers_group') == '3':
            integer = 30233
        elif control.setting('papers_group') == '4':
            integer = 30234
        else:
            integer = 30235

        switch = {
            'title': control.lang(30047).format(control.lang(integer)),
            'icon': iconname('switcher'),
            'action': 'papers_switcher'
        }

        if control.setting('show_pic_switcher') == 'true':

            li = control.item(label=switch['title'], iconImage=switch['icon'])
            li.setArt({'fanart': control.addonInfo('fanart')})
            url = '{0}?action={1}'.format(self.sysaddon, switch['action'])
            control.addItem(self.syshandle, url, li)

        for i in self.list:

            li = control.item(label=i['title'], iconImage=i['image'])
            li.setArt({
                'poster': i['image'],
                'thumb': i['image'],
                'fanart': control.addonInfo('fanart')
            })
            li.setInfo('image', {'title': i['title'], 'picturepath': i['url']})
            url = i['url']
            isFolder = False
            self.directory.append((url, li, isFolder))

        control.addItems(self.syshandle, self.directory)
        control.directory(self.syshandle)
Exemplo n.º 2
0
    def papers_index(self):

        self.data = self.front_pages()

        for i in self.data:
            i.update({'action': None, 'isFolder': 'False'})

        try:
            self.list = [
                item for item in self.data
                if item['group'] == int(control.setting('papers_group'))
            ]
        except Exception:
            self.list = [item for item in self.data if item['group'] == 0]
            control.setSetting('papers_group', '0')

        if control.setting('papers_group') == '1':
            integer = 30232
        elif control.setting('papers_group') == '2':
            integer = 30233
        elif control.setting('papers_group') == '3':
            integer = 30234
        else:
            integer = 30231

        switch = {
            'title': control.lang(30047).format(control.lang(integer)),
            'icon': iconname('switcher'),
            'action': 'papers_switcher'
        }

        if control.setting('show_pic_switcher') == 'true':

            li = control.item(label=switch['title'])
            li.setArt({
                'icon': switch['icon'],
                'fanart': control.addonInfo('fanart')
            })
            url = '{0}?action={1}'.format(sysaddon, switch['action'])
            control.addItem(syshandle, url, li)

        for i in self.list:

            li = control.item(label=i['title'])
            li.setArt({
                'icon': i['image'],
                'poster': i['image'],
                'thumb': i['image'],
                'fanart': control.addonInfo('fanart')
            })
            li.setInfo('image', {'title': i['title'], 'picturepath': i['url']})
            url = i['url']
            self.directory.append((url, li, False))

        control.addItems(syshandle, self.directory)
        control.directory(syshandle)
Exemplo n.º 3
0
    def run(self, url, source):

        path = control.join(control.dataPath, 'temp')

        try:

            path = path.decode('utf-8')

        except Exception:

            pass

        control.deleteDir(control.join(path, ''), force=True)

        control.makeFile(control.dataPath)

        control.makeFile(path)

        if source == 'subtitlesgr':

            subtitle = subtitlesgr.subtitlesgr().download(path, url)

        elif source == 'xsubstv':

            subtitle = xsubstv.xsubstv().download(path, url)

        elif source == 'subzxyz':

            subtitle = subzxyz.subzxyz().download(path, url)

        elif source == 'tvsubtitlesgr':

            subtitle = None

        else:

            subtitle = None

        if subtitle is not None:

            item = control.item(label=subtitle)
            control.addItem(handle=syshandle,
                            url=subtitle,
                            listitem=item,
                            isFolder=False)

        control.directory(syshandle)
Exemplo n.º 4
0
    def mag_index(self, url):

        number = int(client.request(url + '/pages'))

        pages = []

        for page in list(range(1, number + 1)):

            string = str(page)

            title = control.lang(30026) + ' ' + string

            if len(string) == 2:
                image = url + '/thumbs' + '/thumb-' + string + '.jpg'
                link = url + '/page-' + string + '.jpg'
            else:
                image = url + '/thumbs' + '/thumb-' + '0' + string + '.jpg'
                link = url + '/page-' + '0' + string + '.jpg'

            data = {'title': title, 'image': image, 'url': link}
            pages.append(data)

        for p in pages:

            li = control.item(label=p['title'],
                              iconImage=p['image'],
                              thumbnailImage=p['image'])
            li.setArt({
                'poster': p['image'],
                'thumb': p['image'],
                'fanart': control.addonInfo('fanart')
            })
            li.setInfo('image', {
                'title': p['title'],
                'picturepath': p['image']
            })
            path = p['url']

            control.addItem(int(self.argv[1]), path, li, False)

        control.directory(int(self.argv[1]))
Exemplo n.º 5
0
    def mags_index(self):

        magazines = magazine_list()[0]

        for mag in magazines:

            li = control.item(label=mag['title'], iconImage=mag['image'])
            li.setArt({
                'poster': mag['image'],
                'thumb': mag['image'],
                'fanart': control.addonInfo('fanart')
            })
            li.setInfo('image', {
                'title': mag['title'],
                'picturepath': mag['url']
            })
            url = mag['url']

            control.addItem(int(self.argv[1]), url, li, True)

        control.directory(int(self.argv[1]))
Exemplo n.º 6
0
    def run(self, query=None):

        if not 'Greek' in str(langs).split(','):
            control.directory(syshandle)
            control.infoDialog(control.lang(32002).encode('utf-8'))
            return

        if query is None:

            title = control.infoLabel('VideoPlayer.Title')

            if re.search(r'[^\x00-\x7F]+', title) is not None:
                title = control.infoLabel('VideoPlayer.OriginalTitle')

            year = control.infoLabel('VideoPlayer.Year')

            tvshowtitle = control.infoLabel('VideoPlayer.TVshowtitle')

            season = control.infoLabel('VideoPlayer.Season')

            episode = control.infoLabel('VideoPlayer.Episode')

            if 's' in episode.lower():
                season, episode = '0', episode[-1:]

            if not tvshowtitle == '':  # episode
                query = '%s S%02dE%02d' % (tvshowtitle, int(season),
                                           int(episode))
            elif not year == '':  # movie
                query = '%s (%s)' % (title, year)
            else:  # file
                query, year = getCleanMovieTitle(title)
                if not year == '': query = '%s (%s)' % (query, year)

        self.query = query

        threads = []

        threads.append(workers.Thread(self.xsubstv))
        threads.append(workers.Thread(self.subzxyz))
        threads.append(workers.Thread(self.subtitlesgr))

        [i.start() for i in threads]

        for i in range(0, 10 * 2):
            try:
                is_alive = [x.is_alive() for x in threads]
                if all(x == False for x in is_alive):
                    break
                if control.aborted is True:
                    break
                control.sleep(500)
            except:
                pass

        if len(self.list) == 0:
            control.directory(syshandle)
            return

        f = []

        f += [i for i in self.list if i['source'] == 'xsubstv']
        f += [i for i in self.list if i['source'] == 'subzxyz']
        f += [i for i in self.list if i['source'] == 'subtitlesgr']

        self.list = f

        for i in self.list:

            try:
                if i['source'] == 'subzxyz':
                    i['name'] = '[subzxyz] %s' % i['name']
                elif i['source'] == 'xsubstv':
                    i['name'] = '[xsubstv] %s' % i['name']
            except:
                pass

        for i in self.list:

            try:
                name, url, source, rating = i['name'], i['url'], i[
                    'source'], i['rating']

                u = {'action': 'download', 'url': url, 'source': source}
                u = '%s?%s' % (sysaddon, urllib.urlencode(u))

                item = control.item(label='Greek',
                                    label2=name,
                                    iconImage=str(rating),
                                    thumbnailImage='el')
                item.setProperty('sync', 'false')
                item.setProperty('hearing_imp', 'false')

                control.addItem(handle=syshandle,
                                url=u,
                                listitem=item,
                                isFolder=False)
            except:
                pass

        control.directory(syshandle)
Exemplo n.º 7
0
def add(items,
        cacheToDisc=True,
        content=None,
        mediatype=None,
        infotype='video',
        argv=None,
        as_playlist=False,
        pd_heading=None,
        pd_message='',
        clear_first=True,
        progress=False,
        category=None):

    if argv is None:

        from tulip.init import sysaddon, syshandle

    else:

        sysaddon = argv[0]
        syshandle = int(argv[1])

    if items is None or len(items) == 0:
        return

    # sysicon = control.join(control.addonInfo('path'), 'resources', 'media')
    sysimage = control.addonInfo('icon')
    sysfanart = control.addonInfo('fanart')

    if progress:

        pd = control.progressDialogGB
        pd.create(heading=control.name() if not pd_heading else pd_heading,
                  message=pd_message)

    else:

        pd = None

    if as_playlist and clear_first:

        control.playlist(1 if infotype == 'video' else 0).clear()

    meta_tags = [
        'count', 'size', 'date', 'genre', 'country', 'year', 'episode',
        'season', 'sortepisode', 'sortseason', 'episodeguide', 'showlink',
        'top250', 'setid', 'tracknumber', 'rating', 'userrating', 'watched',
        'playcount', 'overlay', 'cast', 'castandrole', 'director', 'mpaa',
        'plot', 'plotoutline', 'title', 'originaltitle', 'sorttitle',
        'duration', 'studio', 'tagline', 'writer', 'tvshowtitle', 'premiered',
        'status', 'set', 'gameclient', 'setoverview', 'tag', 'imdbnumber',
        'code', 'aired', 'credits', 'lastplayed', 'album', 'artist', 'votes',
        'path', 'trailer', 'dateadded', 'mediatype', 'dbid', 'tracknumber',
        'discnumber', 'lyrics', 'listeners', 'musicbrainztrackid', 'comment',
        'picturepath', 'platform', 'genres', 'publisher', 'developer',
        'overview'
    ]

    for c, i in list(enumerate(items)):

        try:

            if progress:

                p = control.per_cent(c, len(items))
                pd.update(p)

            try:
                label = control.lang(i['title']).encode('utf-8')
            except Exception:
                label = i['title']

            if 'label' in i and not i['label'] == '0':
                label = i['label']

            if 'image' in i and not i['image'] == '0':
                image = i['image']
            elif 'poster' in i and not i['poster'] == '0':
                image = i['poster']
            elif 'icon' in i and not i['icon'] == '0':
                image = control.addonmedia(i['icon'])
            else:
                image = sysimage

            if 'banner' in i and not i['banner'] == '0':
                banner = i['banner']
            elif 'fanart' in i and not i['fanart'] == '0':
                banner = i['fanart']
            else:
                banner = image

            fanart = i['fanart'] if 'fanart' in i and not i[
                'fanart'] == '0' else sysfanart

            isFolder = False if 'isFolder' in i and not i[
                'isFolder'] == '0' else True

            try:
                is_play_boolean = i.get('isPlayable') in [
                    'True', 'true', '1', 'yes', 'Yes'
                ]
            except Exception:
                is_play_boolean = False

            isPlayable = True if not isFolder and 'isPlayable' not in i else is_play_boolean

            if isPlayable:

                isFolder = False

            try:
                action = '{0}?action={1}'.format(sysaddon, i['action'])
            except KeyError:
                return

            try:
                url = 'url={0}'.format(quote_plus(i['url']))
            except Exception:
                url = None

            try:
                title = 'title={0}'.format(quote_plus(i['title']))
            except KeyError:
                try:
                    title = 'title={0}'.format(
                        quote_plus(i['title'].encode('utf-8')))
                except KeyError:
                    title = None
            except Exception:
                title = None

            try:
                icon = 'image={0}'.format(quote_plus(i['image']))
            except KeyError:
                try:
                    icon = 'image={0}'.format(
                        quote_plus(i['image'].encode('utf-8')))
                except KeyError:
                    icon = None
            except Exception:
                icon = None
            try:
                name = 'name={0}'.format(quote_plus(i['name']))
            except KeyError:
                try:
                    name = 'name={0}'.format(
                        quote_plus(i['name'].encode('utf-8')))
                except KeyError:
                    name = None
            except Exception:
                name = None
            try:
                year = 'year={0}'.format(quote_plus(i['year']))
            except Exception:
                year = None
            try:
                plot = 'plot={0}'.format(quote_plus(i['plot']))
            except KeyError:
                try:
                    plot = 'plot={0}'.format(
                        quote_plus(i['plot'].encode('utf-8')))
                except KeyError:
                    plot = None
            except Exception:
                plot = None
            try:
                genre = 'genre={0}'.format(quote_plus(i['genre']))
            except KeyError:
                try:
                    genre = 'genre={0}'.format(
                        quote_plus(i['genre'].encode('utf-8')))
                except KeyError:
                    genre = None
            except Exception:
                genre = None
            try:
                dash = 'dash={0}'.format(quote_plus(i['dash']))
            except Exception:
                dash = None
            try:
                query = 'query={0}'.format(quote_plus(i['query']))
            except Exception:
                query = None

            parts = [
                foo for foo in [
                    action, url, title, icon, name, year, plot, genre, dash,
                    query
                ] if foo
            ]

            uri = '&'.join(parts)

            cm = []
            menus = i['cm'] if 'cm' in i else []

            for menu in menus:

                try:

                    try:
                        tmenu = control.lang(menu['title']).encode('utf-8')
                    except Exception:
                        tmenu = menu['title']
                    try:
                        qmenu = urlencode(menu['query'])
                    except Exception:
                        qmenu = urlencode(
                            dict((k, v.encode('utf-8'))
                                 for k, v in menu['query'].items()))
                    cm.append(
                        (tmenu, 'RunPlugin({0}?{1})'.format(sysaddon, qmenu)))

                except Exception:

                    pass

            meta = dict((k, v) for k, v in iteritems(i)
                        if k in meta_tags and (not v == '0' or v is None))

            if mediatype is not None:
                meta['mediatype'] = mediatype

            item = control.item(label=label)

            item.setArt({
                'icon': image,
                'thumb': image,
                'poster': image,
                'tvshow.poster': image,
                'season.poster': image,
                'banner': banner,
                'tvshow.banner': banner,
                'season.banner': banner,
                'fanart': fanart
            })

            item.addContextMenuItems(cm)
            item.setInfo(
                type=infotype if 'infotype' not in i else i['infotype'],
                infoLabels=meta)

            if isPlayable:

                if not i['action'] == 'pvr_client':
                    item.setProperty('IsPlayable', 'true')
                else:
                    item.setProperty('IsPlayable', 'false')

                if not i['action'] == 'pvr_client':
                    if 'streaminfo' not in i and infotype == 'video':
                        item.addStreamInfo(infotype, {'codec': 'h264'})
                    else:
                        item.addStreamInfo(infotype, i.get('streaminfo'))

            if as_playlist and isPlayable:
                control.playlist(1 if infotype == 'video' else 0).add(
                    url=uri, listitem=item, index=c)
            else:
                control.addItem(handle=syshandle,
                                url=uri,
                                listitem=item,
                                isFolder=isFolder,
                                totalItems=len(items))

        except Exception as reason:
            log('Directory not added, reason of failure: ' + repr(reason))

    if progress:
        pd.update(100)
        pd.close()

    if as_playlist:

        control.openPlaylist(1 if infotype == 'video' else 0)

        return

    try:

        i = items[0]
        if i['next'] == '':
            raise Exception()

        url = '{0}?action={1}&url={2}'.format(sysaddon, i['nextaction'],
                                              quote_plus(i['next']))
        icon = i['nexticon'] if 'nexticon' in i else control.addonmedia(
            'next.png')
        fanart = i['nextfanart'] if 'nextfanart' in i else sysfanart

        try:
            label = control.lang(i['nextlabel']).encode('utf-8')
        except Exception:
            label = 'Next'

        item = control.item(label=label)

        item.setArt({
            'icon': icon,
            'thumb': icon,
            'poster': icon,
            'tvshow.poster': icon,
            'season.poster': icon,
            'banner': icon,
            'tvshow.banner': icon,
            'season.banner': icon,
            'fanart': fanart
        })

        control.addItem(handle=syshandle,
                        url=url,
                        listitem=item,
                        isFolder=True,
                        totalItems=len(items))

    except Exception:

        pass

    if content is not None:
        control.content(syshandle, content)

    if category is not None:
        control.setcategory(syshandle, category)

    control.directory(syshandle, cacheToDisc=cacheToDisc)
Exemplo n.º 8
0
    def run(self, query=None):

        if 'Greek' not in str(self.langs).split(','):

            control.directory(self.syshandle)
            control.infoDialog(control.lang(30002))

            return

        dup_removal = False

        if not query:

            title = match_title = control.infoLabel(
                '{0}.Title'.format(infolabel_prefix))

            with concurrent_futures.ThreadPoolExecutor(5) as executor:

                if re.search(r'[^\x00-\x7F]+', title) is not None:

                    title = control.infoLabel(
                        '{0}.OriginalTitle'.format(infolabel_prefix))

                title = unicodedata.normalize('NFKD',
                                              title).encode('ascii', 'ignore')
                title = py3_dec(title)
                year = control.infoLabel('{0}.Year'.format(infolabel_prefix))
                tvshowtitle = control.infoLabel(
                    '{0}.TVshowtitle'.format(infolabel_prefix))
                season = control.infoLabel(
                    '{0}.Season'.format(infolabel_prefix))

                if len(season) == 1:

                    season = '0' + season

                episode = control.infoLabel(
                    '{0}.Episode'.format(infolabel_prefix))

                if len(episode) == 1:
                    episode = '0' + episode

                if 's' in episode.lower():
                    season, episode = '0', episode[-1:]

                if tvshowtitle != '':  # episode

                    title_query = '{0} {1}'.format(tvshowtitle, title)
                    season_episode_query = '{0} S{1} E{2}'.format(
                        tvshowtitle, season, episode)
                    season_episode_query_nospace = '{0} S{1}E{2}'.format(
                        tvshowtitle, season, episode)

                    threads = [
                        executor.submit(self.subtitlesgr,
                                        season_episode_query_nospace),
                        executor.submit(self.xsubstv, season_episode_query),
                        executor.submit(self.podnapisi, season_episode_query),
                        executor.submit(self.vipsubs, season_episode_query)
                    ]

                    dup_removal = True

                    log_debug('Dual query used for subtitles search: ' +
                              title_query + ' / ' + season_episode_query)

                    if control.setting('queries') == 'true':

                        threads.extend([
                            executor.submit(self.subtitlesgr, title_query),
                            executor.submit(self.vipsubs, title_query),
                            executor.submit(self.podnapisi, title_query),
                            executor.submit(self.subtitlesgr,
                                            season_episode_query)
                        ])

                elif year != '':  # movie

                    query = '{0} ({1})'.format(title, year)

                    threads = [
                        executor.submit(self.subtitlesgr, query),
                        executor.submit(self.xsubstv, query),
                        executor.submit(self.vipsubs, query),
                        executor.submit(self.podnapisi, query)
                    ]

                else:  # file

                    query, year = control.cleanmovietitle(title)

                    if year != '':

                        query = '{0} ({1})'.format(query, year)

                    threads = [
                        executor.submit(self.subtitlesgr, query),
                        executor.submit(self.xsubstv, query),
                        executor.submit(self.vipsubs, query),
                        executor.submit(self.podnapisi, query)
                    ]

                for future in concurrent_futures.as_completed(threads):

                    item = future.result()

                    if not item:
                        continue

                    self.list.extend(item)

                if not dup_removal:

                    log_debug('Query used for subtitles search: ' + query)

                self.query = query

                self.query = py3_dec(self.query)

        else:  # Manual query

            with concurrent_futures.ThreadPoolExecutor(5) as executor:

                query = match_title = py3_dec(query)

                threads = [
                    executor.submit(self.subtitlesgr, query),
                    executor.submit(self.xsubstv, query),
                    executor.submit(self.vipsubs, query),
                    executor.submit(self.podnapisi, query)
                ]

                for future in concurrent_futures.as_completed(threads):

                    item = future.result()

                    if not item:
                        continue

                    self.list.extend(item)

        if len(self.list) == 0:

            control.directory(self.syshandle)

            return

        f = []

        # noinspection PyUnresolvedReferences
        f += [i for i in self.list if i['source'] == 'xsubstv']
        f += [i for i in self.list if i['source'] == 'subtitlesgr']
        f += [i for i in self.list if i['source'] == 'podnapisi']
        f += [i for i in self.list if i['source'] == 'vipsubs']

        self.list = f

        if dup_removal:

            self.list = [
                dict(t) for t in {tuple(d.items())
                                  for d in self.list}
            ]

        for i in self.list:

            try:

                if i['source'] == 'xsubstv':
                    i['name'] = u'[xsubstv] {0}'.format(i['name'])
                elif i['source'] == 'podnapisi':
                    i['name'] = u'[podnapisi] {0}'.format(i['name'])
                elif i['source'] == 'vipsubs':
                    i['name'] = u'[vipsubs] {0}'.format(i['name'])

            except Exception:

                pass

        if control.setting('sorting') == '1':
            key = 'source'
        elif control.setting('sorting') == '2':
            key = 'downloads'
        elif control.setting('sorting') == '3':
            key = 'rating'
        else:
            key = 'title'

        self.list = sorted(self.list,
                           key=lambda k: k[key].lower(),
                           reverse=control.setting('sorting')
                           in ['1', '2', '3'])

        for i in self.list:

            u = {'action': 'download', 'url': i['url'], 'source': i['source']}
            u = '{0}?{1}'.format(self.sysaddon, urlencode(u))
            item = control.item(label='Greek', label2=i['name'])
            item.setArt({'icon': str(i['rating'])[:1], 'thumb': 'el'})
            if ratio(
                    splitext(i['title'].lower())[0],
                    splitext(match_title)[0]) >= int(
                        control.setting('sync_probability')):
                item.setProperty('sync', 'true')
            else:
                item.setProperty('sync', 'false')
            item.setProperty('hearing_imp', 'false')

            control.addItem(handle=self.syshandle,
                            url=u,
                            listitem=item,
                            isFolder=False)

        control.directory(self.syshandle)
Exemplo n.º 9
0
    def run(self, url, source):

        log_debug('Source selected: {0}'.format(source))

        path = control.join(control.dataPath, 'temp')

        try:

            path = path.decode('utf-8')

        except Exception:

            pass

        control.deleteDir(control.join(path, ''), force=True)
        control.makeFile(control.dataPath)
        control.makeFile(path)

        if control.setting('keep_subs') == 'true' or control.setting(
                'keep_zips') == 'true':

            if not control.get_info_label('ListItem.Path').startswith(
                    'plugin://') and control.setting('destination') == '0':
                output_path = control.get_info_label('Container.FolderPath')
            elif control.setting('output_folder').startswith('special://'):
                output_path = control.transPath(
                    control.setting('output_folder'))
            else:
                output_path = control.setting('output_folder')

            if not exists(output_path):
                control.makeFile(output_path)

        if source == 'subtitlesgr':

            subtitle = subtitlesgr.Subtitlesgr().download(path, url)

        elif source == 'xsubstv':

            subtitle = xsubstv.Xsubstv().download(path, url)

        elif source == 'podnapisi':

            subtitle = podnapisi.Podnapisi().download(path, url)

        elif source == 'vipsubs':

            subtitle = vipsubs.Vipsubs().download(path, url)

        else:

            subtitle = None

        if subtitle is not None:

            if control.setting('keep_subs') == 'true':

                # noinspection PyUnboundLocalVariable
                try:
                    if control.setting('destination') in ['0', '2']:
                        if control.infoLabel('{0}.Title'.format(
                                infolabel_prefix)).startswith('plugin://'):
                            copy(
                                subtitle,
                                control.join(output_path,
                                             os_split(subtitle)[1]))
                            log_debug(
                                'Item currently selected is not a local file, cannot save subtitle next to it'
                            )
                        else:
                            output_filename = control.join(
                                output_path, ''.join([
                                    splitext(
                                        control.infoLabel('ListItem.FileName'))
                                    [0],
                                    splitext(os_split(subtitle)[1])[1]
                                ]))
                            if exists(output_filename):
                                yesno = control.yesnoDialog(
                                    control.lang(30015))
                                if yesno:
                                    copy(subtitle, output_filename)
                            else:
                                copy(subtitle, output_filename)
                            if control.setting('destination') == '2':
                                if control.setting('output_folder').startswith(
                                        'special://'):
                                    output_path = control.transPath(
                                        control.setting('output_folder'))
                                else:
                                    output_path = control.setting(
                                        'output_folder')
                                copy(
                                    subtitle,
                                    control.join(output_path,
                                                 os_split(subtitle)[1]))
                    else:
                        copy(subtitle,
                             control.join(output_path,
                                          os_split(subtitle)[1]))
                    control.infoDialog(control.lang(30008))
                except Exception:
                    control.infoDialog(control.lang(30013))

            item = control.item(label=subtitle)
            control.addItem(handle=self.syshandle,
                            url=subtitle,
                            listitem=item,
                            isFolder=False)

        control.directory(self.syshandle)
Exemplo n.º 10
0
    def run(self, query=None):

        if 'Greek' not in str(langs).split(','):

            control.directory(syshandle)
            control.infoDialog(control.lang(32002))

            return

        if not control.conditional_visibility(
                'System.HasAddon(vfs.libarchive)') and float(
                    control.addon('xbmc.addon').getAddonInfo('version')
                    [:4]) >= 18.0:

            control.execute('InstallAddon(vfs.libarchive)')

        threads = [
            workers.Thread(self.xsubstv),
            workers.Thread(self.subzxyz),
            workers.Thread(self.subtitlesgr)
        ]
        dup_removal = False

        if not query:

            if control.condVisibility('Player.HasVideo'):
                infolabel_prefix = 'VideoPlayer'
            else:
                infolabel_prefix = 'ListItem'

            title = control.infoLabel('{0}.Title'.format(infolabel_prefix))

            if re.search(r'[^\x00-\x7F]+', title) is not None:

                title = control.infoLabel(
                    '{0}.OriginalTitle'.format(infolabel_prefix))

            year = control.infoLabel('{0}.Year'.format(infolabel_prefix))

            tvshowtitle = control.infoLabel(
                '{0}.TVshowtitle'.format(infolabel_prefix))

            season = control.infoLabel('{0}.Season'.format(infolabel_prefix))

            if len(season) == 1:

                season = '0' + season

            episode = control.infoLabel('{0}.Episode'.format(infolabel_prefix))

            if len(episode) == 1:
                episode = '0' + episode

            if 's' in episode.lower():
                season, episode = '0', episode[-1:]

            if tvshowtitle != '':  # episode

                title_query = '{0} {1}'.format(tvshowtitle, title)
                season_episode_query = '{0} S{1} E{2}'.format(
                    tvshowtitle, season, episode)

                threads = [
                    workers.Thread(self.xsubstv, title_query),
                    workers.Thread(self.subzxyz, title_query),
                    workers.Thread(self.subtitlesgr, title_query),
                    workers.Thread(self.xsubstv, season_episode_query),
                    workers.Thread(self.subzxyz, season_episode_query),
                    workers.Thread(self.subtitlesgr, season_episode_query)
                ]

                dup_removal = True
                log.log('Dual query used for subtitles search: ' +
                        title_query + ' / ' + season_episode_query)

            elif year != '':  # movie

                query = '{0} ({1})'.format(title, year)

            else:  # file

                query, year = getCleanMovieTitle(title)

                if year != '':

                    query = '{0} ({1})'.format(query, year)

        if not dup_removal:

            log.log('Query used for subtitles search: ' + query)

        self.query = query

        [i.start() for i in threads]

        for c, i in list(enumerate(range(0, 40))):

            is_alive = [x.is_alive() for x in threads]

            if all(x is False for x in is_alive):
                log.log('Reached count : ' + str(c))
                break
            if control.aborted is True:
                log.log('Aborted, reached count : ' + str(c))
                break

            control.sleep(750)

        if len(self.list) == 0:

            control.directory(syshandle)

            return

        f = []

        # noinspection PyUnresolvedReferences
        f += [i for i in self.list if i['source'] == 'xsubstv']
        f += [i for i in self.list if i['source'] == 'subzxyz']
        f += [i for i in self.list if i['source'] == 'subtitlesgr']

        self.list = f

        if dup_removal:

            self.list = [
                dict(t) for t in {tuple(d.items())
                                  for d in self.list}
            ]

        for i in self.list:

            try:

                if i['source'] == 'subzxyz':
                    i['name'] = '[subzxyz] {0}'.format(i['name'])
                elif i['source'] == 'xsubstv':
                    i['name'] = '[xsubstv] {0}'.format(i['name'])

            except Exception:

                pass

        for i in self.list:

            u = {'action': 'download', 'url': i['url'], 'source': i['source']}
            u = '{0}?{1}'.format(sysaddon, urlencode(u))

            item = control.item(label='Greek',
                                label2=i['name'],
                                iconImage=str(i['rating']),
                                thumbnailImage='el')
            item.setProperty('sync', 'false')
            item.setProperty('hearing_imp', 'false')

            control.addItem(handle=syshandle,
                            url=u,
                            listitem=item,
                            isFolder=False)

        control.directory(syshandle)
Exemplo n.º 11
0
    def run(self, url, source):

        log_debug('Source selected: {0}'.format(source))

        path = control.join(control.dataPath, 'temp')

        try:

            path = path.decode('utf-8')

        except Exception:

            pass

        control.deleteDir(control.join(path, ''), force=True)

        control.makeFile(control.dataPath)

        control.makeFile(path)

        if control.setting('keep_subs') == 'true' or control.setting(
                'keep_zips') == 'true':

            if control.setting('output_folder').startswith('special://'):
                output_path = control.transPath(
                    control.setting('output_folder'))
            else:
                output_path = control.setting('output_folder')

            control.makeFile(output_path)

        if source == 'subtitlesgr':

            subtitle = subtitlesgr.Subtitlesgr().download(path, url)

        elif source == 'xsubstv':

            subtitle = xsubstv.Xsubstv().download(path, url)

        elif source == 'podnapisi':

            subtitle = podnapisi.Podnapisi().download(path, url)

        elif source == 'vipsubs':

            subtitle = vipsubs.Vipsubs().download(path, url)

        else:

            subtitle = None

        if subtitle is not None:

            if control.setting('keep_subs') == 'true':

                # noinspection PyUnboundLocalVariable
                copy(subtitle, control.join(output_path,
                                            os_split(subtitle)[1]))
                control.infoDialog(control.lang(30008))

            item = control.item(label=subtitle)
            control.addItem(handle=self.syshandle,
                            url=subtitle,
                            listitem=item,
                            isFolder=False)

        control.directory(self.syshandle)