#!/usr/bin/python
#-*- coding: utf-8 -*-
#encoding=utf-8
import hashlib
import time
import sys
import base64
import requests
import json
import re
reload(sys)
sys.setdefaultencoding('utf8')
# md5加密 一次加密 - 截取加密字符串 - 再次加密
def md5(string):
m2 = hashlib.md5()
m2.update(string)
m4 = m2.hexdigest()[9:17].upper() + 'zxnva09'*2 + m2.hexdigest()[20:25].upper() + 'zxnva09'
# print m4
m3 = hashlib.md5()
m3.update(m4)
# print m3.hexdigest()
return m3.hexdigest()
#获取当前时间
def getConrentTime():
return int(time.time()*1000)
def getFilmURlWithString(string): # 获取影视连接
r = requests.get(url=string)
data = json.loads(r.text)
return data
def savefileDianYing(string):
f = open("/Users/zhaohongya/Documents/赵宏亚/python/课程学习/电影名单.txt","a")
f.writelines(string)
f.close()
def base64encode(string):
# 加密
return base64.b64encode(string)
def base64deconde(string):
# 解密
return base64.b64decode(string)
# def getFilmURlWithString(string): # 获取影视连接
# r = requests.get(url=string)
# data = json.loads(r.text)
# film = '\n电影名字:%s \nhd_url:%s \nordinary_url:%s \nsuper_clearurl:%s' % (data['video_name'], data['hd_url'], data['ordinary_url'], data['super_clearurl'])
# return film
def savefile(string):
f = open("/Users/zhaohongya/Documents/赵宏亚/python/课程学习/网络数据名单.txt","a")
f.writelines(string)
f.close()
# 获取电影列表
t = getConrentTime()
string = 't=%d&VideoGroupType=Movie&ClassName=&UserID=20247&PageIndex=1&PageSize=100' % (t)
url = 'http://www.heng.com:7788/VideoGroupInfoSecondScreen.ashx?t=%d&auth=%s&VideoGroupType=Movie&ClassName=&UserID=20247&PageIndex=1&PageSize=100' % (t, md5(string))
data = getFilmURlWithString(url)
film = '[\n'
# 开始获取内容
for dic in data['typevideolist']:
# print dic['videoname']
# print dic['videoimgurl']
# print dic['videoid']
VideoID = dic['videoid']
# print VideoID
stringOne = 't=%d&UserID=20247&SRoomID=106&PlayType=VIDEO&SRoomWay=MY&VideoID=%s&SwitchVideo=T' % (t, VideoID)
urlOne = 'http://www.iyotv.com:7788/ShowRoomShowStart.ashx?t=%d&auth=%s&UserID=20247&SRoomID=106&PlayType=VIDEO&SRoomWay=MY&VideoID=%s&SwitchVideo=T' % (t, md5(stringOne), VideoID)
data = getFilmURlWithString(urlOne)
# film = '{\n电影名字:%s \nhd_url:%s \nordinary_url:%s \nsuper_clearurl:%s' % (data['video_name'], data['hd_url'], data['ordinary_url'], data['super_clearurl'])
# print 'film ======= ', film
mp4file = requests.get(url=data['hd_url'])
# print mp4file.text
# print type(mp4file.text.encode('utf-8'))
str = mp4file.text.encode('utf-8')
searchObjOne = re.search(r'file(.*?)\r\n', str, re.M|re.I|re.S)
if searchObjOne:
film += '{\n电影名字:%s\n电影连接:%s\n图片连接:%s\n},\n' % (data['video_name'], searchObjOne.group(1), dic['videoimgurl'])
# print film
else:
print 'searchObjOne no match'
print str
# savefile(film)
film += ']'
# print(film)