玩蛇网提供最新Python编程技术信息以及Python资源下载!

用python解析风行网vip电影播放地址解析

用python解析风行网vip电影播放地址解析,通过http请求分析,获取视频最终的cdn播放地址,也就是一个mp4视频。
vip电影想看就看,你懂的。

仅用于学习交流目的,最长24小时后请删除^_^
 
 

 

1. [用python解析风行网vip电影播放地址解析文件] fun.py ~ 3KB

#!/usr/bin/evn python
#coding=utf8

import sys
import os
import time
import urllib2
import cStringIO, gzip
import lxml.html
import re
import json
import random

def createRequest(url, referer = None):
    req = urllib2.Request(
        urllib2.quote(url.split('#')[0].encode('utf8'), safe = "%/:=&?~#+!$,;'@()*[]"), 
        headers = {"Accept": "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
                   "Accept-Charset": "GBK,utf-8;q=0.7,*;q=0.3",
                   "Accept-Encoding": "gzip",
                   "Accept-Language": "zh-CN,zh;q=0.8",
                   "Cache-Control": "max-age=0",
                   "Connection": "keep-alive",
                   "User-Agent": "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2",
        })
    
    if referer is not None: 
        req.add_header('Referer', referer)
    return req

def getContent(url, referer = None):
    f = urllib2.urlopen(createRequest(url, referer), timeout = 15)
    data = f.read()
    if data[:6] == '\x1f\x8b\x08\x00\x00\x00':
        data = gzip.GzipFile(fileobj = cStringIO.StringIO(data)).read()
    f.close()
    
    return data

def getCdnUrl(apiUrl, referer = None):
    content = getContent(apiUrl, referer)
    data = json.loads(content)
    token = data['token']
    for resource in data['fsps']:
        fspUrl = resource['url']
        if resource['clarity'] == 'super-dvd':
            fspUrl = resource['url']

    fsp = re.findall("fsp://(\w+)", fspUrl)[0]
    if fsp == '':
        return None
    else:
        timestamp = int(time.time())
        cdnUrl = 'http://jobsfe.funshion.com/query/v1/mp4/{0}.json?clifz=fun&mac=&tm={1}&token={2}'.format(fsp, timestamp, token)
        return cdnUrl

def getPlayUrl(cdnUrl, referer = None):
    content = getContent(cdnUrl, referer)
    data = json.loads(content)
    if data['return'] == 'succ':
        playUrls = data['playlist'][0]['urls']
        return playUrls[random.randint(0, len(playUrls)-1)]
    return None

if __name__ == '__main__':
    if len(sys.argv) < 2 or sys.argv[1].startswith('http') is None:
        print 'Usage: python fun.py http://www.fun.tv/vplay/m-115946/'
        print 'Please input the url to be parse'
        sys.exit()

    videoUrl = sys.argv[1]
    vid = int(re.findall("vplay/m-(\d+)", videoUrl)[0])
    apiUrl = 'http://api.fun.tv/ajax/get_webplayinfo/{0}/1/mp4?user=funshion'.format(vid)
    cdnUrl = getCdnUrl(apiUrl, videoUrl)
    playUrl = getPlayUrl(cdnUrl, videoUrl)
    print playUrl

玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/code/c819.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年01月16日 - 16时30分33秒 发布自玩蛇网

您现在的位置: 玩蛇网首页 > Python源码实例 > 正文内容
我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules