コード例 #1
0
ファイル: txsp.py プロジェクト: ytwangli/crawlers
def getvclip(url, vid, vt, resolution, idx):
    rand = random.random()
    ckey = echo_ckeyv3(vid,
                       PLAYER_GUID,
                       rand,
                       player_version=PLAYER_VERSION,
                       platform=PLATFORM)
    params = {
        'buffer': 0,
        'guid': PLAYER_GUID,
        'vt': vt,
        'ltime': 77,
        'fmt': 'auto',
        'vid': vid,
        'platform': PLATFORM,
        'cKey': ckey,
        'format': resolution,
        'speed': random.randint(1000, 3000),
        'encryptVer': '5.4',
        'idx': idx,
        'appver': PLAYER_VERSION,
        'ehost': url,
        'dltype': 1,
        'charge': 0,
        'otype': 'xml',
        'ran': '%.16f' % rand
    }

    request = urllib2.Request('http://vv.video.qq.com/getvclip')
    request.add_header('Referer', SWF_REFERER)
    request.add_header('Content-type', 'application/x-www-form-urlencoded')
    request.add_header('User-Agent', USER_AGENT)

    form = urllib.urlencode(params)
    resp = urllib2.urlopen(request, data=form)

    vclip = resp.read()
    tree = etree.fromstring(vclip)

    vclip = {
        'filename': tree.xpath('/root/vi/fn/text()')[0],
        'br': float(tree.xpath('/root/vi/br/text()')[0]),
        'fmt': tree.xpath('/root/vi/fmt/text()')[0],
        'key': tree.xpath('/root/vi/key/text()')[0],
        'md5': tree.xpath('/root/vi/md5/text()')[0],
        'fs': int(tree.xpath('/root/vi/fs/text()')[0])
    }

    return vclip
コード例 #2
0
ファイル: txsp.py プロジェクト: sunyymq/crawlers
def getvclip(url, vid, vt, resolution, idx):
    rand = random.random()
    ckey = echo_ckeyv3(vid, PLAYER_GUID, rand, player_version=PLAYER_VERSION, platform=PLATFORM)
    params = {
        'buffer': 0,
        'guid': PLAYER_GUID,
        'vt': vt,
        'ltime': 77,
        'fmt': 'auto',
        'vid': vid,
        'platform': PLATFORM,
        'cKey': ckey,
        'format': resolution,
        'speed': random.randint(1000, 3000),
        'encryptVer': '5.4',
        'idx': idx,
        'appver': PLAYER_VERSION,
        'ehost': url,
        'dltype': 1,
        'charge': 0,
        'otype': 'xml',
        'ran': '%.16f' % rand
    }

    request = urllib2.Request('http://vv.video.qq.com/getvclip')
    request.add_header('Referer', SWF_REFERER)
    request.add_header('Content-type', 'application/x-www-form-urlencoded')
    request.add_header('User-Agent', USER_AGENT)
    
    form = urllib.urlencode(params)
    resp = urllib2.urlopen(request, data=form)

    vclip = resp.read()
    tree = etree.fromstring(vclip)

    vclip = {
        'filename': tree.xpath('/root/vi/fn/text()')[0],
        'br': float(tree.xpath('/root/vi/br/text()')[0]),
        'fmt': tree.xpath('/root/vi/fmt/text()')[0],
        'key': tree.xpath('/root/vi/key/text()')[0],
        'md5': tree.xpath('/root/vi/md5/text()')[0],
        'fs': int(tree.xpath('/root/vi/fs/text()')[0])
    }

    return vclip
