示例#1
0
def delete(dbfile=control.cacheFile, withyes=True):

    if withyes:

        yes = control.yesnoDialog(control.lang(30401).encode('utf-8'), '', '')

        if not yes:
            return

    else:

        pass

    control.deleteFile(dbfile)

    control.infoDialog(control.lang(30402).encode('utf-8'))
示例#2
0
def multichoice(filenames, allow_random=False):
    from random import choice
    from os.path import split as os_split
    if filenames is None or len(filenames) == 0:

        return

    elif len(filenames) >= 1:

        if allow_random:
            length = len(filenames) + 1
        else:
            length = len(filenames)

        if len(filenames) == 1:
            return filenames[0]

        choices = [os_split(i)[1] for i in filenames]

        if allow_random:
            choices.insert(0, control.lang(32215))

        _choice = control.selectDialog(heading=control.lang(32214), list=choices)

        if _choice == 0:
            if allow_random:
                filename = choice(filenames)
            else:
                filename = filenames[0]
        elif _choice != -1 and _choice <= length:
            if allow_random:
                filename = filenames[_choice - 1]
            else:
                filename = filenames[_choice]
        else:
            if allow_random:
                filename = choice(filenames)
            else:
                return

        return filename

    else:

        return
示例#3
0
def clear(table=None, withyes=True):

    try:
        control.idle()

        if table is None:
            table = ['rel_list', 'rel_lib']
        elif not type(table) == list:
            table = [table]

        if withyes:

            try:
                yes = control.yesnoDialog(
                    control.lang(30401).encode('utf-8'), '', '')
            except BaseException:
                yes = control.yesnoDialog(control.lang(30401), '', '')

            if not yes:
                return

        else:

            pass

        dbcon = database.connect(control.cacheFile)
        dbcur = dbcon.cursor()

        for t in table:
            try:
                dbcur.execute("DROP TABLE IF EXISTS %s" % t)
                dbcur.execute("VACUUM")
                dbcon.commit()
            except BaseException:
                pass

        control.infoDialog(control.lang(30402).encode('utf-8'))
    except BaseException:
        pass
示例#4
0
文件: client.py 项目: kenia-borges/Dr
def download_media(url, path, file_name, progress=None):

    try:
        if progress is None:
            progress = int(control.setting('progress_dialog'))

        active = not progress == PROGRESS.OFF
        background = progress == PROGRESS.BACKGROUND

        with control.ProgressDialog(
                control.addonInfo('name'), control.lang(30500).format(file_name), background=background, active=active
        ) as pd:

            try:
                headers = dict([item.split('=') for item in (url.split('|')[1]).split('&')])
                for key in headers:
                    headers[key] = unquote(headers[key])
            except:
                headers = {}

            if 'User-Agent' not in headers:
                headers['User-Agent'] = randomagent()

            request = urllib2.Request(url.split('|')[0], headers=headers)
            response = urllib2.urlopen(request)

            if 'Content-Length' in response.info():
                content_length = int(response.info()['Content-Length'])
            else:
                content_length = 0

            file_name += '.' + get_extension(url, response)
            full_path = control.join(path, file_name)
            log_debug('Downloading: %s -> %s' % (url, full_path))

            path = control.transPath(control.legalfilename(path))

            try:
                control.makeFiles(path)
            except Exception as e:
                log_debug('Path Create Failed: %s (%s)' % (e, path))

            from os import sep

            if not path.endswith(sep):
                path += sep
            if not control.exists(path):
                raise Exception('Failed to create dir')

            file_desc = control.openFile(full_path, 'w')
            total_len = 0
            cancel = False
            while 1:
                data = response.read(512 * 1024)
                if not data:
                    break

                if pd.is_canceled():
                    cancel = True
                    break

                total_len += len(data)
                if not file_desc.write(data):
                    raise Exception('Failed to write file')

                percent_progress = total_len * 100 / content_length if content_length > 0 else 0
                log_debug('Position : {0} / {1} = {2}%'.format(total_len, content_length, percent_progress))
                pd.update(percent_progress)

            file_desc.close()

        if not cancel:
            control.infoDialog(control.lang(30501).format(file_name))
            log_debug('Download Complete: {0} -> {1}'.format(url, full_path))

    except Exception as e:
        log_debug('Error ({0}) during download: {1} -> {2}'.format(str(e), url, file_name))
        control.infoDialog(control.lang(30502).format(str(e), file_name))
