python实现Http地址与thunder|flashget|qq旋风 地址转换

By | 2012/08/27

http链接转换为Thunder、QQ旋风、Flashget之类的地址,实际上就是对原链接进行base64编码,可能会加一些干扰码之类的,但是原理都是一样的。

 

代码

import base64
import sys

def httpToThunder(url):
    url = 'AA'+url+'ZZ'
    return "thunder://"+base64.encodestring(url)

def thunderToHttp(url):
    realUrl = base64.decodestring(url[10:])
    return realUrl[2:-2]

def httpToFlashget(url):
    url = '[FLASHGET]'+url+'[FLASHGET]'
    return "flashget://"+base64.encodestring(url)+"&bspeng922"

def flashgetToHttp(url):
    realUrl = base64.decodestring(url[11:])
    return realUrl[10:-10]

def httpToqqdl(url):
    return "qqdl://"+base64.encodestring(url)

def qqdlToHttp(url):
    return base64.decodestring(url[7:])

def printError():
    return "Wrong input..."

def printMenu():
    print "*"*40
    print "  1. Http to Thunder"
    print "  2. Thunder to Http"
    print "  3. Http to Flashget"
    print "  4. Flashget to Http"
    print "  5. Http to QQdl"
    print "  6. QQdl to Http"
    print "  7. Quit"
    print "*"*40

if __name__ == "__main__":
    while 1 :
        if len(sys.argv)==3:
            userInput = sys.argv[1]
            urlInput = sys.argv[2]
            #print userInput,"    ",urlInput
        else:
            printMenu()
            userInput = raw_input("Input your choice ->")
            if userInput.isdigit() :
                if 7 == int(userInput):
                    break
                elif 1<=int(userInput) and int(userInput)<=6:
                    urlInput = raw_input("Input URL ->")
                else:
                    pass
            else:
                pass

        result = {
            '1' : lambda : httpToThunder(urlInput),
            '2' : lambda : thunderToHttp(urlInput),
            '3' : lambda : httpToFlashget(urlInput),
            '4' : lambda : flashgetToHttp(urlInput),
            '5' : lambda : httpToqqdl(urlInput),
            '6' : lambda : qqdlToHttp(urlInput)
        }.get(userInput,lambda : printError())()
        #result = {
        #    '1' : httpToThunder(urlInput),
        #    '2' : thunderToHttp(urlInput),
        #    '3' : httpToFlashget(urlInput),
        #    '4' : flashgetToHttp(urlInput),
        #    '5' : httpToqqdl(urlInput),
        #    '6' : qqdlToHttp(urlInput),
        #    '8' : printError()
        #}.get(userInput,8)

        print "\n"
        print result

        donext = raw_input("Do you want to continue(Y/N):")
        if 'n' == donext.lower():break

    print "bye..."

Leave a Reply

Your email address will not be published. Required fields are marked *