Пример #1
0
    def get(self, netloc, ua, timeout):
        threads = []

        for i in range(0, 15): threads.append(workers.Thread(self.get_cookie, netloc, ua, timeout))
        [i.start() for i in threads]

        for i in range(0, 30):
            if not self.cookie == None: return self.cookie
            time.sleep(1)
Пример #2
0
    def video_list(self, cid, url, pagination):
        try:
            result = client.request(url)
            result = json.loads(result)
            items = result['items']
        except:
            pass

        for i in range(1, 5):
            try:
                if pagination == True: raise Exception()
                if not 'nextPageToken' in result: raise Exception()
                page = url + '&pageToken=' + result['nextPageToken']
                result = client.request(page)
                result = json.loads(result)
                items += result['items']
            except:
                pass

        try:
            if pagination == False: raise Exception()
            next = cid + '&pageToken=' + result['nextPageToken']
        except:
            next = ''

        for item in items: 
            try:
                title = item['snippet']['title']
                title = title.encode('utf-8')

                try: url = item['snippet']['resourceId']['videoId']
                except: url = item['id']['videoId']
                url = url.encode('utf-8')

                image = item['snippet']['thumbnails']['high']['url']
                if '/default.jpg' in image: raise Exception()
                image = image.encode('utf-8')

                append = {'title': title, 'url': url, 'image': image}
                if not next == '': append['next'] = next
                self.list.append(append)
            except:
                pass

        try:
            u = [range(0, len(self.list))[i:i+50] for i in range(len(range(0, len(self.list))))[::50]]
            u = [','.join([self.list[x]['url'] for x in i]) for i in u]
            u = [self.content_link % i + self.key_link for i in u]

            threads = []
            for i in range(0, len(u)):
                threads.append(workers.Thread(self.thread, u[i], i))
                self.data.append('')
            [i.start() for i in threads]
            [i.join() for i in threads]

            items = []
            for i in self.data: items += json.loads(i)['items']
        except:
            pass

        for item in range(0, len(self.list)):
            try:
                vid = self.list[item]['url']

                self.list[item]['url'] = self.play_link % vid

                d = [(i['id'], i['contentDetails']) for i in items]
                d = [i for i in d if i[0] == vid]
                d = d[0][1]['duration']

                duration = 0
                try: duration += 60 * 60 * int(re.findall('(\d*)H', d)[0])
                except: pass
                try: duration += 60 * int(re.findall('(\d*)M', d)[0])
                except: pass
                try: duration += int(re.findall('(\d*)S', d)[0])
                except: pass
                duration = str(duration)

                self.list[item]['duration'] = duration
            except:
                pass

        return self.list
