from lxml import etree
import pymysql
import requests
import re
import time
import hashlib
import execjs
import codecs

# 打开数据库连接
db = pymysql.connect("172.96.211.248", "tv_live", "CmEBNZjAdEWYdwrW", "tv_live", charset='utf8' )
# 使用cursor()方法获取操作游标 
cur = db.cursor()
#清空数据库
cur.execute("truncate table iptv")
cur.execute("truncate table huya")
cur.execute("truncate table bilibili")
cur.execute("truncate table douyu")
db.commit()

#定义虎牙直播地址获取
headers={'User-Agent':'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 MicroMessenger/7.0.3(0x17000321) NetType/WIFI Language/zh_CN'}
hy_01="https://m.huya.com/"
xrule="//video[@id='html5player-video']/@src"
def get_hyreal_url(room):
    hy_url=hy_01+room
    html=requests.get(hy_url,headers=headers)
    respon=etree.HTML(html.text)
    match=respon.xpath(xrule)
    return "http:"+match[0]

#IPTV函数定义开始
def get_iptvreal_url(wurl):
    html=requests.get(wurl)
    regex=r"http.*\'"
    real_url=re.findall(regex,html.text)
    return (real_url[0].strip("'"))

#哔哩哔哩函数定义开始
def get_real_rid(rid):
    room_url = 'https://api.live.bilibili.com/room/v1/Room/room_init?id=' + str(rid)
    response = requests.get(url=room_url).json()
    data = response.get('data', 0)
    if data:
        live_status = data.get('live_status', 0)
        room_id = data.get('room_id', 0)
    else:
        live_status = room_id = 0
    return live_status, room_id


def get_blreal_url(rid):
    room = get_real_rid(rid)
    live_status = room[0]
    room_id = room[1]
    if live_status:
        try:
            room_url = 'https://api.live.bilibili.com/xlive/web-room/v1/index/getRoomPlayInfo?room_id={}&play_url=1&mask=1&qn=0&platform=web'.format(room_id)
            response = requests.get(url=room_url).json()
            durl = response.get('data').get('play_url').get('durl', 0)
            real_url = durl[-1].get('url')
        except:
            real_url = '疑似部分国外IP无法GET到正确数据,待验证'
    else:
        real_url = '未开播或直播间不存在'
    return real_url

#斗鱼函数定义开始
def get_tt():
    tt1 = str(int(time.time()))
    tt2 = str(int((time.time() * 1000)))
    today = time.strftime('%Y%m%d', time.localtime())
    return tt1, tt2, today


def get_homejs(rid):
    room_url = 'https://m.douyu.com/' + rid
    response = requests.get(url=room_url)
    pattern_real_rid = r'"rid":(\d{1,7})'
    real_rid = re.findall(pattern_real_rid, response.text, re.I)[0]
    if real_rid != rid:
        room_url = 'https://m.douyu.com/' + real_rid
        response = requests.get(url=room_url)
    homejs = ''
    pattern = r'(function ub9.*)[\s\S](var.*)'
    result = re.findall(pattern, response.text, re.I)
    str1 = re.sub(r'eval.*;}', 'strc;}', result[0][0])
    homejs = str1 + result[0][1]
    return homejs, real_rid


def get_sign(rid, post_v, tt, ub9):
    docjs = execjs.compile(ub9)
    res2 = docjs.call('ub98484234')
    str3 = re.sub(r'\(function[\s\S]*toString\(\)', '\'', res2)
    md5rb = hashlib.md5((rid + '10000000000000000000000000001501' + tt + '2501' +
                         post_v).encode('utf-8')).hexdigest()
    str4 = 'function get_sign(){var rb=\'' + md5rb + str3
    str5 = re.sub(r'return rt;}[\s\S]*','return re;};', str4) 
    str6 = re.sub(r'"v=.*&sign="\+', '', str5)
    docjs1 = execjs.compile(str6)
    sign = docjs1.call(
        'get_sign', rid, '10000000000000000000000000001501', tt)
    return sign


def mix_room(rid):
    result1 = 'PKing'
    return result1


