本文整理汇总了Python中addon.common.net.Net类的典型用法代码示例。如果您正苦于以下问题:Python Net类的具体用法?Python Net怎么用?Python Net使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Net类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __http_get_with_retry_1
def __http_get_with_retry_1(self, url, headers):
utils.log('Fetching URL: %s' % url, xbmc.LOGDEBUG)
net = Net()
cookiejar = _1CH.get_profile()
cookiejar = os.path.join(cookiejar, 'cookies')
net.set_cookies(cookiejar)
retries=0
html=None
while retries<=MAX_RETRIES:
try:
html = net.http_GET(url, headers=headers).content
# if no exception, jump out of the loop
break
except socket.timeout:
retries += 1
utils.log('Retry #%s for URL %s because of timeout' % (retries, url), xbmc.LOGWARNING)
continue
except urllib2.HTTPError as e:
# if it's a temporary code, retry
if e.code in TEMP_ERRORS:
retries += 1
utils.log('Retry #%s for URL %s because of HTTP Error %s' % (retries, url, e.code), xbmc.LOGWARNING)
continue
# if it's not pass it back up the stack
else:
raise
else:
raise
return html
示例2: __init__
def __init__(self, load = None, disable = None, cache_results=False):
self.threadpool_size = 5
self.cache_results = cache_results
self._load_list = load
self._disable_list = disable
self.enabled_scrapers = 0
self.active_scrapers = []
self.supported_scrapers = []
self._active_scrapers = []
self._load_scrapers()
self._enable_scrapers()
self.search_results = []
expired = True
cache_file = vfs.join(DATA_PATH, 'debrid_hosts.cache')
if vfs.exists(cache_file):
timestamp = int(time.time())
m_time = vfs.get_stat(cache_file).st_mtime()
if (timestamp - m_time) < 86400: expired = False
if expired:
hosts = {}
response = Net().http_GET('http://real-debrid.com/api/hosters.php').content
hosts['rd'] = [x.strip('"') for x in response.split(',')]
response = Net().http_GET('http://alldebrid.com/api.php?action=get_host').content
hosts['ad'] = [x.strip('"') for x in response.split(',\n')]
response = Net().http_GET('http://premium.rpnet.biz/hoster2.json').content
hosts['rp'] = json.loads(response)['supported']
ADDON.save_data(cache_file, hosts)
示例3: PLAYLIST
def PLAYLIST(name, url, iconimage, imdb):
net = Net()
link = net.http_GET(url).content
link=link.replace('\r\n', '').replace('"},]', '"}]')
magic = api.loads(link, encoding='latin1')
liste=[]
stream1=[]
stream2=[]
dialog = xbmcgui.Dialog()
for i in magic:
if imdb in i['imdblink'].encode('utf-8'):
try:
stream1=re.search("S*R*C*s*r*c*='(.*?)'.*?", i['streamlink1']).group(1)
vid1=re.search("S*R*C*s*r*c*='https*://(.*?)\.*c*o*m*t*o*/.*?'.*?",i['streamlink1'])
liste.append(vid1.group(1))
except:
pass
try:
stream2=re.search("S*R*C*s*r*c*='(.*?)'.*?", i['streamlink2']).group(1)
vid2=re.search("S*R*C*s*r*c*='https*://(.*?)\.*c*o*m*t*o*/.*?'.*?",i['streamlink2'])
liste.append(vid2.group(1))
except:
pass
hoster = dialog.select('HOSTER',liste)
if hoster == 0:
HOSTER(name,stream1,iconimage)
elif hoster == 1:
HOSTER(name,stream2,iconimage)
else:
pass
示例4: resolve_cloudyvideos
def resolve_cloudyvideos(name,url,iconimage):
# print "cloudyvideos"
url=re.sub('embed-|-.*?(?:\.html)','',url)
net = Net()
web_url = url
headers = {'Referer': web_url}
html = net.http_GET(web_url, headers=headers).content
data={}
time.sleep(3)
for match in re.finditer(r'type="hidden".*?name="([^"]+)".*?value="([^"]+)', html):
data[match.group(1)] = match.group(2)
data.update ({'method_free': 'Continue'})
htmla = net.http_POST(web_url, data).content
r = re.search('file:\s*\'(.*?)\',+', htmla)
pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
pl.clear()
try:
listitem = xbmcgui.ListItem(name,thumbnailImage=iconimage)
url = r.group(1)+'|Referer=http://cloudyvideos&User-Agent=%s' % (USER_AGENT)
pl.add(url, listitem)
xbmc.Player().play(pl)
except Exception, e:
dialog = xbmcgui.DialogProgress()
dialog1 = xbmcgui.Dialog()
dialog1.ok('error','[UPPERCASE][B] Sorry but the video is deleted!!![/B][/UPPERCASE]')
print '**** cloudyvideo Error occured: %s' % e
raise
示例5: login_and_retry
def login_and_retry(redirect):
_1CH.log('Logging in for url %s' % redirect)
# needed here because login_and_retry was moved to utils. Probably better to pass in but this works and is quick but dirty.
USER_AGENT = ("User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64)"
"AppleWebKit/537.17 (KHTML, like Gecko)"
"Chrome/24.0.1312.56")
BASE_URL = _1CH.get_setting('domain')
if (_1CH.get_setting("enableDomain")=='true') and (len(_1CH.get_setting("customDomain")) > 10):
BASE_URL = _1CH.get_setting("customDomain")
user = _1CH.get_setting('username')
passwd = _1CH.get_setting('passwd')
url = BASE_URL + '/login.php'
net = Net()
cookiejar = _1CH.get_profile()
cookiejar = os.path.join(cookiejar, 'cookies')
host = re.sub('http://', '', BASE_URL)
headers = {'Referer': redirect, 'Origin': BASE_URL, 'Host': host, 'User-Agent': USER_AGENT}
form_data = {'username': user, 'password': passwd, 'remember': 'on', 'login_submit': 'Login'}
html = net.http_POST(url, headers=headers, form_data=form_data).content
if '<a href="/logout.php">[ Logout ]</a>' in html:
net.save_cookies(cookiejar)
return html
else:
_1CH.log('Failed to login')
print html
示例6: read_url
def read_url(url):
net = Net()
html=net.http_GET(url).content
h = HTMLParser.HTMLParser()
html = h.unescape(html)
return html
示例7: read_url
def read_url(url):
net = Net()
html = net.http_GET(url).content
import HTMLParser
h = HTMLParser.HTMLParser()
html = h.unescape(html)
try:
return html.encode("utf-8")
except:
return html
示例8: __login
def __login(self,redirect):
url = self.base_url + '/login.php'
net = Net()
cookiejar = _1CH.get_profile()
cookiejar = os.path.join(cookiejar, 'cookies')
host = re.sub('http://', '', self.base_url)
headers = {'Referer': redirect, 'Origin': self.base_url, 'Host': host, 'User-Agent': USER_AGENT}
form_data = {'username': self.username, 'password': self.password, 'remember': 'on', 'login_submit': 'Login'}
html = net.http_POST(url, headers=headers, form_data=form_data).content
if '<a href="/logout.php">[ Logout ]</a>' in html:
net.save_cookies(cookiejar)
return True
else:
return False
示例9: readnet2
def readnet2(url):
from addon.common.net import Net
net=Net()
USER_AGENT='Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:30.0) Gecko/20100101 Firefox/30.0'
MAX_TRIES=3
headers = {
'User-Agent': USER_AGENT,
'Referer': url
}
html = net.http_GET(url).content
return html
示例10: __init__
def __init__(self, load = None, disable = None, cache_results=False):
self.threadpool_size = 5
self.cache_results = cache_results
self._load_list = load
self._disable_list = disable
self.enabled_scrapers = 0
self.active_scrapers = []
self.supported_scrapers = []
self._active_scrapers = []
self._load_scrapers()
self._enable_scrapers()
self.search_results = []
self.show_scraper_progress = ADDON.get_setting('enable_scraper_progress') == 'true'
expired = True
self.filters = False
if ADDON.get_setting('enable_result_filters') == 'true':
cache_file = vfs.join(DATA_PATH, 'filters.cache')
if vfs.exists(cache_file):
self.filters = ADDON.load_data(cache_file)
cache_file = vfs.join(DATA_PATH, 'debrid_hosts.cache')
if vfs.exists(cache_file):
timestamp = int(time.time())
m_time = vfs.get_stat(cache_file).st_mtime()
if (timestamp - m_time) < 86400: expired = False
if expired:
hosts = {"pm": [], "rd": [], "ad": [], "rp": []}
net = Net()
try:
customer_id = xbmcaddon.Addon('script.module.urlresolver').getSetting('PremiumizeMeResolver_username')
pin = xbmcaddon.Addon('script.module.urlresolver').getSetting('PremiumizeMeResolver_password')
query = {"method": "hosterlist", "params[login]": customer_id, "params[pass]": pin}
api_url = "http://api.premiumize.me/pm-api/v1.php?" + urllib.urlencode(query)
response = net.http_GET(api_url).content
data = json.loads(response)
if 'result' in data:
hosts['pm'] = data['result']['hosterlist']
except: pass
try:
response = Net().http_GET('http://real-debrid.com/api/hosters.php').content
hosts['rd'] = [x.strip('"') for x in response.split(',')]
except: pass
try:
response = Net().http_GET('http://alldebrid.com/api.php?action=get_host').content
hosts['ad'] = [x.strip('"') for x in response.split(',\n')]
except: pass
try:
response = Net().http_GET('http://premium.rpnet.biz/hoster2.json').content
hosts['rp'] = json.loads(response)['supported']
except: pass
ADDON.save_data(cache_file, hosts)
示例11: SEARCH
def SEARCH(url,name,imdb,move,movegen):
net = Net()
link = net.http_GET(url).content
link=link.replace('\r\n', '').replace('"},]', '"}]')
magic = api.loads(link, encoding='latin1')
kb = xbmc.Keyboard('', 'Search KinoLeak', False)
kb.doModal()
search = kb.getText()
# search=urllib.quote(search)
for e,i in enumerate(magic):
if search.lower() in (i['titel'].encode('utf-8')).lower():
try:
imdb=re.search(".*?/(tt\d+)/*.*?$", i['imdblink']).group(1)
except:
imdb=""
try:
sub=re.search("(.*?)\((\d+)\)", i['titel'])
addDir(sub.group(1),url,2,i['cover'],imdb,"movie".decode('utf-8'),sub.group(2),None,"")
except:
addDir(i['titel'],url,2,i['cover'],imdb,"movie",'',None,"")
xbmcplugin.setContent(int(sys.argv[1]), 'movies')
xbmc.executebuiltin("Container.SetViewMode(%s)" % addon.getSetting('MAIN') )
示例12: request
def request(self, uri, params=None, query=None, headers=None, return_soup=False, return_json=False):
COOKIE_JAR = vfs.join(COOKIE_PATH, self.service + ".lwp")
net = Net()
net.set_cookies(COOKIE_JAR)
if headers:
headers["Referer"] = self.referrer
headers["Accept"] = self.ACCEPT
headers["User-Agent"] = self.USER_AGENT
else:
headers = {"Referer": self.referrer, "Accept": self.ACCEPT, "User-Agent": self.USER_AGENT}
if query:
uri = uri % urllib.urlencode(query)
if params:
html = net.http_POST(self.base_url + uri, params, headers=headers).content
else:
html = net.http_GET(self.base_url + uri, headers=headers).content
net.save_cookies(COOKIE_JAR)
if return_soup:
return BeautifulSoup(html)
elif return_json:
return json.loads(html)
else:
return html
示例13: Addon
import xbmc, xbmcgui
import urllib, urllib2
import re
import HTMLParser
from elementtree.ElementTree import parse
try:
from addon.common.addon import Addon
from addon.common.net import Net
except:
xbmc.log('Failed to import script.module.addon.common, attempting t0mm0.common')
xbmcgui.Dialog().ok("Import Failure", "Failed to import addon.common", "A component needed by this addon is missing on your system", "Please visit www.xbmc.org for support")
addon = Addon('plugin.video.redlettermedia', sys.argv)
net = Net()
##### Queries ##########
play = addon.queries.get('play', None)
mode = addon.queries['mode']
url = addon.queries.get('url', None)
page_num = addon.queries.get('page_num', None)
addon.log('-----------------RedLetterMedia Addon Params------------------')
addon.log('--- Version: ' + str(addon.get_version()))
addon.log('--- Mode: ' + str(mode))
addon.log('--- Play: ' + str(play))
addon.log('--- URL: ' + str(url))
addon.log('--- Page: ' + str(page_num))
addon.log('---------------------------------------------------------------')
示例14: INDEX
def INDEX(url,name,imdb,move,movegen):
net = Net()
link = net.http_GET(url).content
link=link.replace('\r\n', '').replace('"},]', '"}]')
magic = api.loads(link, encoding='latin1')
progress = xbmcgui.DialogProgress()
progress.create('Fortschritt', 'This is a progress bar.')
genre=[]
neu=[]
sammeln=[]
for e,i in enumerate(reversed(magic)):
if name == "Neu im Programm" and e<27:
neu.append(i)
for e,i in enumerate(magic):
if name in i['genre'].encode('utf-8'):
genre.append(i)
for e,i in enumerate(magic):
if "sammeln" in name:
sammeln.append(i)
#----Neu im Programm----#
for e,i in enumerate(neu):
if e < len(neu):
percent = int((e/len(neu))*100)
message = str(e) + " von "+str(len(neu))+" Filmen geladen"
progress.update(percent, message, "Dies passiert bei noch nie eingelesenen Filmen")
try:
imdb=re.search(".*?/(tt\d+)/*.*?$", i['imdblink']).group(1)
except:
imdb=""
try:
sub=re.search("(.*?)\((\d+)\)", i['titel'])
addDir(sub.group(1),url,2,i['cover'],imdb,"movie".decode('utf-8'),sub.group(2),None,"")
except:
addDir(i['titel'],url,2,i['cover'],imdb,"movie",'',None,"")
#----GENRES die Filme----#
for e,i in enumerate(sorted(genre, key=lambda genre: genre['titel'])):
if move<=e<move+25:
if e-move < move+25:
percent = ((e-move)/25*100)
message = "FilmInfo des "+str(e-move) + ". von 25 Filmen geladen"
progress.update(percent, message, "Dies passiert bei noch nie eingelesenen Filmen")
try:
imdb=re.search(".*?/(tt\d+)/*.*?$", i['imdblink']).group(1)
except:
imdb=""
try:
sub=re.search("(.*?)\((\d+)\)", i['titel'])
addDir(sub.group(1),url,2,i['cover'],imdb,"movie".decode('utf-8'),sub.group(2),None,"")
except:
addDir(i['titel'],url,2,i['cover'],imdb,"movie",'',None,"")
#----FilmInfo von allen Filmen Sammeln für die Datenbank----#
for e,i in enumerate(sorted(sammeln, key=lambda sammeln: sammeln['titel'])):
if e < len(sammeln):
percent = int((e/len(sammeln))*100)
message = "FilmInfo des "+str(e) + ". von "+str(len(sammeln))+" Filmen geladen"
progress.update(percent, message, "Dies passiert bei noch nie eingelesenen Filmen")
try:
imdb=re.search(".*?/(tt\d+)/*.*?$", i['imdblink']).group(1)
except:
imdb=""
try:
sub=re.search("(.*?)\((\d+)\)", i['titel'])
addDir(sub.group(1),url,2,i['cover'],imdb,"movie".decode('utf-8'),sub.group(2),None,"")
except:
addDir(i['titel'],url,2,i['cover'],imdb,"movie",'',None,"")
#----SEITENNAVIGATION----#
if len(genre)>0:
if move!=None and move==0 and len(genre)>25:
print "<<<----OLDU-1---->>>"
addDir("Next-->>",url,4,"","","folder","",move+25,name)
if move!=None and move!=0 and move+25<=len(genre) and len(genre)-move>0:
print "<<<----OLDU-2---->>>"
addDir("Next-->>",url,4,"","","folder","",move+25,name)
addDir("<<--Back",url,4,"","","folder","",move-25,name)
if move+25>=len(genre) and move!=0:
print "<<<----OLDU-3---->>>"
addDir("<<--Back",url,4,"","","folder","",move-25,name)
addDir("Home","",None,"","","folder","",None,"")
progress.close()
xbmcplugin.setContent(int(sys.argv[1]), 'movies')
xbmc.executebuiltin("Container.SetViewMode(%s)" % addon.getSetting('MAIN') )
示例15: get_params
# -*- coding: cp1252 -*-
# Main Module by: Blazetamer and TheHighway
import urllib,urllib2,re,xbmcplugin,xbmcgui,sys,xbmc,os,xbmcaddon
try: from addon.common.addon import Addon
except:
try: from t0mm0.common.addon import Addon
except: from t0mm0_common_addon import Addon
try: from addon.common.net import Net
except:
try: from t0mm0.common.net import Net
except: from t0mm0_common_net import Net
#Define common.addon
addon_id='plugin.video.phwizard';
AddonTitle='Config Wizard';
# Global Stuff
addon=Addon(addon_id,sys.argv); net=Net(); settings=xbmcaddon.Addon(id=addon_id); net.set_user_agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3');
AddonIcon=settings.getAddonInfo('icon')
AddonFanart=settings.getAddonInfo('fanart')
AddonPath=settings.getAddonInfo('path')
# #
def get_params():
param=[]
paramstring=sys.argv[2]
if len(paramstring)>=2:
params=sys.argv[2]; cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'): params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&'); param={}
for i in range(len(pairsofparams)):
splitparams={}; splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2: param[splitparams[0]]=splitparams[1]
return param