Пример #3
0
    def getSources(self,
                   title,
                   year,
                   imdb,
                   tvdb,
                   season,
                   episode,
                   tvshowtitle,
                   premiered,
                   quality='HD',
                   timeout=10):
        u = None

        self.prepareSources()

        sourceDict = self.sourceDict

        content = 'movie' if tvshowtitle == None else 'episode'
        if content == 'movie':
            sourceDict = [(i[0], i[1], getattr(i[1], 'movie', None))
                          for i in sourceDict]
        else:
            sourceDict = [(i[0], i[1], getattr(i[1], 'tvshow', None))
                          for i in sourceDict]
        sourceDict = [(i[0], i[1]) for i in sourceDict if not i[2] == None]

        sourceDict = [(i[0], i[1], i[1].priority) for i in sourceDict]

        if quality == 'SD':
            sourceDict = [i for i in sourceDict if i[2] == 0]

        threads = []

        if content == 'movie':
            title = self.getTitle(title)
            for i in sourceDict:
                threads.append(
                    workers.Thread(self.getMovieSource, title, title, year,
                                   imdb, i[0], i[1]))
        else:
            tvshowtitle = self.getTitle(tvshowtitle)
            for i in sourceDict:
                threads.append(
                    workers.Thread(self.getEpisodeSource, title, year, imdb,
                                   tvdb, season, episode, tvshowtitle,
                                   tvshowtitle, premiered, i[0], i[1]))

        s = [i[0] + (i[1], ) for i in zip(sourceDict, threads)]
        s = [(i[3].getName(), i[0], i[2]) for i in s]

        mainsourceDict = [i[0] for i in s if i[2] == 0]

        [i.start() for i in threads]

        progressDialog = control.progressDialog
        progressDialog.create(control.addonInfo('name'),
                              control.lang(30726).encode('utf-8'))
        progressDialog.update(0)

        progressDialog.update(0,
                              control.lang(30726).encode('utf-8'),
                              control.lang(30731).encode('utf-8'))

        for i in range(0, (timeout * 2) + 60):
            try:
                if xbmc.abortRequested == True: return sys.exit()

                timerange = int(i * 0.5)

                try:
                    if progressDialog.iscanceled(): break
                except:
                    pass

                is_alive = [x.is_alive() for x in threads]
                if all(x == False for x in is_alive): break

                if timerange >= timeout:
                    is_alive = [
                        x for x in threads if x.is_alive() == True
                        and x.getName() in mainsourceDict
                    ]
                    if not is_alive: break

                time.sleep(0.5)
            except:
                pass

        progressDialog.update(50,
                              control.lang(30726).encode('utf-8'),
                              control.lang(30731).encode('utf-8'))

        items = self.sourcesFilter()

        filter = [
            i for i in items
            if i['source'].lower() in self.hostcapDict and i['debrid'] == ''
        ]
        items = [i for i in items if not i in filter]

        filter = [
            i for i in items
            if i['source'].lower() in self.hostblockDict and i['debrid'] == ''
        ]
        items = [i for i in items if not i in filter]

        items = [
            i for i in items if ('autoplay' in i and i['autoplay'] == True)
            or not 'autoplay' in i
        ]

        for i in range(len(items)):
            try:
                if progressDialog.iscanceled(): break
                if xbmc.abortRequested == True: return sys.exit()
                url = self.sourcesResolve(items[i])
                if u == None: u = url
                if not url == None: break
            except:
                pass

        try:
            progressDialog.close()
        except:
            pass

        return u
Пример #4
0
    def resolve(self, url):
        try:
            m3u8 = [
                '#EXTM3U',
                '#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",DEFAULT=YES,AUTOSELECT=YES,NAME="Stream 1",URI="{audio_stream}"',
                '',
                '#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=0,NAME="{stream_name}",AUDIO="audio"',
                '{video_stream}'
            ]

            query = urlparse.parse_qs(url)
            query = dict([(key, query[key][0]) if query[key] else (key, '')
                          for key in query])

            auth = 'http://streamtorrent.tv/api/torrent/%s/%s.m3u8?json=true' % (
                query['vid_id'], query['stream_id'])

            r = client.request(auth)
            r = json.loads(r)
            try:
                url = r['url']
            except:
                url = None

            if not url == None:

                def dialog(url):
                    try:
                        self.disableScraper = control.yesnoDialog(
                            'To watch this video visit from any device',
                            '[COLOR skyblue]%s[/COLOR]' % url, '', 'Torba',
                            'Cancel', 'Settings')
                    except:
                        pass

                workers.Thread(dialog, url).start()
                control.sleep(3000)

                for i in range(100):
                    try:
                        if not control.condVisibility(
                                'Window.IsActive(yesnoDialog)'):
                            break

                        r = client.request(auth)
                        r = json.loads(r)
                        try:
                            url = r['url']
                        except:
                            url = None

                        if url == None: break

                        workers.Thread(dialog, url).start()
                        control.sleep(3000)
                    except:
                        pass

                if self.disableScraper:
                    control.openSettings(query='2.0')
                    return ''

                control.execute('Dialog.Close(yesnoDialog)')

            if not url == None: return

            stream_name = '%sp' % (query['height'])
            video_stream = r[stream_name]

            if not 'audio' in r: return video_stream

            audio_stream = r['audio']

            content = ('\n'.join(m3u8)).format(
                **{
                    'audio_stream': audio_stream,
                    'stream_name': stream_name,
                    'video_stream': video_stream
                })

            path = os.path.join(control.dataPath, 'torbase.m3u8')

            control.makeFile(control.dataPath)
            control.deleteFile(path)

            file = control.openFile(path, 'w')
            file.write(content)
            file.close()

            return path
        except:
            return