def get_pre_url(rid, tt):
    request_url = 'https://playweb.douyucdn.cn/lapi/live/hlsH5Preview/' + rid
    post_data = {
        'rid': rid,
        'did': '10000000000000000000000000001501'
    }
    auth = hashlib.md5((rid + str(tt)).encode('utf-8')).hexdigest()
    header = {
        'content-type': 'application/x-www-form-urlencoded',
        'rid': rid,
        'time': tt,
        'auth': auth
    }
    response = requests.post(url=request_url, headers=header, data=post_data)
    response = response.json()
    pre_url = ''
    if response.get('error') == 0:
        real_url = (response.get('data')).get('rtmp_live')
        if 'mix=1' in real_url:
            pre_url = mix_room(rid)
        else:
            pattern1 = r'^[0-9a-zA-Z]*'
            pre_url = re.search(pattern1, real_url, re.I).group()
    return pre_url


def get_sign_url(post_v, rid, tt, ub9):
    sign = get_sign(rid, post_v, tt, ub9)
    request_url = 'https://m.douyu.com/api/room/ratestream'
    post_data = {
        'v': '2501' + post_v,
        'did': '10000000000000000000000000001501',
        'tt': tt,
        'sign': sign,
        'ver': '219032101',
        'rid': rid,
        'rate': '-1'
    }
    header = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'User-Agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36'
    }
    response = requests.post(url=request_url, headers=header, data=post_data).json()
    if response.get('code') == 0:
        real_url = (response.get('data')).get('url')
        if 'mix=1' in real_url:
            result1 = mix_room(rid)
        else:
            pattern1 = r'live/(\d{1,8}[0-9a-zA-Z]+)_?[\d]{0,4}/playlist'
            result1 = re.findall(pattern1, real_url, re.I)[0]
    else:
        result1 = 0
    return result1


def get_dyreal_url(rid):
    rid = str(rid)
    tt = get_tt()
    url = get_pre_url(rid, tt[1])
    if url:
        return "http://tx2play1.douyucdn.cn/live/" + url + ".flv?uuid="
    else:
        result = get_homejs(rid)
        real_rid = result[1]
        homejs = result[0]
        real_url = get_sign_url(tt[2], real_rid, tt[0], homejs)
        if real_url != 0:
            real_url = "http://tx2play1.douyucdn.cn/live/" + real_url + ".flv?uuid="
        else:
            real_url = '未开播'
        return real_url


def get_url_from_js(rid):
    # 从播放页源代码中直接匹配地址
    header = {
    'Content-Type': 'application/x-www-form-urlencoded'
    }
    try:
        response = requests.get('https://www.douyu.com/{}'.format(rid), headers=header).text
        real_url = re.findall(r'live/({}[\d\w]*?)_'.format(rid), response)[0]
    except:
        real_url = '直播间未开播或不存在'
    return "http://tx2play1.douyucdn.cn/live/" + real_url + ".flv?uuid="

#定义IPTV数组
iptv_array=["湖南卫视,http://player.ioioz.com/17/js/yangzhouflvpc.php?id=hnws",
            "湖南都市,http://player.ioioz.com/17/hunan/mgtv.php?id=hnds",
            "湖南娱乐,http://player.ioioz.com/17/hunan/mgtv.php?id=hnyl",
            "湖南经视,http://player.ioioz.com/17/hunan/mgtv.php?id=hnjs"]

#定义bilibili数组
bl_array=[ "樱桃小丸子,10367724",
        "中华小当家,211603",
        "红楼梦,21730412",
        "情深深雨蒙蒙,21292394"]

#定义斗鱼数组
dy_array=["名侦探柯南,82205",
    "金庸武侠剧,7795592",
    "悬疑港剧A,7679196",
    "悬疑港剧B,5869182",
    "经典港剧,4290711",
    "皆大欢喜,5689514",
    "新白娘子传奇,7678360",
    "港剧24H,326852",
    "热门港剧,5522351",
    "经典港剧,4549169"]

