Ejemplo n.º 1
0
 def _request(self,
              index,
              method,
              category,
              action,
              id=None,
              parameters=None,
              authentication=True):
     link = self._link(index=index, category=category, action=action, id=id)
     headers = self._requestHeaders(index=index)
     networker = network.Networker()
     result = networker.retrieveJson(method=method,
                                     json=not parameters is None,
                                     link=link,
                                     headers=headers,
                                     parameters=parameters)
     if networker.errorCode(
     ) == 401 and authentication:  # Reauthenticate if token is expiered or revoked.
         self._authenticate(index=index)
         result = self._request(index=index,
                                method=method,
                                category=category,
                                action=action,
                                parameters=parameters,
                                authentication=False)
     return result
Ejemplo n.º 2
0
	def _headers(self):
		try:
			networker = network.Networker()
			data = networker.retrieve(self.base_link)
			id = re.findall('token\s*:\s*(.*)', data, re.I)[-1].strip()
			token = re.findall(id + '\s*=\s*[\'"](.*?)[;\'"]', data, re.I)[-1].strip()
			token += ''.join(re.findall(id + '\s*\+=\s*[\'"](.*?)[;\'"]', data, re.I))
			headers = {'X-Request-Token' : token}
			return headers, networker
		except:
			tools.Logger.error()
			return None, None
Ejemplo n.º 3
0
	def _request(self, type = None, action = None, parameters = {}, raw = False):
		if not type == None: parameters[self.ParameterType] = type
		if not action == None: parameters[self.ParameterAction] = action

		time = tools.Time.timestamp()
		parameters[self.ParameterKey] = tools.Hash.sha256(tools.Converter.base64From(tools.Settings.getString(tools.Converter.base64From('aW50ZXJuYWwuYXBp'), raw = True), 15 % 10) + str(time) + tools.System.name().lower())
		parameters[self.ParameterTime] = time
		try:
			result = network.Networker(link = self.Link, parameters = parameters).retrieve(addon = True)
			if raw:
				return result
			else:
				result = tools.Converter.jsonFrom(result)
				if result['success']: return result['data']
				else: return None
		except:
			return None
Ejemplo n.º 4
0
    def _authentication(self, url):
        if not '|Cookie' in url:  # Avoid adding multiple cookies in case the URL is resolved multiple times.
            link = self.base_link + self.login_link
            data = {'id': self.username, 'pass': self.password}

            # NB: Must make two requests.
            # The first request does not have any CloudFlare cookies. YGG will return its own cookie, but it will be an unauthenticated-cookie.
            # Make a second request with the CloudFlare cookies to get an authenticated-cookie.
            # Both requests must use the same networker in order to share the cookie jar.
            net = network.Networker()
            cookies = net.cookies(link=link,
                                  parameters=data,
                                  raw=True,
                                  force=True)
            cookies = net.cookies(link=link,
                                  parameters=data,
                                  raw=True,
                                  force=True,
                                  headers={'Cookie': cookies})

            if cookies: url += '|Cookie=' + urllib.quote_plus(cookies)
        return url
Ejemplo n.º 5
0
	from resources.lib.extensions import interface
	from resources.lib.extensions import clipboard
	from resources.lib.extensions import network
	from resources.lib.extensions import tools
	try:
		interface.Loader.show() # Needs some time to load. Show busy.
		if 'link' in params:
			link = params.get('link')
		elif 'source' in params:
			link = source['url']
			if 'resolve' in params and tools.Converter.boolean(params.get('resolve')):
				if 'urlresolved' in source:
					link = source['urlresolved']
				else:
					from resources.lib.extensions import network
					link = network.Networker().resolve(source, clean = True)
			if not link: # Sometimes resolving does not work. Eg: 404 errors.
				link = source['url']
			link = network.Networker(link).link() # Clean link
		clipboard.Clipboard.copyLink(link, True)
	except:
		pass
	interface.Loader.hide()

elif action == 'copyClipboard':
	from resources.lib.extensions import interface
	from resources.lib.extensions import clipboard
	try:
		interface.Loader.show() # Needs some time to load. Show busy.
		clipboard.Clipboard.copy(params.get('value'), True)
	except:
Ejemplo n.º 6
0
	def handle(self, link, item, download = False, popups = False, close = True, select = False, cloud = False):
		try:
			parameters = {}

			# Link
			parameters['uri'] = network.Networker.quote(link)

			# Type
			type = None
			if 'type' in item and not 'type' == None:
				if item['type'] == tools.Media.TypeShow:
					type = 'episode'
				else:
					type = 'movie'
			elif 'tvshowtitle' in item:
				type = 'episode'
			else:
				type = 'movie'
			parameters['type'] = type

			# Information
			information = item['information'] if 'information' in item else None

			# Show
			if type == 'episode':
				if 'season' in information:
					parameters['season'] = information['season']
				if 'episode' in information:
					parameters['episode'] = information['episode']

			# TMDB
			try:
				tmdbApi = tools.Settings.getString('accounts.informants.tmdb.api') if tools.Settings.getBoolean('accounts.informants.tmdb.enabled') else ''
				if tmdbApi == '': tmdbApi = tools.System.obfuscate(tools.Settings.getString('internal.tmdb.api', raw = True))
				if not tmdbApi == '':
					if 'tvdb' in information and not information['tvdb'] == None: # Shows - IMDB ID for episodes does not work on tmdb
						result = cache.get(client.request, 240, 'http://api.themoviedb.org/3/find/%s?api_key=%s&external_source=tvdb_id' % (information['tvdb'], tmdbApi))
						result = result['tv_episode_results']
						parameters['tmdb'] = str(result['id'])
						parameters['show'] = str(result['show_id'])
					elif 'imdb' in information and not information['imdb'] == None:
						result = cache.get(client.request, 240, 'http://api.themoviedb.org/3/find/%s?api_key=%s&external_source=imdb_id' % (information['imdb'], tmdbApi))
						if isinstance(result, basestring): result = tools.Converter.jsonFrom(result)
						result = result['movie_results']
						if isinstance(result, list): result = result[0]
						parameters['tmdb'] = str(result['id'])
			except:
				tools.Logger.error()

			# This will add the torrent to Quasar, but after Quasar's buffer phase, playback is not started and nothing happens.
			# This is because of the source-selection dialog that causes Kodi's addon handle to be -1 (aka no handle). This will cause the Kodi player to not launch.
			# Use the RPC instead.
			# action = 'torrents/add' if download else 'play'
			#parameters = network.Networker.linkParameters(parameters)
			#tools.System.execute('RunPlugin(plugin://plugin.video.quasar/%s?%s)' % (action, parameters))

			interface.Dialog.notification(title = 33570, message = 35320, icon = interface.Dialog.IconSuccess, time = 10000)
			interface.Core.close()
			interface.Loader.show()

			if download: network.Networker(tools.Quasar.linkAdd(parameters)).request()
			else: network.Networker(tools.Quasar.linkPlay(parameters)).request()

			tools.Time.sleep(1)
			while True:
				if interface.Dialog.dialogProgressVisible(): break
				tools.Time.sleep(0.5)

			interface.Loader.hide()

			while True:
				if not interface.Dialog.dialogProgressVisible(): break
				tools.Time.sleep(0.5)

			# Quasar does not start playback after initial buffering.
			# If requesting the link again after buffering is done, Quasar does start playback.
			if not download:
				if not interface.Player().isPlaying(): interface.Loader.show()
				tools.Time.sleep(3)
				if not interface.Player().isPlaying(): network.Networker(tools.Quasar.linkPlay({'resume' : parameters['uri']})).request()
				interface.Loader.hide()

			if interface.Player().isPlaying() and window.WindowStreams.enabled():
				window.WindowStreams.close()

			return debrid.Debrid.addResult(error = Handler.ReturnExternal) # Return because Quasar will handle the playback.
		except:
			tools.Logger.error()