コード例 #3
0
ファイル: txsp.py プロジェクト: zero20151631/crawlers
def getvclip(url, vid, vt, resolution, idx):
    rand = random.random()
    ckey = echo_ckeyv3(vid, PLAYER_GUID, rand, player_version=PLAYER_VERSION, platform=PLATFORM)
    params = {
        "buffer": 0,
        "guid": PLAYER_GUID,
        "vt": vt,
        "ltime": 77,
        "fmt": "auto",
        "vid": vid,
        "platform": PLATFORM,
        "cKey": ckey,
        "format": resolution,
        "speed": random.randint(1000, 3000),
        "encryptVer": "5.4",
        "idx": idx,
        "appver": PLAYER_VERSION,
        "ehost": url,
        "dltype": 1,
        "charge": 0,
        "otype": "xml",
        "ran": "%.16f" % rand,
    }

    request = urllib2.Request("http://vv.video.qq.com/getvclip")
    request.add_header("Referer", SWF_REFERER)
    request.add_header("Content-type", "application/x-www-form-urlencoded")
    request.add_header("User-Agent", USER_AGENT)

    form = urllib.urlencode(params)
    resp = urllib2.urlopen(request, data=form)

    vclip = resp.read()
    tree = etree.fromstring(vclip)

    vclip = {
        "filename": tree.xpath("/root/vi/fn/text()")[0],
        "br": float(tree.xpath("/root/vi/br/text()")[0]),
        "fmt": tree.xpath("/root/vi/fmt/text()")[0],
        "key": tree.xpath("/root/vi/key/text()")[0],
        "md5": tree.xpath("/root/vi/md5/text()")[0],
        "fs": int(tree.xpath("/root/vi/fs/text()")[0]),
    }

    return vclip
コード例 #4
0
ファイル: txsp.py プロジェクト: ytwangli/crawlers
def getvkey(url, vid, vt, resolution, filename):

    rand = random.random()
    ckey = echo_ckeyv3(vid,
                       PLAYER_GUID,
                       rand,
                       player_version=PLAYER_VERSION,
                       platform=PLATFORM)

    params = {
        'guid': PLAYER_GUID,
        'platform': PLATFORM,
        'vt': vt,
        'linkver': 2,
        'vid': vid,
        'lnk': vid,
        'charge': 0,
        'cKey': ckey,
        'encryptVer': '5.4',
        'otype': 'xml',
        'filename': filename,
        'ehost': url,
        'format': resolution,
        'appver': PLAYER_VERSION,
        'ran': rand,
    }

    request = urllib2.Request('http://vv.video.qq.com/getvkey')
    request.add_header('Referer', SWF_REFERER)
    request.add_header('Content-type', 'application/x-www-form-urlencoded')
    request.add_header('User-Agent', USER_AGENT)

    form = urllib.urlencode(params)
    resp = urllib2.urlopen(request, data=form)
    resp_body = resp.read()
    print resp_body
    tree = etree.fromstring(resp_body)
    vkey = {
        'filename': tree.xpath('/root/filename/text()')[0],
        'br': float(tree.xpath('/root/br/text()')[0]),
        'key': tree.xpath('/root/key/text()')[0]
    }
    return vkey