示例#5
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:
            if control.condVisibility('Player.HasVideo'):
                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')
                try:
                    imdb = control.infoLabel('VideoPlayer.IMDBNumber')
                    if not imdb:
                        imdb = '0'
                except BaseException:
                    imdb = '0'
            else:
                title = xbmc.getInfoLabel("ListItem.OriginalTitle")
                year = xbmc.getInfoLabel("ListItem.Year")
                tvshowtitle = xbmc.getInfoLabel("ListItem.TVShowTitle")
                season = xbmc.getInfoLabel("ListItem.Season")
                episode = xbmc.getInfoLabel("ListItem.Episode")
                #labelType = xbmc.getInfoLabel("ListItem.DBTYPE")
                try:
                    imdb = control.infoLabel('ListItem.IMDBNumber')
                    # xbmc.log('$#$QUERY-NONE-IMDB: %s' % imdb, xbmc.LOGNOTICE)
                    if not imdb:
                        imdb = '0'
                except BaseException:
                    imdb = '0'

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

            if not tvshowtitle == '':  # episode
                query = '%s S%02dE%02d/imdb=%s' % (tvshowtitle, int(season),
                                                   int(episode), str(imdb))

            elif not year == '':  # movie
                query = '%s (%s)/imdb=%s' % (title, year, str(imdb))

            elif '(S' in title:
                query = '%s/imdb=%s' % (title, str(imdb))

            else:  # file
                query, year = getCleanMovieTitle(title)
                if not year == '':
                    query = '%s (%s)/imdb=%s' % (query, year, str(imdb))
            # xbmc.log('$#$QUERY-NONE-FINAL: %s' % query, xbmc.LOGNOTICE)

        else:
            query = '%s/imdb=0' % re.sub('[\(|\)]', '', query)
            # xbmc.log('$#$QUERY-ELSE: %s' % query, xbmc.LOGNOTICE)

        self.query = query
        # xbmc.log('$#$QUERY: %s' % query, xbmc.LOGNOTICE)

        threads = []
        if control.setting('provider.subztv.club'):
            threads.append(workers.Thread(self.subztv))
        if control.setting('provider.s4f'):
            threads.append(workers.Thread(self.s4f))
        if control.setting('provider.yifi'):
            threads.append(workers.Thread(self.yifi))

        [i.start() for i in threads]
        [i.join() for i in threads]

        f = []

        f += [i for i in self.list if i['source'] == 'subztv']

        f += [i for i in self.list if i['source'] == 's4f']

        f += [i for i in self.list if i['source'] == 'yifi']

        self.list = sorted(f, key=lambda k: k['rating'], reverse=True)

        for i in self.list:

            try:

                if i['source'] == 'subztv':
                    i['name'] = '[subztv] %s' % i['name']

                elif i['source'] == 's4f':
                    i['name'] = '[S4F] %s' % i['name']

                elif i['source'] == 'yifi':
                    i['name'] = '[yifi] %s' % i['name']
            except BaseException:
                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 BaseException:
                pass

        control.directory(syshandle)
