def lotteryDialog(self): from resources.lib.extensions import interface type = tools.Settings.getString('general.statistics.lottery.type') voucher = tools.Settings.getString('general.statistics.lottery.voucher') description = tools.Settings.getString('general.statistics.lottery.description') instruction = tools.Settings.getString('general.statistics.lottery.instruction') timeClaim = tools.Settings.getInteger('general.statistics.lottery.time.claim') timeExpiry = tools.Settings.getInteger('general.statistics.lottery.time.expiry') timeDuration = tools.Settings.getInteger('general.statistics.lottery.time.duration') indent = ' ' message = interface.Format.bold(interface.Translation.string(33875)) + interface.Format.newline() message += '%s%s: %s' % (indent, interface.Translation.string(33343), interface.Format.bold(type)) + interface.Format.newline() message += '%s%s: %s' % (indent, interface.Translation.string(33876), interface.Format.bold(voucher)) + interface.Format.newline() if description: message += '%s%s: %s' % (indent, interface.Translation.string(33040), interface.Format.bold(description)) + interface.Format.newline() if instruction: message += instruction if not message.endswith('.'): message += '.' if timeExpiry and timeDuration: expirationDuration = convert.ConverterDuration(timeDuration, convert.ConverterDuration.UnitSecond).string(format = convert.ConverterDuration.FormatWordLong, unit = convert.ConverterDuration.UnitDay) expirationTime = convert.ConverterTime(timeExpiry, convert.ConverterTime.FormatTimestamp).string(format = convert.ConverterTime.FormatDate) expiration = '%s (%s)' % (expirationDuration, expirationTime) message += ' ' + (interface.Translation.string(33877) % expiration) message += ' ' + interface.Translation.string(33878) interface.Dialog.confirm(title = 33879, message = message) interface.Player().stop()
def _addWaitAction(self, result, seconds = None): # Ask to close a background dialog, because there is no cancel button as with the foreground dialog. elapsed = self.mTimer.elapsed() conditionShort = self.mTimerShort == False and elapsed > 30 conditionLong = self.mTimerLong == False and elapsed > 120 if conditionShort or conditionLong: if conditionShort: question = 'The download is taking a bit longer.' else: question = 'The download is taking a lot longer.' if seconds: question += ' The estimated remaining time is ' + convert.ConverterDuration(seconds, convert.ConverterDuration.UnitSecond).string(format = convert.ConverterDuration.FormatWordMedium) + '.' else: question += ' The estimated remaining time is currently unknown.' if conditionShort: question += ' Do you want to take action or let the download continue in the background?' else: question += ' Are you sure you do not want to take action and let the download continue in the background?' if conditionShort: self.mTimerShort = True if conditionLong: self.mTimerLong = True title = core.Core.Name + ' Download' answer = interface.Dialog.option(title = title, message = question, labelConfirm = 'Take Action', labelDeny = 'Continue Download') if answer: self._addAction(result) return True return False
def sources(self, url, hostDict, hostprDict): self.tSources = [] try: if url == None: raise Exception() ignoreContains = None data = self._decode(url) if 'exact' in data and data['exact']: query = title = data['tvshowtitle'] if 'tvshowtitle' in data else data['title'] titles = None year = None season = None episode = None pack = False packCount = None else: title = data['tvshowtitle'] if 'tvshowtitle' in data else data['title'] titles = data['alternatives'] if 'alternatives' in data else None year = int(data['year']) if 'year' in data and not data['year'] == None else None season = int(data['season']) if 'season' in data and not data['season'] == None else None episode = int(data['episode']) if 'episode' in data and not data['episode'] == None else None pack = data['pack'] if 'pack' in data else False packCount = data['packcount'] if 'packcount' in data else None if 'tvshowtitle' in data: # Search special episodes by name. All special episodes are added to season 0 by Trakt and TVDb. Hence, do not search by filename (eg: S02E00), since the season is not known. if (season == 0 or episode == 0) and ('title' in data and not data['title'] == None and not data['title'] == ''): title = '%s %s' % (data['tvshowtitle'], data['title']) # Change the title for metadata filtering. query = title ignoreContains = len(data['title']) / float(len(title)) # Increase the required ignore ration, since otherwise individual episodes and season packs are found as well. else: if pack: query = '%s %d' % (title, season) else: query = '%s S%02dE%02d' % (title, season, episode) else: query = '%s %d' % (title, year) query = re.sub('(\\\|/| -|:|;|\*|\?|"|\'|<|>|\|)', ' ', query) query = urllib.quote_plus(query) if not self._query(query): return sources url = urlparse.urljoin(self.base_link, self.search_link) pageLimit = tools.Settings.getInteger('scraping.providers.pages') pageCounter = 0 # Page starts at 1, but incremented before first request. timerTimeout = tools.Settings.getInteger('scraping.providers.timeout') timerEnd = timerTimeout - 8 timer = tools.Time(start = True) threads = [] self.tLock = threading.Lock() while True: try: # Stop searching 8 seconds before the provider timeout, otherwise might continue searching, not complete in time, and therefore not returning any links. if timer.elapsed() > timerEnd: break added = False pageCounter += 1 if pageLimit > 0 and pageCounter > pageLimit: break html = BeautifulSoup(client.request(url % (query, pageCounter))) htmlTable = html.find_all('table', class_ = 'results') htmlTable = htmlTable[len(htmlTable) - 1] htmlRows = htmlTable.find_all('tr') for i in range(1, len(htmlRows)): try: htmlRow = htmlRows[i] htmlColumns = htmlRow.find_all('td', recursive = False) # Use children and no further. # Name htmlName = htmlColumns[0].find_all('a')[0].getText() # Link htmlLink = urlparse.urljoin(self.base_link, htmlColumns[0].find_all('a')[0]['href']) # Size htmlSize = htmlColumns[1].getText() # Age htmlAge = htmlColumns[3].getText() htmlAge = int(convert.ConverterDuration(htmlAge).value(convert.ConverterDuration.UnitDay)) # Metadata meta = metadata.Metadata(name = htmlName, title = title, titles = titles, year = year, season = season, episode = episode, pack = pack, packCount = packCount, link = htmlLink, size = htmlSize, age = htmlAge) # Ignore meta.ignoreAdjust(contains = ignoreContains, length = 0.3) if meta.ignore(False): continue # Add self.tLock.acquire() self.tSources.append({'url' : None, 'debridonly' : False, 'direct' : False, 'source' : 'usenet', 'language' : self.language[0], 'quality': meta.videoQuality(), 'metadata' : meta, 'file' : htmlName}) self.tLock.release() added = True # Link thread = threading.Thread(target = self._link, args = (htmlLink, len(self.tSources) - 1)) threads.append(thread) thread.start() except: pass if not added: break except: break # First filter out all non-related links before doing the hash lookup. timerTimeout -= 2 while True: if timer.elapsed() > timerTimeout: break if not any([thread.is_alive() for thread in threads]): break tools.Time.sleep(0.5) try: self.tLock.release() except: pass except: try: self.tLock.release() except: pass return [i for i in self.tSources if i['url']]