コード例 #5
0
ファイル: txsp.py プロジェクト: sunyymq/crawlers
def getvinfo(target_dir, url, vid):
    rand = random.random()
    ckey = echo_ckeyv3(vid, PLAYER_GUID, rand, player_version=PLAYER_VERSION, platform=PLATFORM)
    params = {
        'fp2p': 1,
        'charge': 0,
        'guid': PLAYER_GUID,
        'pid': PLAYER_PID,
        'vid': vid,
        'platform': PLATFORM,
        'cKey': ckey,
        'otype': 'xml', 
        'fhdswitch': 0,
        'defnpayver': 1,
        'appver': PLAYER_VERSION,
        'ehost': url, 
        'vids': vid,
        'encryptVer': '5.4',
        'utype': 0,
        'ran': '%.16f' % rand,
        'speed': random.randint(1000, 3000)
    }
    request = urllib2.Request('http://vv.video.qq.com/getvinfo')
    request.add_header('Referer', SWF_REFERER)
    request.add_header('Content-type', 'application/x-www-form-urlencoded')
    request.add_header('User-Agent', USER_AGENT)
    
    form = urllib.urlencode(params)
    resp = urllib2.urlopen(request, data=form)

    vinfo = resp.read()
    tree = etree.fromstring(vinfo)

    resolutions = {}
    slid = None
    for fi in tree.xpath('/root/fl/fi'):
        name = fi.xpath('name/text()')[0]
        fiid = int(fi.xpath('id/text()')[0])
        sl = int(fi.xpath('sl/text()')[0])
        cname = fi.xpath('cname/text()')[0]
        if sl:
            pass
        if name == 'fhd':
            slid = fiid
            print 'Selected %s: %s' % (name, cname)
        resolutions[name] = fiid

    print resolutions

    for vi in tree.xpath('/root/vl/vi'):
        video_type = int(vi.xpath('videotype/text()')[0])
        if video_type == 1:
            video_type = 'flv'
        elif video_type == 2:
            video_type = 'mp4'
        else:
            video_type = 'unknown'

        video_id = vi.xpath('vid/text()')[0]

        cdn_host = vi.xpath('ul/ui/url/text()')[0]
        vt = vi.xpath('ul/ui/vt/text()')[0]

        for ci in vi.xpath('cl/ci'):
            idx = int(ci.xpath('idx/text()')[0])
            cd = float(ci.xpath('cd/text()')[0])

            vclip = getvclip(url, vid, vt, slid, idx)

            filename = vclip['filename']
            key = vclip['key']

            print '%d: %s (%f, %d) %s' % (idx, filename, cd, vclip['fs'], vclip['md5'])

            cdn_url = '%s/%s' % (cdn_host, filename)
            target_file = os.path.join(target_dir, filename)
            if os.path.exists(target_file):
                continue
            download_vclip(target_file, cdn_url, key, vclip['br'], vclip['fmt'], vclip['fs'])
コード例 #6
0
ファイル: txsp.py プロジェクト: zero20151631/crawlers
def getvinfo(target_dir, url, vid):
    rand = random.random()
    ckey = echo_ckeyv3(vid, PLAYER_GUID, rand, player_version=PLAYER_VERSION, platform=PLATFORM)
    params = {
        "fp2p": 1,
        "charge": 0,
        "guid": PLAYER_GUID,
        "pid": PLAYER_PID,
        "vid": vid,
        "platform": PLATFORM,
        "cKey": ckey,
        "otype": "xml",
        "fhdswitch": 0,
        "defnpayver": 1,
        "appver": PLAYER_VERSION,
        "ehost": url,
        "vids": vid,
        "encryptVer": "5.4",
        "utype": 0,
        "ran": "%.16f" % rand,
        "speed": random.randint(1000, 3000),
    }
    request = urllib2.Request("http://vv.video.qq.com/getvinfo")
    request.add_header("Referer", SWF_REFERER)
    request.add_header("Content-type", "application/x-www-form-urlencoded")
    request.add_header("User-Agent", USER_AGENT)

    form = urllib.urlencode(params)
    resp = urllib2.urlopen(request, data=form)

    vinfo = resp.read()
    tree = etree.fromstring(vinfo)

    resolutions = {}
    slid = None
    for fi in tree.xpath("/root/fl/fi"):
        name = fi.xpath("name/text()")[0]
        fiid = int(fi.xpath("id/text()")[0])
        sl = int(fi.xpath("sl/text()")[0])
        cname = fi.xpath("cname/text()")[0]
        if sl:
            slid = fiid
            print "Selected %s: %s" % (name, cname)
        resolutions[name] = fiid

    print resolutions

    for vi in tree.xpath("/root/vl/vi"):
        video_type = int(vi.xpath("videotype/text()")[0])
        if video_type == 1:
            video_type = "flv"
        elif video_type == 2:
            video_type = "mp4"
        else:
            video_type = "unknown"

        video_id = vi.xpath("vid/text()")[0]

        cdn_host = vi.xpath("ul/ui/url/text()")[0]
        vt = vi.xpath("ul/ui/vt/text()")[0]

        for ci in vi.xpath("cl/ci"):
            idx = int(ci.xpath("idx/text()")[0])
            cd = float(ci.xpath("cd/text()")[0])

            vclip = getvclip(url, vid, vt, slid, idx)

            filename = vclip["filename"]
            key = vclip["key"]

            print "%d: %s (%f, %d) %s" % (idx, filename, cd, vclip["fs"], vclip["md5"])

            cdn_url = "%s/%s" % (cdn_host, filename)
            download_vclip(os.path.join(target_dir, filename), cdn_url, key, vclip["br"], vclip["fmt"], vclip["fs"])