示例#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')
            try:
                imdb = control.infoLabel('VideoPlayer.IMDBNumber')
            except:
                imdb = '0'

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

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

        self.query = query

        threads = []

        threads.append(workers.Thread(self.subztv))
        threads.append(workers.Thread(self.s4f))
        threads.append(workers.Thread(self.yifi))

        [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 is 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'] == 'subztv']
        f += [i for i in self.list if i['source'] == 's4f']
        f += [i for i in self.list if i['source'] == 'yifi']

        self.list = sorted(f, key=lambda k: k['rating'], reverse=True)

        for i in self.list:

            try:

                if i['source'] == 'subztv':
                    i['name'] = '[subztv] %s' % i['name']

                elif i['source'] == 's4f':
                    i['name'] = '[S4F] %s' % i['name']

                elif i['source'] == 'yifi':
                    i['name'] = '[yifi] %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)
示例#7
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 control.kodi_version() >= 18.0 and not\
                control.conditional_visibility('System.HasAddon(vfs.libarchive)')\
                and not (control.condVisibility('System.Platform.Linux')):
            control.execute('InstallAddon(vfs.libarchive)')

        if not control.conditional_visibility(
                'System.HasAddon(script.module.futures)') and six.PY2:
            if 17.0 <= control.kodi_version() <= 18.9:
                control.execute('InstallAddon(script.module.futures)')
                control.sleep(1500)

        if query:
            query = '{}/imdb=0'.format(re.sub(r'[\(|\)]', '', query))
            # xbmc.log('$#$QUERY-ELSE: %s' % query, xbmc.LOGINFO)
        else:
            if control.condVisibility('Player.HasVideo'):
                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')
                try:
                    imdb = control.infoLabel('VideoPlayer.IMDBNumber')
                    if not imdb:
                        imdb = '0'
                except BaseException:
                    imdb = '0'
            else:
                title = xbmc.getInfoLabel("ListItem.OriginalTitle")
                year = xbmc.getInfoLabel("ListItem.Year")
                tvshowtitle = xbmc.getInfoLabel("ListItem.TVShowTitle")
                season = xbmc.getInfoLabel("ListItem.Season")
                episode = xbmc.getInfoLabel("ListItem.Episode")
                #labelType = xbmc.getInfoLabel("ListItem.DBTYPE")
                try:
                    imdb = control.infoLabel('ListItem.IMDBNumber')
                    # xbmc.log('$#$QUERY-NONE-IMDB: %s' % imdb, xbmc.LOGNOTICE)
                    if not imdb:
                        imdb = '0'
                except BaseException:
                    imdb = '0'

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

            if not tvshowtitle == '':  # episode
                query = '%s S%02dE%02d/imdb=%s' % (tvshowtitle, int(season),
                                                   int(episode), str(imdb))

            elif not year == '':  # movie
                query = '%s (%s)/imdb=%s' % (title, year, str(imdb))

            elif '(S' in title:
                query = '%s/imdb=%s' % (title, str(imdb))

            else:  # file
                query, year = getCleanMovieTitle(title)
                if not year == '':
                    query = '{} ({})/imdb={}'.format(query, year, str(imdb))

        self.query = six.ensure_str(query, encoding='utf-8')

        with concurrent.futures.ThreadPoolExecutor(5) as executor:
            query = self.query
            threads = [
                executor.submit(self.subztv, query),
                executor.submit(self.s4f, query),
                executor.submit(self.yifi, query)
            ]

            for future in concurrent.futures.as_completed(threads):

                item = future.result()

                if not item:
                    continue

                self.list.extend(item)
        # threads = []
        # if control.setting('provider.subztv.club'):
        #     threads.append(workers.Thread(self.subztv))
        # xbmc.log('$#$THREAD1: %s' % threads)
        # if control.setting('provider.s4f'):
        #     threads.append(workers.Thread(self.s4f))
        # xbmc.log('$#$THREAD2: %s' % threads)
        # if control.setting('provider.yifi'):
        #     threads.append(workers.Thread(self.yifi))
        # xbmc.log('$#$THREAD3: %s' % threads)
        #
        # [i.start() for i in threads]
        # [i.join() for i in threads]
        self.list = [i for i in self.list if i]

        f = []

        f += [i for i in self.list if i['source'] == 'subztv']

        f += [i for i in self.list if i['source'] == 's4f']

        f += [i for i in self.list if i['source'] == 'yifi']

        self.list = sorted(f, key=lambda k: k['rating'], reverse=True)
        for i in self.list:
            try:

                if i['source'] == 'subztv':
                    i['name'] = u'[SUBZ] {0}'.format(i['name'])

                elif i['source'] == 's4f':
                    i['name'] = u'[S4F] {0}'.format(i['name'])

                elif i['source'] == 'yifi':
                    i['name'] = u'[YIFI] {0}'.format(i['name'])
            except BaseException:
                pass

        for i in self.list:
            try:
                u = {
                    'action': 'download',
                    'url': i['url'],
                    'source': i['source']
                }
                u = '{0}?{1}'.format(sysaddon, urlencode(u))
                item = control.item(label='Greek', label2=i['name'])
                item.setArt({'icon': str(i['rating'])[:1], 'thumb': 'el'})
                item.setProperty('hearing_imp', 'false')
                control.addItem(handle=syshandle,
                                url=u,
                                listitem=item,
                                isFolder=False)
            except BaseException:
                pass

        control.directory(syshandle)