#定义虎牙数组
hy_array=["蜡笔小新,11352970",
    "犬夜叉,11352893",
    "TVB西游记,11342395",
    "还珠格格,11342415",
    "金枝欲孽,11352963",
    "甄嬛传,11601955",
    "芈月传,11352918",
    "知否,知否,11602068",
    "父母爱情,11352920",
    "爱情公寓,11336726",
    "武林外传,11352915",
    "铁齿铜牙纪晓岚,11342396",
    "琅琊榜,11352956",
    "亮剑,11342434",
    "漫威英雄,11602075",
    "女神系列,11336571",
    "李连杰影片,11342390",
    "刘德华影片,11342424",
    "甄子丹影片,11352935",
    "生化危机,11352962",
    "陈翔六点半,cxldb",
    "美食记录片,11352955",
    "BIG笑工坊,14776702",
    "动物世界,11352912"]

#数据库操作
for arr in dy_array:
    arr01=arr.split(',')
    cur.execute("insert into douyu (name,url) values ('%s','%s')"%(arr01[0],get_dyreal_url(arr01[1])))
    db.commit()
print ("斗鱼资源已更新完毕!")

for arr in bl_array:
    arr02=arr.split(',')
    cur.execute("insert into bilibili (name,url) values ('%s','%s')"%(arr02[0],get_blreal_url(arr02[1])))
    db.commit()
print ("bilibili资源已更新完毕!")

for arr in huya_array:
    arr03=arr.split(',')
    cur.execute("insert into huya (name,url) values ('%s','%s')"%(arr03[0],get_hyreal_url(arr03[1])))
    db.commit()
print ("虎牙资源已更新完毕!")

for arr in iptv_array:
    arr04=arr.split(',')
    cur.execute("insert into iptv (name,url) values ('%s','%s')"%(arr04[0],get_iptvreal_url(arr04[1])))
    db.commit()
print ("IPTV已更新完毕!")

#关闭数据库
db.close()
colatiger(前端大神) - 2020-01-19 0 人
自用的电视盒子IPTV网络电视文件
class Person():
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex
    def personInfo(self):
        print("个人信息:")
        print("姓名:%s, 性别:%s, 年龄:%d"%(self.name, self.sex, self.age))

class Student(Person):
    def __init__(self, college, cls, name, age, sex):
        super().__init__(name, age, sex)
        self.college = college
        self.cls = cls
    def personInfo(self):
        # Person.personInfo(self)
        super().personInfo()
        print("学生信息:")
        print('校园:%s, 班级:%s'%(self.college, self.cls))
    def study(self, teacher):
        res = teacher.teachObj()
        print("老师 %s,我终于学会了!"%res)
    def __str__(self):
        res = '校园:%s, 班级:%s, 姓名:%s, 年龄:%s, 性别: %s'%(self.college, self.cls, self.name, self.age, self.sex)
        return res

class Teacher(Person):
    def __init__(self,college, professional, name, age, sex):
        super().__init__(name, age, sex)
        self.college = college
        self.professional = professional
    def personInfo(self):
        super().personInfo()
        print("老师信息:")
        print("学院:%s, 专业:%s"%(self.college, self.professional))
    def teachObj(self):
        res = "今天用了如何用面向对象程序设计"
        return res
    
if __name__ == "__main__":
    st1 = Student("西南石油大学", "计科2班", "莎诺斯", 300, "Male")
    st2 = Student("西南石油大学", "计科3班", "卡莎", 23, "Women")
    st3 = Student("西南石油大学", "计科4班", "塞拉斯", 30, "Male")
    tea = Teacher("西南石油大学", "计算机", "诺曼", 40, "Male")
    st1.study(tea)
    stu = [st1, st2, st3]
    for item in stu:
        print(item)
alanhahahah(前端大神) - 2019-12-19 0 人
作业,用于学习类
class Person():
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex
    def personInfo(self):
        print("个人信息:")
        print("姓名:%s, 性别:%s, 年龄:%d"%(self.name, self.sex, self.age))

class Student(Person):
    def __init__(self, college, cls, name, age, sex):
        super().__init__(name, age, sex)
        self.college = college
        self.cls = cls
    def personInfo(self):
        # Person.personInfo(self)
        super().personInfo()
        print("学生信息:")
        print('校园:%s, 班级:%s'%(self.college, self.cls))
    def study(self, teacher):
        res = teacher.teachObj()
        print("老师 %s,我终于学会了!"%res)
    def __str__(self):
        res = '校园:%s, 班级:%s, 姓名:%s, 年龄:%s, 性别: %s'%(self.college, self.cls, self.name, self.age, self.sex)
        return res

class Teacher(Person):
    def __init__(self,college, professional, name, age, sex):
        super().__init__(name, age, sex)
        self.college = college
        self.professional = professional
    def personInfo(self):
        super().personInfo()
        print("老师信息:")
        print("学院:%s, 专业:%s"%(self.college, self.professional))
    def teachObj(self):
        res = "今天用了如何用面向对象程序设计"
        return res
    
if __name__ == "__main__":
    st1 = Student("西南石油大学", "计科2班", "莎诺斯", 300, "Male")
    st2 = Student("西南石油大学", "计科3班", "卡莎", 23, "Women")
    st3 = Student("西南石油大学", "计科4班", "塞拉斯", 30, "Male")
    tea = Teacher("西南石油大学", "计算机", "诺曼", 40, "Male")
    st1.study(tea)
    stu = [st1, st2, st3]
    for item in stu:
        print(item)
alanhahahah(前端大神) - 2019-12-19 0 人
作业,用于学习类
class Person():
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex
    def personInfo(self):
        print("个人信息:")
        print("姓名:%s, 性别:%s, 年龄:%d"%(self.name, self.sex, self.age))

class Student(Person):
    def __init__(self, college, cls, name, age, sex):
        super().__init__(name, age, sex)
        self.college = college
        self.cls = cls
    def personInfo(self):
        # Person.personInfo(self)
        super().personInfo()
        print("学生信息:")
        print('校园:%s, 班级:%s'%(self.college, self.cls))
    def study(self, teacher):
        res = teacher.teachObj()
        print("老师 %s,我终于学会了!"%res)
    def __str__(self):
        res = '校园:%s, 班级:%s, 姓名:%s, 年龄:%s, 性别: %s'%(self.college, self.cls, self.name, self.age, self.sex)
        return res

class Teacher(Person):
    def __init__(self,college, professional, name, age, sex):
        super().__init__(name, age, sex)
        self.college = college
        self.professional = professional
    def personInfo(self):
        super().personInfo()
        print("老师信息:")
        print("学院:%s, 专业:%s"%(self.college, self.professional))
    def teachObj(self):
        res = "今天用了如何用面向对象程序设计"
        return res
    
if __name__ == "__main__":
    st1 = Student("西南石油大学", "计科2班", "莎诺斯", 300, "Male")
    st2 = Student("西南石油大学", "计科3班", "卡莎", 23, "Women")
    st3 = Student("西南石油大学", "计科4班", "塞拉斯", 30, "Male")
    tea = Teacher("西南石油大学", "计算机", "诺曼", 40, "Male")
    st1.study(tea)
    stu = [st1, st2, st3]
    for item in stu:
        print(item)
alanhahahah(前端大神) - 2019-12-19 0 人
作业,用于学习类
class Person():
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex
    def personInfo(self):
        print("个人信息:")
        print("姓名:%s, 性别:%s, 年龄:%d"%(self.name, self.sex, self.age))

class Student(Person):
    def __init__(self, college, cls, name, age, sex):
        super().__init__(name, age, sex)
        self.college = college
        self.cls = cls
    def personInfo(self):
        # Person.personInfo(self)
        super().personInfo()
        print("学生信息:")
        print('校园:%s, 班级:%s'%(self.college, self.cls))
    def study(self, teacher):
        res = teacher.teachObj()
        print("老师 %s,我终于学会了!"%res)
    def __str__(self):
        res = '校园:%s, 班级:%s, 姓名:%s, 年龄:%s, 性别: %s'%(self.college, self.cls, self.name, self.age, self.sex)
        return res

class Teacher(Person):
    def __init__(self,college, professional, name, age, sex):
        super().__init__(name, age, sex)
        self.college = college
        self.professional = professional
    def personInfo(self):
        super().personInfo()
        print("老师信息:")
        print("学院:%s, 专业:%s"%(self.college, self.professional))
    def teachObj(self):
        res = "今天用了如何用面向对象程序设计"
        return res
    
if __name__ == "__main__":
    st1 = Student("西南石油大学", "计科2班", "莎诺斯", 300, "Male")
    st2 = Student("西南石油大学", "计科3班", "卡莎", 23, "Women")
    st3 = Student("西南石油大学", "计科4班", "塞拉斯", 30, "Male")
    tea = Teacher("西南石油大学", "计算机", "诺曼", 40, "Male")
    st1.study(tea)
    stu = [st1, st2, st3]
    for item in stu:
        print(item)
alanhahahah(前端大神) - 2019-12-19 0 人
作业,用于学习类
# coding=utf-8  
   
import turtle  
from datetime import *  
   
# 抬起画笔,向前运动一段距离放下  
def Skip(step):  
    turtle.penup()  
    turtle.forward(step)  
    turtle.pendown()  
   
def mkHand(name, length):  
    # 注册Turtle形状,建立表针Turtle  
    turtle.reset()  
    Skip(-length * 0.1)  
    # 开始记录多边形的顶点。当前的乌龟位置是多边形的第一个顶点。  
    turtle.begin_poly()  
    turtle.forward(length * 1.1)  
    # 停止记录多边形的顶点。当前的乌龟位置是多边形的最后一个顶点。将与第一个顶点相连。  
    turtle.end_poly()  
    # 返回最后记录的多边形。  
    handForm = turtle.get_poly()  
    turtle.register_shape(name, handForm)  
   
def Init():  
    global secHand, minHand, hurHand, printer  
    # 重置Turtle指向北  
    turtle.mode("logo")  
    # 建立三个表针Turtle并初始化  
    mkHand("secHand", 135)  
    mkHand("minHand", 125)  
    mkHand("hurHand", 90)  
    secHand = turtle.Turtle()  
    secHand.shape("secHand")  
    minHand = turtle.Turtle()  
    minHand.shape("minHand")  
    hurHand = turtle.Turtle()  
    hurHand.shape("hurHand")  
     
    for hand in secHand, minHand, hurHand:  
        hand.shapesize(1, 1, 3)  
        hand.speed(0)  
     
    # 建立输出文字Turtle  
    printer = turtle.Turtle()  
    # 隐藏画笔的turtle形状  
    printer.hideturtle()  
    printer.penup()  
      
def SetupClock(radius):  
    # 建立表的外框  
    turtle.reset()  
    turtle.pensize(7)  
    for i in range(60):  
        Skip(radius)  
        if i % 5 == 0:  
            turtle.forward(20)  
            Skip(-radius - 20)  
             
            Skip(radius + 20)  
            if i == 0:  
                turtle.write(int(12), align="center", font=("Courier", 14, "bold"))  
            elif i == 30:  
                Skip(25)  
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))  
                Skip(-25)  
            elif (i == 25 or i == 35):  
                Skip(20)  
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))  
                Skip(-20)  
            else:  
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))  
            Skip(-radius - 20)  
        else:  
            turtle.dot(5)  
            Skip(-radius)  
        turtle.right(6)  
          
def Week(t):     
    week = ["星期一", "星期二", "星期三",  
            "星期四", "星期五", "星期六", "星期日"]  
    return week[t.weekday()]  
   
def Date(t):  
    y = t.year  
    m = t.month  
    d = t.day  
    return "%s %d %d" % (y, m, d)  
   
def Tick():  
    # 绘制表针的动态显示  
    t = datetime.today()  
    second = t.second + t.microsecond * 0.000001  
    minute = t.minute + second / 60.0  
    hour = t.hour + minute / 60.0  
    secHand.setheading(6 * second)  
    minHand.setheading(6 * minute)  
    hurHand.setheading(30 * hour)  
      
    turtle.tracer(False)   
    printer.forward(65)  
    printer.write(Week(t), align="center",  
                  font=("Courier", 14, "bold"))  
    printer.back(130)  
    printer.write(Date(t), align="center",  
                  font=("Courier", 14, "bold"))  
    printer.home()  
    turtle.tracer(True)  
   
    # 100ms后继续调用tick  
    turtle.ontimer(Tick, 100)  
   
def main():  
    # 打开/关闭龟动画,并为更新图纸设置延迟。  
    turtle.tracer(False)  
    Init()  
    SetupClock(160)  
    turtle.tracer(True)  
    Tick()  
    turtle.mainloop()  
   
if __name__ == "__main__":  
    main()  
wangsibo(B W C酷) - 2019-11-24 0 人
Python时钟
没有了
1/10 下一页