コード例 #7
0
ファイル: txsp.py プロジェクト: ytwangli/crawlers
def getvinfo(target_dir, url, vid):
    rand = random.random()
    ckey = echo_ckeyv3(vid,
                       PLAYER_GUID,
                       rand,
                       player_version=PLAYER_VERSION,
                       platform=PLATFORM)
    params = {
        'newplatform': PLATFORM,
        'guid': PLAYER_GUID,
        'pid': PLAYER_PID,
        'speed': random.randint(5000, 9000),
        'vids': vid,
        'fp2p': 1,
        'dtype': 3,
        'linkver': 2,
        'ehost': url,
        'fhdswitch': 0,
        'cKey': ckey,
        'vid': vid,
        'appver': PLAYER_VERSION,
        'ran': '%.16f' % rand,
        'utype': 0,
        'encryptVer': '5.4',
        'defnpayver': 1,
        'charge': 0,
        'ip': '',
        'otype': 'xml',
        'platform': PLATFORM,
    }
    request = urllib2.Request('http://vv.video.qq.com/getvinfo')
    request.add_header('Referer', SWF_REFERER)
    request.add_header('Content-type', 'application/x-www-form-urlencoded')
    request.add_header('User-Agent', USER_AGENT)

    form = urllib.urlencode(params)
    resp = urllib2.urlopen(request, data=form)

    vinfo = resp.read()
    # print 'vinfo=', vinfo
    tree = etree.fromstring(vinfo)

    resolutions = {}
    slid = None
    for fi in tree.xpath('/root/fl/fi'):
        name = fi.xpath('name/text()')[0]
        fiid = int(fi.xpath('id/text()')[0])
        sl = int(fi.xpath('sl/text()')[0])
        cname = fi.xpath('cname/text()')[0]
        resolutions[name] = fiid
        if sl or name == 'fhd':
            slid = fiid
            print 'Selected %s: %s' % (name, cname)
            break


#    print 'resolutions=', resolutions

    for vi in tree.xpath('/root/vl/vi'):
        video_type = int(vi.xpath('videotype/text()')[0])
        if video_type == 1:
            video_type = 'flv'
        elif video_type == 2:
            video_type = 'mp4'
        else:
            video_type = 'unknown'

        video_id = vi.xpath('vid/text()')[0]

        cdn_host = vi.xpath('ul/ui/url/text()')[0]
        vt = vi.xpath('ul/ui/vt/text()')[0]
        fn = vi.xpath('fn/text()')[0]
        fs = int(vi.xpath('fs/text()')[0])

        fc = int(vi.xpath('cl/fc/text()')[0])
        if fc == 0:
            vkey = getvkey(url, vid, vt, slid, fn)
            filename = vkey.get('filename')
            target_file = os.path.join(target_dir, filename)
            cdn_url = '%s/%s' % (cdn_host, filename)
            key = vkey.get('key')
            br = vkey.get('br')
            download_vclip(target_file, cdn_url, key, br, video_type, fs)

        else:
            for ci in vi.xpath('cl/ci'):
                idx = int(ci.xpath('idx/text()')[0])
                cd = float(ci.xpath('cd/text()')[0])
                md5 = ci.xpath('cmd5/text()')[0]

                vclip = getvclip(url, vid, vt, slid, idx)

                filename = vclip['filename']
                key = vclip['key']

                print '%d: %s (%f, %d) %s' % (idx, filename, cd, vclip['fs'],
                                              md5)

                cdn_url = '%s/%s' % (cdn_host, filename)
                target_file = os.path.join(target_dir, filename)
                if os.path.exists(target_file):
                    continue
                download_vclip(target_file, cdn_url, key, vclip['br'],
                               vclip['fmt'], vclip['fs'])