基于python实现的VIP视频播放器源代码

import re
import tkinter as tk
import requests
import webbrowser # 使应用程序直接接入网页内容

# 定义获取接口url地址的函数
def get_interface_url():
url = 'http://www.qmaile.com/' # 全民解析网址
resp = requests.get(url)
# print(resp.content.decode('utf-8')) # 正确解码,显示包括汉字的二进制的网页源代码(前提是源代码是utf-8的
resp.encoding = resp.apparent_encoding # 从网页中获得源代码的编码,并设置解码
response = resp.text #
res = re.compile('<option value="(.*?)" selected="">')
rootweb = re.findall(res, response) # 获得全部接口url
rootweb.pop(1)
return(rootweb) # 返回接口url列表


# 定义播放GUI
root = tk.Tk()
root.title('VIP视频播放器')
root.geometry('500x300+100+100')
l1 = tk.Label(root, text = '播放接口:', font = ('仿宋', 12))
l1.grid(row = 0, column = 0)

# 定义播放函数
def play():
# var.get()获得单选框最后选定结果
# chromePath = r"C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe"
# C:\Users\Administrator\AppData\Local\Google\Chrome\Application
with open(r'addr.txt', 'r') as f: #加入r'addr.txt'读取文件中的内容为原生字符串
chromePath = f.readline().strip() + '\\chrome.exe'
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(
chromePath)) # 这里的'chrome'可以用其它任意名字,如chrome111,这里将想打开的浏览器保存到'chrome'
webbrowser.get('chrome').open(var.get() + t1.get())

# 定义清除函数
def del_text():
t1.delete(0, 'end') # 清除文本输入框中的内容

def savechrome():
new_addr = t2.get()
with open('addr.txt', 'w') as f:
f.write(new_addr)

one, two, three, four, five, six = get_interface_url() # 获取接口地址并重新赋值给变量
# 定义变量,开始单选钮界面
var = tk.StringVar()
var.set(one) # 设定初始单选钮值为one
r1 = tk.Radiobutton(root, text = '播放接口1', variable = var, value = one)
r1.grid(row = 0, column = 1)
r2 = tk.Radiobutton(root, text = '播放接口2', variable = var, value = two)
r2.grid(row = 1, column = 1)
r3 = tk.Radiobutton(root, text = '播放接口3', variable = var, value = three)
r3.grid(row = 2, column = 1)
r4 = tk.Radiobutton(root, text = '播放接口4', variable = var, value = four)
r4.grid(row = 3, column = 1)
r5 = tk.Radiobutton(root, text = '播放接口5', variable = var, value = five)
r5.grid(row = 4, column = 1)
r6 = tk.Radiobutton(root, text = '播放接口6', variable = var, value = six)
r6.grid(row = 5, column = 1)

l2 = tk.Label(root, text = '播放链接:', font = ('仿宋', 12))
l2.grid(row = 6, column = 0)
t1 = tk.Entry(root, text = '', width = 50)
t1.grid(row = 6, column = 1)
# 定义播放按钮
b1 = tk.Button(root, text = '播放', width = 8, font = ('仿宋', 12), command = play)
b1.grid(row = 7, column = 1)
b2 = tk.Button(root, text = '清除', width = 8, font = ('仿宋', 12), command = del_text)
b2.grid(row = 8, column = 1)
l3 = tk.Label(root, text = 'chrome地址:', font = ('仿宋', 12))
l3.grid(row = 9, column = 0)
my_add = tk.StringVar()
with open('addr.txt', 'r') as f:
addr_content = f.readline()
my_add.set(addr_content)
t2 = tk.Entry(root, width = 50, textvariable = my_add)
t2.grid(row = 9, column = 1)
b3 = tk.Button(root, text = '保存chrome地址', font = ('仿宋', 12), command = savechrome)
b3.grid(row = 10, column = 1)
root.mainloop()

posted @ 2020-06-12 13:01  Iceberg_710815  阅读(4971)  评论(0编辑  收藏  举报