基於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()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM