Пример #1
0
    def __init__(self):
        self.orion = orionoid.Orionoid()

        self.pack = False  # Checked by provider.py
        self.priority = 0
        self.language = ['un']

        self.base_link = self.orion.link()
        self.domains = [network.Networker.linkDomain(self.base_link)]

        enabledPremiumize = debrid.Premiumize().accountValid() and (
            tools.Settings.getBoolean('streaming.torrent.premiumize.enabled')
            or
            tools.Settings.getBoolean('streaming.usenet.premiumize.enabled'))
        enabledOffCloud = debrid.OffCloud().accountValid() and (
            tools.Settings.getBoolean('streaming.torrent.offcloud.enabled')
            or tools.Settings.getBoolean('streaming.usenet.offcloud.enabled'))
        enabledRealDebrid = debrid.RealDebrid().accountValid(
        ) and tools.Settings.getBoolean('streaming.torrent.realdebrid.enabled')
        self.cache = tools.Settings.getBoolean('scraping.cache.enabled') and (
            (enabledPremiumize
             and tools.Settings.getBoolean('scraping.cache.premiumize')) or
            (enabledOffCloud
             and tools.Settings.getBoolean('scraping.cache.offcloud')) or
            (enabledRealDebrid
             and tools.Settings.getBoolean('scraping.cache.realdebrid')))
Пример #2
0
	def _showAccounts(self, first = True):
		if first:
			choice = self._option(35288, 33743, 33821)
			if choice == Wizard.ChoiceLeft: return self._cancel()

		orion = orionoid.Orionoid()
		enabled = interface.Format.fontBold(interface.Format.fontColor(interface.Translation.string(32301), interface.Format.ColorExcellent))
		disabled = interface.Format.fontBold(interface.Format.fontColor(interface.Translation.string(32302), interface.Format.ColorBad))
		special = interface.Translation.string(33105)
		premium = interface.Translation.string(33768)
		provider = interface.Translation.string(33681)
		general = interface.Translation.string(32310)

		items = [
			interface.Format.fontBold(interface.Translation.string(33821)),
			interface.Format.fontBold('[' + special + '] ' + interface.Translation.string(35400) + ': ') + (enabled if orion.accountValid() else disabled),
			interface.Format.fontBold('[' + general + '] ' + interface.Translation.string(32315) + ': ') + (enabled if tools.Settings.getBoolean('accounts.informants.trakt.enabled') else disabled),
			interface.Format.fontBold('[' + general + '] ' + interface.Translation.string(32034) + ': ') + (enabled if tools.Settings.getBoolean('accounts.informants.imdb.enabled') else disabled),
			interface.Format.fontBold('[' + general + '] ' + interface.Translation.string(35260) + ': ') + (enabled if tools.Settings.getBoolean('accounts.artwork.fanart.enabled') else disabled),
			interface.Format.fontBold('[' + premium + '] ' + interface.Translation.string(33566) + ': ') + (enabled if debrid.Premiumize().accountValid() else disabled),
			interface.Format.fontBold('[' + premium + '] ' + interface.Translation.string(35200) + ': ') + (enabled if debrid.OffCloud().accountValid() else disabled),
			interface.Format.fontBold('[' + premium + '] ' + interface.Translation.string(33567) + ': ') + (enabled if debrid.RealDebrid().accountValid() else disabled),
			interface.Format.fontBold('[' + premium + '] ' + interface.Translation.string(33794) + ': ') + (enabled if debrid.EasyNews().accountValid() else disabled),
			interface.Format.fontBold('[' + premium + '] ' + interface.Translation.string(33568) + ': ') + (enabled if debrid.AllDebrid().accountValid() else disabled),
			interface.Format.fontBold('[' + premium + '] ' + interface.Translation.string(33569) + ': ') + (enabled if debrid.RapidPremium().accountValid() else disabled),
		]

		choice = interface.Dialog.options(title = 32346, items = items)
		if choice < 0: return self._cancel()

		if choice == 0:
			return Wizard.OptionContinue
		elif choice == 1:
			if self._showOrion() == Wizard.OptionCancelWizard: return Wizard.OptionCancelWizard
		elif choice == 2:
			if self._showTrakt() == Wizard.OptionCancelWizard: return Wizard.OptionCancelWizard
		elif choice == 3:
			if self._showImdb() == Wizard.OptionCancelWizard: return Wizard.OptionCancelWizard
		elif choice == 4:
			if self._showFanart() == Wizard.OptionCancelWizard: return Wizard.OptionCancelWizard
		elif choice == 5:
			if self._showPremiumize() == Wizard.OptionCancelWizard: return Wizard.OptionCancelWizard
		elif choice == 6:
			if self._showOffCloud() == Wizard.OptionCancelWizard: return Wizard.OptionCancelWizard
		elif choice == 7:
			if self._showRealDebrid() == Wizard.OptionCancelWizard: return Wizard.OptionCancelWizard
		elif choice == 8:
			if self._showEasyNews() == Wizard.OptionCancelWizard: return Wizard.OptionCancelWizard
		elif choice == 9:
			if self._showAllDebrid() == Wizard.OptionCancelWizard: return Wizard.OptionCancelWizard
		elif choice == 10:
			if self._showRapidPremium() == Wizard.OptionCancelWizard: return Wizard.OptionCancelWizard

		return self._showAccounts(first = False)
Пример #3
0
	def _showOrion(self):
		try:
			orion = orionoid.Orionoid()
			choice = self._option(35408, 33897, 33898)
			if choice == Wizard.ChoiceLeft: return Wizard.OptionCancelStep
			choice = self._option(35409, 33899, 33900)
			if choice == Wizard.ChoiceLeft:
				tools.System.openLink(orion.link())
				choice = self._option(35410, 33743, 33898)
				if choice == Wizard.ChoiceLeft: return self._cancel()
			while True:
				if orion.accountUpdate(input = True, loader = True):
					orion.accountEnable()
					choice = self._option(35412, 33743, 33821)
					if choice == Wizard.ChoiceLeft: return self._cancel()
					return Wizard.OptionContinue
				else:
					orion.accountDisable()
					choice = self._option(35413, 33743, 33902)
					if choice == Wizard.ChoiceLeft: return self._cancel()
			return Wizard.OptionContinue
		except:
			tools.Logger.error()
Пример #4
0
	def request(self, timeout = 30, range = None, force = False, parameters = None, addon = False, flare = True, form = None):
		try:
			if self.mResponse == None or force:
				self.mError = False
				self.mErrorCode = None
				self.mResponse = None
				self.mData = None
				json = False
				if self.mLink:
					if parameters == None: parameters = self.mParameters
					try:
						if isinstance(parameters, dict):
							for key, value in parameters.iteritems():
								if isinstance(value, dict) or isinstance(value, list) or isinstance(value, tuple):
									json = True
									break
						if json: parameters = tools.Converter.jsonTo(parameters)
						else: parameters = urllib.urlencode(parameters, doseq = True)
					except: pass

					if form == None:
						request = urllib2.Request(self.mLink, data = parameters)
					else:
						if not isinstance(form, list): form = [form]
						boundry = 'X-X-X-' + str(tools.Time.timestamp()) + '-X-X-X'
						self.mHeadersPost['Content-Type'] = 'multipart/form-data; boundary=%s' % boundry

						data = bytearray('', 'utf8')
						for f in form:
							disposition = 'Content-Disposition: form-data; name="%s"' % f['name']
							if 'filename' in form: disposition += '; filename="%s"' % f['filename']
							disposition += '\n'

							data += bytearray('--%s\n' % boundry, 'utf8')
							data += bytearray(disposition, 'utf8')
							if 'type' in f: data += bytearray('Content-Type: %s\n' % f['type'], 'utf8')
							data += bytearray('\n', 'utf8')
							try: data += bytearray(f['data'], 'utf8')
							except: data += f['data']
							data += bytearray('\n', 'utf8')

						data += bytearray('--%s--\n' % boundry, 'utf8')
						request = urllib2.Request(self.mLink, data = data)

					request.add_header('User-Agent', self.userAgent(randomize = True, mobile = False, addon = addon))
					if json: request.add_header('Content-Type', 'application/json')

					if not range == None:
						start = 0 if range[0] == None else range[0]
						size = 0 if range[1] == None else range[1]
						if start > 0 or size > 0:
							if size == 0: request.add_header('Range', 'bytes=%d-' % start)
							else: request.add_header('Range', 'bytes=%d-%d' % (start, start + size - 1))

					# Will override User-Agent if present in self.mHeadersPost.
					for key, value in self.mHeadersPost.iteritems():
						request.add_header(key, value)

					try:
						secureContext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
						self.mResponse = urllib2.urlopen(request, context = secureContext, timeout = timeout)
					except:
						# SPMC (Python < 2.7.8) does not support TLS. Try to do it wihout SSL/TLS, otherwise bad luck.
						self.mResponse = urllib2.urlopen(request, timeout = timeout)
			return self.mResponse
		except urllib2.HTTPError as error: # HTTP error.
			if flare and parameters == None and error.code == 503 and 'cloudflare' in str(error.info()).lower():
				try:
					from resources.lib.extensions import orionoid
					data = orionoid.Orionoid().flare(link = self.mLink)
					self.mResponse = data['response']
					self.mData = data['body']
					self.mHeaders = {}
					for key, value in data['headers'].iteritems():
						self.mHeaders[key.lower()] = value
					return None # Ensure that the response is not read again.
				except urllib2.HTTPError as error: # HTTP error.
					self.mError = True
					self.mErrorCode = error.code
					if self.mDebug: tools.Logger.log(tools.System.name() + " Network Error [" + self.mLink + "]: " + str(self.mErrorCode))
				except urllib2.URLError as error: # Non-HTTP error, like not able to resolve URL.
					self.mError = True
					self.mErrorCode = error.args
					if self.mDebug: tools.Logger.log(tools.System.name() + " Network Error [" + self.mLink + "]: " + str(self.mErrorCode))
				except: # Other possible errors.
					self.mError = True
					self.mErrorCode = None
					if self.mDebug: tools.Logger.error()
			else:
				self.mError = True
				self.mErrorCode = error.code
				if self.mDebug: tools.Logger.log(tools.System.name() + " Network Error [" + self.mLink + "]: " + str(self.mErrorCode))
		except urllib2.URLError as error: # Non-HTTP error, like not able to resolve URL.
			self.mError = True
			self.mErrorCode = error.args
			if self.mDebug: tools.Logger.log(tools.System.name() + " Network Error [" + self.mLink + "]: " + str(self.mErrorCode))
		except: # Other possible errors.
			self.mError = True
			self.mErrorCode = None
			if self.mDebug: tools.Logger.error()
		return None
Пример #5
0
	def keepPlaybackAlive(self):
		from resources.lib.extensions import core
		self._downloadCheck()

		pname = '%s.player.overlay' % control.addonInfo('id')
		control.window.clearProperty(pname)

		if self.typeMovie:
			overlay = playcount.getMovieOverlay(playcount.getMovieIndicators(), self.idImdb)
		elif self.typeTelevision:
			overlay = playcount.getEpisodeOverlay(playcount.getTVShowIndicators(), self.idImdb, self.idTvdb, self.seasonString, self.episodeString)
		else:
			overlay = '6'

		title = interface.Translation.string(33451)
		status = interface.Translation.string(33452)
		substatus1 = interface.Translation.string(35474)
		substatus2 = interface.Translation.string(35303)
		message = self.progressMessage
		if not message == '':
			if interface.Core.background() and not self.core.progressPlaybackEnabled():
				message += ' - '
			else:
				message += '.' + interface.Format.newline()
		message += status
		interface.Loader.hide()

		self.core.progressPlaybackInitialize(title = title, message = message, metadata = self.metadata)
		timeout = tools.Settings.getInteger('general.playback.timeout')

		# Use a thread for Kodi 18, since the player freezes for a few seconds before starting playback.
		thread = threading.Thread(target = self.keepPlaybackWait, args = (title, message, status, substatus1, substatus2, timeout))
		thread.start()
		thread.join()

		if self.core.progressPlaybackCanceled():
			self.core.progressPlaybackClose()
			self.stop()
			self._debridClear()
			return True

		# Only show the notification if the player is not able to load the file at all.
		if not self.isPlayback():
			self.stop()
			self.core.progressPlaybackUpdate(progress = 100, message = '', status = None) # Must be set to 100 for background dialog, otherwise it shows up in a later dialog.
			control.window.clearProperty(pname)
			return False

		#self.core.progressPlaybackClose()
		addLibrary = tools.Settings.getBoolean('library.updates.watched')
		playbackEnd = tools.Settings.getInteger('general.playback.end') / 100.0

		streamsHas = False
		visibleWas = False

		while self.isPlayingVideo():
			try:
				self.timeTotal = self.getTotalTime()
				self.timeCurrent = self.getTime()

				watcher = (self.timeCurrent / self.timeTotal >= playbackEnd)
				property = control.window.getProperty(pname)

				if watcher == True and not property == '7':
					try: orionoid.Orionoid().streamVote(idItem = self.source['orion']['item'], idStream = self.source['orion']['stream'], vote = orionoid.Orionoid.VoteUp)
					except: pass
					control.window.setProperty(pname, '7')
					if self.typeMovie:
						playcount.markMovieDuringPlayback(self.idImdb, '7')
						if addLibrary: library.Library(type = self.type).add(title = self.title, year = self.year, imdb = self.imdb, tmdb = self.tmdb, metadata = self.metadata)
					else:
						playcount.markEpisodeDuringPlayback(self.idImdb, self.idTvdb, self.seasonString, self.episodeString, '7')
						if addLibrary: library.Library(type = self.type).add(title = self.title, year = self.year, imdb = self.imdb, tvdb = self.tvdb, metadata = self.metadata)
				elif watcher == False and not property == '6':
					control.window.setProperty(pname, '6')
					# Gaia
					# Do not mark as unwatched, otherwise if the video was previously watched and later rewatched, if will mark it as unwatched when played the second time.
					# Trakt can set multiple watches so that you can track on how many times you watched something.
					#playcount.markMovieDuringPlayback(self.idImdb, '6')
					#playcount.markEpisodeDuringPlayback(self.idImdb, self.idTvdb, self.seasonString, self.episodeString, '6')
			except:
				pass

			if self.navigationStreamsSpecial:
				for i in range(4):
					visible = self.isVisible()
					playback = self.isPlayback()
					if not visibleWas and visible: visibleWas = True
					if not streamsHas and playback and visibleWas and not visible:
						streamsHas = True
						self._showStreams()
					elif streamsHas and visible:
						streamsHas = False
						interface.Dialog.closeAll()
					if not self.download == None: self._downloadCheck()
					xbmc.sleep(1000)
			else:
				if self.download == None:
					xbmc.sleep(2000)
				else:
					for i in range(4):
						self._downloadCheck()
						xbmc.sleep(500)

		control.window.clearProperty(pname)
		return True
Пример #6
0
	def _showProviders(self, first = True):
		if first:
			choice = self._option(33908, 33743, 33821)
			if choice == Wizard.ChoiceLeft: return self._cancel()

		orion = orionoid.Orionoid()
		enabled = interface.Format.fontColor(interface.Translation.string(32301), interface.Format.ColorExcellent)
		disabled = interface.Format.fontColor(interface.Translation.string(32302), interface.Format.ColorBad)
		special = '[' + interface.Translation.string(33105) + '] '
		general = '[' + interface.Translation.string(32310) + '] '
		torrent = '[' + interface.Translation.string(33199) + '] '
		usenet = '[' + interface.Translation.string(33200) + '] '
		hoster = '[' + interface.Translation.string(33198) + '] '
		external = '[' + interface.Translation.string(35354) + '] '

		choices = [None]
		items = [interface.Format.fontBold(interface.Translation.string(33821))]

		if orion.accountValid():
			choices.append('specialorion')
			items.append(interface.Format.fontBold(special + interface.Translation.string(35414) + ': ' + (enabled if orion.accountEnabled() else disabled)))

		choices.append('generallocal')
		items.append(interface.Format.fontBold(general + interface.Translation.string(35356) + ': ' + (enabled if tools.Settings.getBoolean('providers.general.local.open.enabled') or tools.Settings.getBoolean('providers.general.local.member.enabled') else disabled)))

		if tools.Settings.getBoolean('accounts.debrid.premiumize.enabled') or tools.Settings.getBoolean('accounts.debrid.offcloud.enabled') or tools.Settings.getBoolean('accounts.debrid.realdebrid.enabled') or tools.Settings.getBoolean('accounts.debrid.easynews.enabled'):
			choices.append('generalpremium')
			items.append(interface.Format.fontBold(general + interface.Translation.string(35357) + ': ' + (enabled if tools.Settings.getBoolean('providers.general.premium.open.enabled') or tools.Settings.getBoolean('providers.general.premium.member.enabled') else disabled)))

		if handler.Handler(handler.Handler.TypeTorrent).serviceHas():
			choices.append('torrentuniversal')
			items.append(interface.Format.fontBold(torrent + interface.Translation.string(35355) + ': ' + (enabled if tools.Settings.getBoolean('providers.torrent.universal.open.enabled') or tools.Settings.getBoolean('providers.torrent.universal.distributed.enabled') or tools.Settings.getBoolean('providers.torrent.universal.member.enabled') else disabled)))
			choices.append('torrentfrench')
			items.append(interface.Format.fontBold(torrent + interface.Translation.string(35033) + ': ' + (enabled if tools.Settings.getBoolean('providers.torrent.french.open.enabled') or tools.Settings.getBoolean('providers.torrent.french.member.enabled') else disabled)))
			choices.append('torrentrussian')
			items.append(interface.Format.fontBold(torrent + interface.Translation.string(35353) + ': ' + (enabled if tools.Settings.getBoolean('providers.torrent.russian.open.enabled') or tools.Settings.getBoolean('providers.torrent.russian.member.enabled') else disabled)))
			choices.append('torrentitalian')
			items.append(interface.Format.fontBold(torrent + interface.Translation.string(35389) + ': ' + (enabled if tools.Settings.getBoolean('providers.torrent.italian.open.enabled') or tools.Settings.getBoolean('providers.torrent.italian.member.enabled') else disabled)))

		if handler.Handler(handler.Handler.TypeUsenet).serviceHas():
			choices.append('usenetuniversal')
			items.append(interface.Format.fontBold(usenet + interface.Translation.string(35355) + ': ' + (enabled if tools.Settings.getBoolean('providers.usenet.universal.open.enabled') or tools.Settings.getBoolean('providers.usenet.universal.member.enabled') else disabled)))

		if handler.Handler(handler.Handler.TypeHoster).serviceHas():
			choices.append('hosteruniversal')
			items.append(interface.Format.fontBold(hoster + interface.Translation.string(35355) + ': ' + (enabled if tools.Settings.getBoolean('providers.hoster.universal.open.enabled') or tools.Settings.getBoolean('providers.hoster.universal.member.enabled') else disabled)))

		choices.append('externalopescrapers')
		items.append(interface.Format.fontBold(external + interface.Translation.string(35550) + ': ' + (enabled if tools.Settings.getBoolean('providers.external.universal.open.opescrapersx') else disabled)))
		choices.append('externallamscrapers')
		items.append(interface.Format.fontBold(external + interface.Translation.string(35530) + ': ' + (enabled if tools.Settings.getBoolean('providers.external.universal.open.lamscrapersx') else disabled)))
		choices.append('externalcivscrapers')
		items.append(interface.Format.fontBold(external + interface.Translation.string(35531) + ': ' + (enabled if tools.Settings.getBoolean('providers.external.universal.open.civscrapersx') else disabled)))
		choices.append('externalgloscrapers')
		items.append(interface.Format.fontBold(external + interface.Translation.string(35532) + ': ' + (enabled if tools.Settings.getBoolean('providers.external.universal.open.gloscrapersx') else disabled)))
		choices.append('externaluniscrapers')
		items.append(interface.Format.fontBold(external + interface.Translation.string(35349) + ': ' + (enabled if tools.Settings.getBoolean('providers.external.universal.open.uniscrapersx') else disabled)))
		choices.append('externalnanscrapers')
		items.append(interface.Format.fontBold(external + interface.Translation.string(35350) + ': ' + (enabled if tools.Settings.getBoolean('providers.external.universal.open.nanscrapersx') else disabled)))
		choices.append('externalincscrapers')
		items.append(interface.Format.fontBold(external + interface.Translation.string(35352) + ': ' + (enabled if tools.Settings.getBoolean('providers.external.universal.open.incscrapersx') else disabled)))
		choices.append('externalplascrapers')
		items.append(interface.Format.fontBold(external + interface.Translation.string(35351) + ': ' + (enabled if tools.Settings.getBoolean('providers.external.universal.open.plascrapersx') else disabled)))
		choices.append('externalyodscrapers')
		items.append(interface.Format.fontBold(external + interface.Translation.string(35533) + ': ' + (enabled if tools.Settings.getBoolean('providers.external.universal.open.yodscrapersx') else disabled)))

		choice = interface.Dialog.options(title = 33014, items = items)
		if choice < 0: return self._cancel()
		choice = choices[choice]

		# Takes about 3 secs. By default they are all set to true, so this can be skipped.
		'''tools.Settings.set('streaming.torrent.enabled', True)
		tools.Settings.set('streaming.torrent.premiumize.enabled', True)
		tools.Settings.set('streaming.torrent.offcloud.enabled', True)
		tools.Settings.set('streaming.torrent.realdebrid.enabled', True)
		tools.Settings.set('streaming.usenet.enabled', True)
		tools.Settings.set('streaming.usenet.premiumize.enabled', True)
		tools.Settings.set('streaming.usenet.offcloud.enabled', True)
		tools.Settings.set('streaming.hoster.enabled', True)
		tools.Settings.set('streaming.hoster.premiumize.enabled', True)
		tools.Settings.set('streaming.hoster.offcloud.enabled', True)
		tools.Settings.set('streaming.hoster.realdebrid.enabled', True)
		tools.Settings.set('streaming.hoster.alldebrid.enabled', True)
		tools.Settings.set('streaming.hoster.rapidpremium.enabled', True)
		tools.Settings.set('streaming.hoster.resolveurl.enabled', True)
		tools.Settings.set('streaming.hoster.urlresolver.enabled', True)'''

		defaultTorrent = 0
		defaultUsenet = 0
		defaultHoster = 0
		handlerPremium = tools.Settings.getBoolean('accounts.debrid.premiumize.enabled')
		handlerOffcloud = tools.Settings.getBoolean('accounts.debrid.offcloud.enabled')
		handlerRealdebrid = tools.Settings.getBoolean('accounts.debrid.realdebrid.enabled')
		handlers = int(handlerPremium) + int(handlerOffcloud) + int(handlerRealdebrid)
		if handlers == 1:
			defaultTorrent = 1 if handlerPremium else 2 if handlerOffcloud else 3
			defaultUsenet = 1 if handlerPremium else 2 if handlerOffcloud else 0
			defaultHoster = 1 if handlerPremium else 2 if handlerOffcloud else 3
		tools.Settings.set('streaming.torrent.default', defaultTorrent)
		tools.Settings.set('streaming.usenet.default', defaultUsenet)
		tools.Settings.set('streaming.hoster.default', defaultHoster)

		if choice == None:
			interface.Loader.show()
			count = len(provider.Provider.providers())
			interface.Loader.hide()
			if count > 200:
				if self._option(interface.Translation.string(33909) % count, 35045, 35044) == Wizard.ChoiceLeft:
					return self._showProviders(first = False)
			return Wizard.OptionContinue
		elif choice == 'specialorion':
			active = self._option(35415, 33737, 33192) == Wizard.ChoiceRight
			orion.accountEnable(active)
		elif choice == 'generallocal':
			active = self._option(33958, 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.general.local.open.enabled', active)
			tools.Settings.set('providers.general.local.member.enabled', active)
		elif choice == 'generalpremium':
			active = self._option(33906, 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.general.premium.open.enabled', active)
			tools.Settings.set('providers.general.premium.member.enabled', active)
		elif choice == 'torrentuniversal':
			active = self._option(interface.Translation.string(33956) % interface.Translation.string(35358), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.torrent.universal.open.enabled', active)
			tools.Settings.set('providers.torrent.universal.distributed.enabled', active)
			tools.Settings.set('providers.torrent.universal.member.enabled', active)
		elif choice == 'torrentfrench':
			active = self._option(interface.Translation.string(33956) % interface.Translation.string(33790), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.torrent.french.open.enabled', active)
			tools.Settings.set('providers.torrent.french.member.enabled', active)
		elif choice == 'torrentrussian':
			active = self._option(interface.Translation.string(33956) % interface.Translation.string(33992), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.torrent.russian.open.enabled', active)
			tools.Settings.set('providers.torrent.russian.member.enabled', active)
		elif choice == 'torrentitalian':
			active = self._option(interface.Translation.string(33956) % interface.Translation.string(35388), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.torrent.italian.open.enabled', active)
			tools.Settings.set('providers.torrent.italian.member.enabled', active)
		elif choice == 'usenetuniversal':
			active = self._option(interface.Translation.string(33957) % interface.Translation.string(35358), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.usenet.universal.open.enabled', active)
			tools.Settings.set('providers.usenet.universal.member.enabled', active)
		elif choice == 'hosteruniversal':
			active = self._option(interface.Translation.string(33905) % interface.Translation.string(35358), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.hoster.universal.open.enabled', active)
			tools.Settings.set('providers.hoster.universal.member.enabled', active)
		elif choice == 'externalopescrapers':
			active = self._option(interface.Translation.string(33907) % interface.Translation.string(35548), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.external.universal.open.opescrapersx', active)
		elif choice == 'externallamscrapers':
			active = self._option(interface.Translation.string(33907) % interface.Translation.string(35431), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.external.universal.open.lamscrapersx', active)
		elif choice == 'externalcivscrapers':
			active = self._option(interface.Translation.string(33907) % interface.Translation.string(35504), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.external.universal.open.civscrapersx', active)
		elif choice == 'externalgloscrapers':
			active = self._option(interface.Translation.string(33907) % interface.Translation.string(35534), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.external.universal.open.gloscrapersx', active)
		elif choice == 'externaluniscrapers':
			active = self._option(interface.Translation.string(33907) % interface.Translation.string(35359), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.external.universal.open.uniscrapersx', active)
		elif choice == 'externalnanscrapers':
			active = self._option(interface.Translation.string(33907) % interface.Translation.string(35360), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.external.universal.open.nanscrapersx', active)
		elif choice == 'externalincscrapers':
			active = self._option(interface.Translation.string(33907) % interface.Translation.string(35362), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.external.universal.open.incscrapersx', active)
		elif choice == 'externalplascrapers':
			active = self._option(interface.Translation.string(33907) % interface.Translation.string(35361), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.external.universal.open.plascrapersx', active)
		elif choice == 'externalyodscrapers':
			active = self._option(interface.Translation.string(33907) % interface.Translation.string(35535), 33737, 33192) == Wizard.ChoiceRight
			tools.Settings.set('providers.external.universal.open.yodscrapersx', active)

		return self._showProviders(first = False)
Пример #7
0
def request(url,
            close=True,
            redirect=True,
            error=False,
            proxy=None,
            post=None,
            headers=None,
            mobile=False,
            XHR=False,
            limit=None,
            referer=None,
            cookie=None,
            compression=True,
            output='',
            timeout='30',
            ignoreSsl=False,
            flare=True):
    try:
        # Gaia
        if url == None: return None

        handlers = []

        if not proxy == None:
            handlers += [
                urllib2.ProxyHandler({'http': '%s' % (proxy)}),
                urllib2.HTTPHandler
            ]
            opener = urllib2.build_opener(*handlers)
            opener = urllib2.install_opener(opener)

        if output == 'cookie' or output == 'extended' or not close == True:
            cookies = cookielib.LWPCookieJar()
            handlers += [
                urllib2.HTTPHandler(),
                urllib2.HTTPSHandler(),
                urllib2.HTTPCookieProcessor(cookies)
            ]
            opener = urllib2.build_opener(*handlers)
            opener = urllib2.install_opener(opener)

        if ignoreSsl or ((2, 7, 8) < sys.version_info < (2, 7, 12)):
            try:
                import ssl
                ssl_context = ssl.create_default_context()
                ssl_context.check_hostname = False
                ssl_context.verify_mode = ssl.CERT_NONE
                handlers += [urllib2.HTTPSHandler(context=ssl_context)]
                opener = urllib2.build_opener(*handlers)
                opener = urllib2.install_opener(opener)
            except:
                pass

        if url.startswith('//'): url = 'http:' + url

        try:
            headers.update(headers)
        except:
            headers = {}
        if 'User-Agent' in headers:
            pass
        elif not mobile == True:
            #headers['User-Agent'] = agent()
            headers['User-Agent'] = cache.get(randomagent, 1)
        else:
            headers['User-Agent'] = 'Apple-iPhone/701.341'
        if 'Referer' in headers:
            pass
        elif referer is not None:
            headers['Referer'] = referer
        if not 'Accept-Language' in headers:
            headers['Accept-Language'] = 'en-US'
        if 'X-Requested-With' in headers:
            pass
        elif XHR == True:
            headers['X-Requested-With'] = 'XMLHttpRequest'
        if 'Cookie' in headers:
            pass
        elif not cookie == None:
            headers['Cookie'] = cookie
        if 'Accept-Encoding' in headers:
            pass
        elif compression and limit is None:
            headers['Accept-Encoding'] = 'gzip'

        if redirect == False:

            class NoRedirection(urllib2.HTTPErrorProcessor):
                def http_response(self, request, response):
                    return response

            opener = urllib2.build_opener(NoRedirection)
            opener = urllib2.install_opener(opener)

            try:
                del headers['Referer']
            except:
                pass

        if isinstance(post, dict):
            # [GAIA]
            # Gets rid of the error: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
            for key, value in post.iteritems():
                try:
                    post[key] = value.encode('utf-8')
                except:
                    pass
            # [/GAIA]

            post = urllib.urlencode(post)

        request = urllib2.Request(url, data=post)
        _add_request_header(request, headers)

        try:
            response = urllib2.urlopen(request, timeout=int(timeout))
        except urllib2.HTTPError as response:

            if response.code == 503:
                cf_result = response.read(5242880)
                try:
                    encoding = response.info().getheader('Content-Encoding')
                except:
                    encoding = None
                if encoding == 'gzip':
                    cf_result = gzip.GzipFile(
                        fileobj=StringIO.StringIO(cf_result)).read()

                if flare and 'cloudflare' in str(response.info()).lower():
                    try:
                        from resources.lib.extensions import orionoid
                        response = orionoid.Orionoid().flare(link=url)
                        result = response['body']
                        response = response['response']
                        flare = 'cloudflare'  # Used below
                    except:
                        from resources.lib.extensions import tools
                        tools.Logger.error()

                elif 'cf-browser-verification' in cf_result:

                    netloc = '%s://%s' % (urlparse.urlparse(url).scheme,
                                          urlparse.urlparse(url).netloc)

                    ua = headers['User-Agent']

                    cf = cache.get(cfcookie().get, 168, netloc, ua, timeout)

                    headers['Cookie'] = cf

                    request = urllib2.Request(url, data=post)
                    _add_request_header(request, headers)

                    response = urllib2.urlopen(request, timeout=int(timeout))
                else:
                    log_utils.log(
                        'Request-Error (%s): %s' % (str(response.code), url),
                        log_utils.LOGDEBUG)
                    if error == False: return
            else:
                log_utils.log(
                    'Request-Error (%s): %s' % (str(response.code), url),
                    log_utils.LOGDEBUG)
                if error == False: return

        if output == 'cookie':
            try:
                result = '; '.join(
                    ['%s=%s' % (i.name, i.value) for i in cookies])
            except:
                pass
            try:
                result = cf
            except:
                pass
            if close == True: response.close()
            return result

        elif output == 'geturl':
            result = response.geturl()
            if close == True: response.close()
            return result

        elif output == 'headers':
            result = response.headers
            if close == True: response.close()
            return result

        elif output == 'chunk':
            try:
                content = int(response.headers['Content-Length'])
            except:
                content = (2049 * 1024)
            if content < (2048 * 1024): return
            result = response.read(16 * 1024)
            if close == True: response.close()
            return result

        if not flare == 'cloudflare':
            if limit == '0':
                result = response.read(224 * 1024)
            elif not limit == None:
                result = response.read(int(limit) * 1024)
            else:
                result = response.read(5242880)

        try:
            encoding = response.info().getheader('Content-Encoding')
        except:
            encoding = None
        if encoding == 'gzip':
            result = gzip.GzipFile(fileobj=StringIO.StringIO(result)).read()

        if 'sucuri_cloudproxy_js' in result:
            su = sucuri().get(result)

            headers['Cookie'] = su

            request = urllib2.Request(url, data=post)
            _add_request_header(request, headers)

            response = urllib2.urlopen(request, timeout=int(timeout))

            if limit == '0':
                result = response.read(224 * 1024)
            elif not limit == None:
                result = response.read(int(limit) * 1024)
            else:
                result = response.read(5242880)

            try:
                encoding = response.info().getheader('Content-Encoding')
            except:
                encoding = None
            if encoding == 'gzip':
                result = gzip.GzipFile(
                    fileobj=StringIO.StringIO(result)).read()

        if 'Blazingfast.io' in result and 'xhr.open' in result:
            netloc = '%s://%s' % (urlparse.urlparse(url).scheme,
                                  urlparse.urlparse(url).netloc)
            ua = headers['User-Agent']
            headers['Cookie'] = cache.get(bfcookie().get, 168, netloc, ua,
                                          timeout)

            result = _basic_request(url,
                                    headers=headers,
                                    post=post,
                                    timeout=timeout,
                                    limit=limit)

        if output == 'extended':
            try:
                response_headers = dict([(item[0].title(), item[1])
                                         for item in response.info().items()])
            except:
                response_headers = response.headers
            response_code = str(response.code)
            try:
                cookie = '; '.join(
                    ['%s=%s' % (i.name, i.value) for i in cookies])
            except:
                pass
            try:
                cookie = cf
            except:
                pass
            if close == True: response.close()
            return (result, response_code, response_headers, headers, cookie)
        else:
            if close == True: response.close()
            return result
    except Exception as e:
        # Gaia
        from resources.lib.extensions import tools
        tools.Logger.error()
        log_utils.log('Request-Error: (%s) => %s' % (str(e), url),
                      log_utils.LOGDEBUG)
        return
Пример #8
0
 def silent(self, silent=True):
     self.orion = orionoid.Orionoid(silent=silent)