def download(self, path, url):
        try:
            result = client.request(url)

            f = os.path.splitext(urlparse.urlparse(url).path)[1][1:]
            f = os.path.join(path, 'file.%s' % f)

            with open(f, 'wb') as subFile:
                subFile.write(result)
            subFile.close()

            dirs, files = control.listDir(path)

            if len(files) == 0: return

            control.execute('Extract("%s","%s")' % (f, path))

            for i in range(0, 10):
                try:
                    dirs, files = control.listDir(path)
                    if len(files) > 1: break
                    control.sleep(1000)
                except:
                    pass

            control.deleteFile(f)

            subtitle = [
                i for i in files if any(
                    i.endswith(x) for x in ['.srt', '.sub'])
            ][0]

            subtitle = os.path.join(path, subtitle.decode('utf-8'))

            return subtitle
        except:
            pass
Exemplo n.º 2
0
    def run(self, query=None):

        if not 'Greek' in str(langs).split(','):
            control.directory(int(sys.argv[1]))
            control.infoDialog(control.lang(32002).encode('utf-8'))
            return

        if query == None:
            title = control.infoLabel('VideoPlayer.Title')

            if not re.search(r'[^\x00-\x7F]+', title) == 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 = xbmc.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.subztvgr))

        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 xbmc.abortRequested == True: break
                control.sleep(500)
            except:
                pass

        if len(self.list) == 0:
            control.directory(int(sys.argv[1]))
            return

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

        for i in self.list:
            try:
                if i['source'] == 'subztvgr':
                    i['name'] = '[subztvgr] %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' % (sys.argv[0], 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=int(sys.argv[1]),
                                url=u,
                                listitem=item,
                                isFolder=False)
            except:
                pass

        control.directory(int(sys.argv[1]))
Exemplo n.º 3
0
    def download(self, path, url):
        try:
            url = re.findall('/(\d+)/', url + '/', re.I)[-1]
            url = 'http://www.findsubtitles.eu/getp.php?id=%s' % url
            url = client.request(url, output='geturl')

            data = urllib2.urlopen(url, timeout=10).read()
            zip = zipfile.ZipFile(StringIO.StringIO(data))
            files = zip.namelist()
            files = [i for i in files if i.startswith('subs/')]
            srt = [
                i for i in files if any(
                    i.endswith(x) for x in ['.srt', '.sub'])
            ]
            rar = [
                i for i in files if any(
                    i.endswith(x) for x in ['.rar', '.zip'])
            ]

            if len(srt) > 0:
                result = zip.open(srt[0]).read()

                subtitle = os.path.basename(srt[0])

                subtitle = os.path.join(path, subtitle.decode('utf-8'))

                with open(subtitle, 'wb') as subFile:
                    subFile.write(result)
                subFile.close()

                return subtitle

            elif len(rar) > 0:
                result = zip.open(rar[0]).read()

                f = os.path.splitext(urlparse.urlparse(rar[0]).path)[1][1:]
                f = os.path.join(path, 'file.%s' % f)

                with open(f, 'wb') as subFile:
                    subFile.write(result)
                subFile.close()

                dirs, files = control.listDir(path)

                if len(files) == 0: return

                control.execute('Extract("%s","%s")' % (f, path))

                for i in range(0, 10):
                    try:
                        dirs, files = control.listDir(path)
                        if len(files) > 1: break
                        control.sleep(1000)
                    except:
                        pass

                control.deleteFile(f)

                subtitle = [
                    i for i in files if any(
                        i.endswith(x) for x in ['.srt', '.sub'])
                ][0]

                subtitle = os.path.join(path, subtitle.decode('utf-8'))

                return subtitle

        except:
            pass