Esempio n. 1
0
def decode_url(args):
    '''
	usage: lx decode-url thunder://...
	'''
    from lixian_url import url_unmask
    for x in args:
        print url_unmask(x)
Esempio n. 2
0
def decode_url(args):
	'''
	usage: lx decode-url thunder://...
	'''
	from lixian_url import url_unmask
	for x in args:
		print url_unmask(x)
Esempio n. 3
0
def link_equals(x1, x2):
	from lixian_url import url_unmask, normalize_unicode_link
	x1 = url_unmask(x1)
	x2 = url_unmask(x2)
	if x1.startswith('magnet:'):
		x1 = 'bt://'+lixian_hash_bt.magnet_to_infohash(x1).encode('hex')
	if x2.startswith('magnet:'):
		x2 = 'bt://'+lixian_hash_bt.magnet_to_infohash(x2).encode('hex')
	if x1.startswith('ed2k://') and x2.startswith('ed2k://'):
		return lixian_hash_ed2k.parse_ed2k_link(x1) == lixian_hash_ed2k.parse_ed2k_link(x2)
		#import urllib
		#if type(x1) == unicode:
		#	x1 = x1.encode('utf-8')
		#if type(x2) == unicode:
		#	x2 = x2.encode('utf-8')
		#x1 = urllib.unquote(x1)
		#x2 = urllib.unquote(x2)
		#x1 = x1.replace('&', '&')
		#x2 = x2.replace('&', '&')
	elif x1.startswith('bt://') and x2.startswith('bt://'):
		x1 = x1.lower()
		x2 = x2.lower()
	elif x1.startswith('http://') and x2.startswith('http://'):
		x1 = normalize_unicode_link(x1)
		x2 = normalize_unicode_link(x2)
	return x1 == x2
Esempio n. 4
0
def link_equals(x1, x2):
    from lixian_url import url_unmask, normalize_unicode_link
    x1 = url_unmask(x1)
    x2 = url_unmask(x2)
    if x1.startswith('magnet:'):
        x1 = 'bt://' + lixian_hash_bt.magnet_to_infohash(x1).encode('hex')
    if x2.startswith('magnet:'):
        x2 = 'bt://' + lixian_hash_bt.magnet_to_infohash(x2).encode('hex')
    if x1.startswith('ed2k://') and x2.startswith('ed2k://'):
        return lixian_hash_ed2k.parse_ed2k_link(
            x1) == lixian_hash_ed2k.parse_ed2k_link(x2)
        #import urllib
        #if type(x1) == unicode:
        #	x1 = x1.encode('utf-8')
        #if type(x2) == unicode:
        #	x2 = x2.encode('utf-8')
        #x1 = urllib.unquote(x1)
        #x2 = urllib.unquote(x2)
        #x1 = x1.replace('&', '&')
        #x2 = x2.replace('&', '&')
    elif x1.startswith('bt://') and x2.startswith('bt://'):
        x1 = x1.lower()
        x2 = x2.lower()
    elif x1.startswith('http://') and x2.startswith('http://'):
        x1 = normalize_unicode_link(x1)
        x2 = normalize_unicode_link(x2)
    return x1 == x2
Esempio n. 5
0
def addtask():
	rs={'msg':'','log':'','rst':'','data':{}}
	form = cgi.FieldStorage()
	if "url" in form:
		url=form["url"].value
	else:
		url = None
		rs['msg']="needurl"
		return rs	
		
	bt = 0
	if "tasktype" in form:
		bt = (form["tasktype"].value == "bt")	
		
		
	try:
		sys.path.append('core')
		from lixian_url import url_unmask
		url = url_unmask(url)			
		conf=readconf()		
		from lixian import XunleiClient
		client = XunleiClient(conf['username'],conf['password'],conf['LIXIAN_HOME'] +'/.xunlei.lixian.cookies')		
		if (url.startswith('http://') or url.startswith('ftp://')) and bt:
			torrent = urllib2.urlopen(url, timeout=60).read()		
			client.add_torrent_task_by_content(torrent, os.path.basename(url))
			rs['msg']="addok"
		else:
			client.add_task(url)	
			rs['msg']="addok"
	except Exception as inst:
		rs['msg']="addng"
		rs['log']=str(inst)
		
	return rs
Esempio n. 6
0
    def add_task(self, url):
        protocol = parse_url_protocol(url)
        assert protocol in (
            'ed2k', 'http', 'https', 'ftp', 'thunder', 'Flashget', 'qqdl',
            'bt', 'magnet'), 'protocol "%s" is not suppoted' % protocol

        from lixian_url import url_unmask
        url = url_unmask(url)
        protocol = parse_url_protocol(url)
        assert protocol in (
            'ed2k', 'http', 'https', 'ftp', 'bt',
            'magnet'), 'protocol "%s" is not suppoted' % protocol

        if protocol == 'bt':
            return self.add_torrent_task_by_info_hash(url[5:])
        elif protocol == 'magnet':
            return self.add_magnet_task(url)

        random = current_random()
        check_url = 'http://dynamic.cloud.vip.xunlei.com/interface/task_check?callback=queryCid&url=%s&random=%s&tcache=%s' % (
            urllib.quote(url), random, current_timestamp())
        js = self.urlread(check_url).decode('utf-8')
        qcid = re.match(r'^queryCid(\(.+\))\s*$', js).group(1)
        qcid = literal_eval(qcid)
        if len(qcid) == 8:
            cid, gcid, size_required, filename, goldbean_need, silverbean_need, is_full, random = qcid
        elif len(qcid) == 9:
            cid, gcid, size_required, filename, goldbean_need, silverbean_need, is_full, random, ext = qcid
        elif len(qcid) == 10:
            cid, gcid, size_required, some_key, filename, goldbean_need, silverbean_need, is_full, random, ext = qcid
        else:
            raise NotImplementedError(qcid)
        assert goldbean_need == 0
        assert silverbean_need == 0

        if url.startswith('http://') or url.startswith('ftp://'):
            task_type = 0
        elif url.startswith('ed2k://'):
            task_type = 2
        else:
            raise NotImplementedError()
        task_url = 'http://dynamic.cloud.vip.xunlei.com/interface/task_commit?' + urlencode(
            {
                'callback': 'ret_task',
                'uid': self.id,
                'cid': cid,
                'gcid': gcid,
                'size': size_required,
                'goldbean': goldbean_need,
                'silverbean': silverbean_need,
                't': filename,
                'url': url,
                'type': task_type,
                'o_page': 'task',
                'o_taskid': '0',
            })

        response = self.urlread(task_url)
        assert response == 'ret_task(Array)', response
Esempio n. 7
0
    def add_task(self, url):
        protocol = parse_url_protocol(url)
        assert protocol in ("ed2k", "http", "ftp", "thunder", "Flashget", "qqdl", "bt", "magnet"), (
            'protocol "%s" is not suppoted' % protocol
        )

        from lixian_url import url_unmask

        url = url_unmask(url)
        protocol = parse_url_protocol(url)
        assert protocol in ("ed2k", "http", "ftp", "bt", "magnet"), 'protocol "%s" is not suppoted' % protocol

        if protocol == "bt":
            return self.add_torrent_task_by_info_hash(url[5:])
        elif protocol == "magnet":
            return self.add_magnet_task(url)

        random = current_random()
        check_url = (
            "http://dynamic.cloud.vip.xunlei.com/interface/task_check?callback=queryCid&url=%s&random=%s&tcache=%s"
            % (urllib.quote(url), random, current_timestamp())
        )
        js = self.urlopen(check_url).read().decode("utf-8")
        qcid = re.match(r"^queryCid(\(.+\))\s*$", js).group(1)
        qcid = literal_eval(qcid)
        if len(qcid) == 8:
            cid, gcid, size_required, filename, goldbean_need, silverbean_need, is_full, random = qcid
        elif len(qcid) == 9:
            cid, gcid, size_required, filename, goldbean_need, silverbean_need, is_full, random, ext = qcid
        else:
            raise NotImplementedError()
        assert goldbean_need == 0
        assert silverbean_need == 0

        if url.startswith("http://") or url.startswith("ftp://"):
            task_type = 0
        elif url.startswith("ed2k://"):
            task_type = 2
        else:
            raise NotImplementedError()
        task_url = "http://dynamic.cloud.vip.xunlei.com/interface/task_commit?" + urlencode(
            {
                "callback": "ret_task",
                "uid": self.id,
                "cid": cid,
                "gcid": gcid,
                "size": size_required,
                "goldbean": goldbean_need,
                "silverbean": silverbean_need,
                "t": filename,
                "url": url,
                "type": task_type,
                "o_page": "task",
                "o_taskid": "0",
            }
        )

        response = self.urlopen(task_url).read()
        assert_default_page(response, self.id)
Esempio n. 8
0
    def add_task(self, url):
        protocol = parse_url_protocol(url)
        assert protocol in ('ed2k', 'http', 'https', 'ftp', 'thunder', 'Flashget', 'qqdl', 'bt',
                            'magnet'), 'protocol "%s" is not suppoted' % protocol

        from lixian_url import url_unmask

        url = url_unmask(url)
        protocol = parse_url_protocol(url)
        assert protocol in ('ed2k', 'http', 'https', 'ftp', 'bt', 'magnet'), 'protocol "%s" is not suppoted' % protocol

        if protocol == 'bt':
            return self.add_torrent_task_by_info_hash(url[5:])
        elif protocol == 'magnet':
            return self.add_magnet_task(url)

        random = current_random()
        check_url = 'http://dynamic.cloud.vip.xunlei.com/interface/task_check?callback=queryCid&url=%s&random=%s&tcache=%s' % (
        urllib.quote(url), random, current_timestamp())
        js = self.urlread(check_url).decode('utf-8')
        qcid = re.match(r'^queryCid(\(.+\))\s*$', js).group(1)
        qcid = literal_eval(qcid)
        if len(qcid) == 8:
            cid, gcid, size_required, filename, goldbean_need, silverbean_need, is_full, random = qcid
        elif len(qcid) == 9:
            cid, gcid, size_required, filename, goldbean_need, silverbean_need, is_full, random, ext = qcid
        elif len(qcid) == 10:
            cid, gcid, size_required, some_key, filename, goldbean_need, silverbean_need, is_full, random, ext = qcid
        else:
            raise NotImplementedError(qcid)
        assert goldbean_need == 0
        assert silverbean_need == 0

        if url.startswith('http://') or url.startswith('ftp://'):
            task_type = 0
        elif url.startswith('ed2k://'):
            task_type = 2
        else:
            raise NotImplementedError()
        task_url = 'http://dynamic.cloud.vip.xunlei.com/interface/task_commit?' + urlencode(
            {'callback': 'ret_task',
             'uid': self.id,
             'cid': cid,
             'gcid': gcid,
             'size': size_required,
             'goldbean': goldbean_need,
             'silverbean': silverbean_need,
             't': filename,
             'url': url,
             'type': task_type,
             'o_page': 'task',
             'o_taskid': '0',
            })

        response = self.urlread(task_url)
        assert response == 'ret_task(Array)', response
Esempio n. 9
0
def link_normalize(url):
    from lixian_url import url_unmask, normalize_unicode_link
    url = url_unmask(url)
    if url.startswith('magnet:'):
        return 'bt://' + lixian_hash_bt.magnet_to_infohash(url).encode('hex')
    elif url.startswith('ed2k://'):
        return lixian_hash_ed2k.parse_ed2k_id(url)
    elif url.startswith('bt://'):
        return url.lower()
    elif url.startswith('http://') or url.startswith('ftp://'):
        return normalize_unicode_link(url)
    return url
Esempio n. 10
0
def link_normalize(url):
	from lixian_url import url_unmask, normalize_unicode_link
	url = url_unmask(url)
	if url.startswith('magnet:'):
		return 'bt://'+lixian_hash_bt.magnet_to_infohash(url).encode('hex')
	elif url.startswith('ed2k://'):
		return lixian_hash_ed2k.parse_ed2k_id(url)
	elif url.startswith('bt://'):
		return url.lower()
	elif url.startswith('http://') or url.startswith('ftp://'):
		return normalize_unicode_link(url)
	return url
Esempio n. 11
0
def link_normalize(url):
    from lixian_url import url_unmask, normalize_unicode_link
    from lixian_url import url_unmask, normalize_unicode_link

    url = url_unmask(url)
    if url.startswith("magnet:"):
        return "bt://" + lixian_hash_bt.magnet_to_infohash(url).encode("hex")
    elif url.startswith("ed2k://"):
        return lixian_hash_ed2k.parse_ed2k_link(url)
    elif url.startswith("bt://"):
        return url.lower()
    elif url.startswith("http://") or url.startswith("ftp://"):
        return normalize_unicode_link(url)
    return url
Esempio n. 12
0
 def __init__(self, base, x):
     super(UrlQuery, self).__init__(base)
     self.url = lixian_url.url_unmask(x)
     self.task = self.base.find_task_by_url(self.url)
Esempio n. 13
0
	def __init__(self, base, x):
		super(UrlQuery, self).__init__(base)
		self.url = lixian_url.url_unmask(x)
		self.task = self.base.find_task_by_url(self.url)
def decode_url(args):
	from lixian_url import url_unmask
	for x in args:
		print url_unmask(x)