网络资源
全部免费下载

[Python] tk & json 做的GUI 人人影视下载资源解析

 [Python] tk & json 做的GUI 人人影视下载资源解析

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
import tkinter as tk
import tkinter.messagebox
import requests
import json
import pyperclip
 
def btn_5_srcCopy():
    try:
        src_chosen = listbox_4.get(listbox_4.curselection())
    except:
        tkinter.messagebox.showwarning('提示', '未选择资源')
    else:
        pyperclip.copy(src_chosen)
        tkinter.messagebox.showinfo('提示', '%s\n%s\n\n已复制至剪贴板' % (src_chosen.split('   ')[0], src_chosen.split('   ')[1]))
 
def btn_4_episodeChooser():
    try:
        episode_chosen = listbox_3.get(listbox_3.curselection())
    except:
        tkinter.messagebox.showwarning('提示', '未选择“集”')
    else:
        label_2.config(text='%s' % drama_title+'.'+season_chosen+'.'+episode_chosen)
        se_ep_chosen = season_chosen + episode_chosen
        listbox_4.delete(0, 'end')
        for se_ep, link, passwd in src:
            if se_ep == se_ep_chosen:
                listbox_4.insert('end', link + '   passwd:' + passwd)
        if listbox_4.size() == 0:
            listbox_4.insert('end', 'No resource found')
        listbox_4.selection_set(0)
        frame_4.place(x=220, y=240)
        btn_5.place(x=440, y=420)
 
def btn_3_seasonChooser():
    global season_chosen
    try:
        season_chosen = listbox_2.get(listbox_2.curselection())
    except:
        tkinter.messagebox.showwarning('提示', '未选择“季”')
    else:
        frame_4.place_forget()
        btn_5.place_forget()
        label_2.config(text='%s' % drama_title+'.'+season_chosen)
        listbox_3.delete(0, 'end')
        for se_ep in season_episodes:
            if se_ep.find(season_chosen) == 0:
                #找到且处于字符串开头
                listbox_3.insert('end', se_ep.replace(season_chosen, '', 1))
        frame_3.place(x=110, y=240)
        btn_4.place(x=110, y=420)
        #如果只有一个选项,则自动选中
        if listbox_3.size() == 1:
            listbox_3.selection_set(0)
            btn_4.invoke()
 
def Parser(resp_drama):
    result_drama = json.loads(resp_drama.text)
    if result_drama['info'] in ['暂无资源', '资源关闭']:
        tkinter.messagebox.showwarning('提示', result_drama['info'])
        return
    global season_episodes
    global src
    seasons = []
    season_episodes = []
    src = []
    try:
        list = result_drama['data']['list']
        for i in range(len(list)):
            season_name = list[i]['season_name']
            seasons.append(season_name)
            episodes = list[i]['episodes']
            if episodes:
                #正常情况,episodes是一个列表
                for j in range(len(episodes)):
                    episode_name = episodes[j]['episode_name']
                    season_episodes.append(season_name + episode_name)
                    files = episodes[j]['files']
                    for fileformat in files:
                        if fileformat == 'yyets':
                            src_address = files[fileformat]['name']
                            src_passwd = ''
                            src.append((season_name + episode_name, src_address, src_passwd))
                        else:
                            for m in range(len(files[fileformat])):
                                src_address = files[fileformat][m]['address']
                                src_passwd = files[fileformat][m]['passwd']
                                if not src_passwd:
                                    src_passwd = ''
                                src.append((season_name + episode_name, src_address, src_passwd))
            else:
                #特殊情况,"episodes": null
                seasons.pop()
        listbox_2.delete(0, 'end')
        for season in seasons:
            listbox_2.insert('end', season)
        frame_2.place(x=10, y=240)
        btn_3.place(x=10, y=420)
        #如果只有一个选项,则自动选中
        if listbox_2.size() == 1:
            listbox_2.selection_set(0)
            btn_3.invoke()
    except Exception as e:
        tkinter.messagebox.showwarning('出错了', e)
 
def btn_2_dramaChooser():
    global drama_title
    try:
        drama_chosen = listbox_1.get(listbox_1.curselection())
    except:
        tkinter.messagebox.showwarning('提示', '未选择影视剧')
    else:
        frame_2.place_forget()
        btn_3.place_forget()
        frame_3.place_forget()
        btn_4.place_forget()
        frame_4.place_forget()
        btn_5.place_forget()
        drama_id = ids[int(drama_chosen[:drama_chosen.index('.')])]
        drama_title = drama_chosen[drama_chosen.index('.')+1:]
        label_2.config(text='%s' % drama_title)
        label_2.place(x=10, y=200)
        try:
            resp_drama = requests.get(api_get+str(drama_id), headers=headers)
            if resp_drama.status_code != 200:
                resp_drama.raise_for_status()
        except Exception as e:
            tkinter.messagebox.showwarning('出错了', e)
        else:
            Parser(resp_drama)
 
def btn_1_search():
    global label_2
    global frame_2
    global listbox_2
    global btn_3
    global frame_3
    global listbox_3
    global btn_4
    global frame_4
    global listbox_4
    global btn_5
    global ids
    global listbox_1
    if entry_1.get() == '':
        tkinter.messagebox.showwarning('提示', '关键词缺失')
    else:
        try:
            response = requests.get(api_search+entry_1.get(), headers=headers)
            if response.status_code != 200:
                response.raise_for_status()
        except Exception as e:
            tkinter.messagebox.showwarning('出错了', e)
        else:
            label_2.place_forget()
            frame_2.place_forget()
            btn_3.place_forget()
            frame_3.place_forget()
            btn_4.place_forget()
            frame_4.place_forget()
            btn_5.place_forget()
            ids = []
            #print(json.dumps(json.loads(response.text), indent=2, ensure_ascii=False)) 查看嵌套结构
            result = json.loads(response.text)
            label_1 = tk.Label(window, text='查询结果:%d项' % len(result['data']), bg='green', fg='white', font=('simkai', 12), width=20, height=1)
            label_1.place(x=10, y=50)
            frame_1 = tk.Frame(window, width=72, height=6)
            frame_1.place(x=10, y=80)
            listbox_1 = tk.Listbox(frame_1, font=('simkai', 12), width=70, height=6)
            for i in range(len(result['data'])):
                ids.append(result['data'][i]['id'])
                listbox_1.insert('end', '%d.[%s].%s (%s)' % (i, result['data'][i]['channel_cn'], result['data'][i]['cnname'], result['data'][i]['enname']))
            listbox_1.pack(side='left', fill='both')
            scrollbar_1 = tk.Scrollbar(frame_1)
            scrollbar_1.pack(side='right', fill='y')
            listbox_1.config(yscrollcommand=scrollbar_1.set)
            scrollbar_1.config(command=listbox_1.yview)
            btn_2 = tk.Button(window, text='解析', font=('simkai', 12), width=6, height=1, command=btn_2_dramaChooser)
            btn_2.place(x=480, y=44)
            #如果只有一个选项,则自动选中
            if listbox_1.size() == 1:
                listbox_1.selection_set(0)
                btn_2.invoke()
 
if __name__ == "__main__":
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0'}
    api_search = 'http://pc.zmzapi.com/index.php?g=api/pv3&m=index&client=5&accesskey=519f9cab85c8059d17544947k361a827&a=search&uid=&token=&page=1&limit=30&k='
    api_get = 'http://pc.zmzapi.com/index.php?g=api/pv3&m=index&client=5&accesskey=519f9cab85c8059d17544947k361a827&a=resource&uid=undefined&token=undefined&id='
    window = tk.Tk()
    window.resizable(width=False, height=False)
    window.title('人人影视下载资源解析')
    width, height = (600, 480)
    screenwidth, screenheight = (window.winfo_screenwidth(), window.winfo_screenheight())
    size_loc = '%dx%d+%d+%d' % (width, height, (screenwidth-width)/2, (screenheight-height)/2)
    window.geometry(size_loc)
    v_keyword = tk.StringVar()
    v_keyword.set('复仇者')
    entry_1 = tk.Entry(window, textvariable=v_keyword, font=('simkai', 12), width=30)
    entry_1.place(x=10, y=20)
    btn_1 = tk.Button(window, text='搜索', font=('simkai', 12), width=5, height=1, command=btn_1_search)
    btn_1.place(x=260, y=16)
    #初始化以下组件但并不显示
    #video title banner
    label_2 = tk.Label(window, text='', bg='green', fg='white', font=('simkai', 12), width=72, height=1)
    #season chooser
    frame_2 = tk.Frame(window, width=12, height=12)
    listbox_2 = tk.Listbox(frame_2, font=('simkai', 10), width=10, height=12)
    listbox_2.pack(side='left', fill='both')
    scrollbar_2 = tk.Scrollbar(frame_2)
    scrollbar_2.pack(side='right', fill='y')
    listbox_2.config(yscrollcommand=scrollbar_2.set)
    scrollbar_2.config(command=listbox_2.yview)
    btn_3 = tk.Button(window, text='选择季', font=('simkai', 12), width=10, height=1, command=btn_3_seasonChooser)
    #episode chooser
    frame_3 = tk.Frame(window, width=12, height=12)
    listbox_3 = tk.Listbox(frame_3, font=('simkai', 10), width=10, height=12)
    listbox_3.pack(side='left', fill='both')
    scrollbar_3 = tk.Scrollbar(frame_3)
    scrollbar_3.pack(side='right', fill='y')
    listbox_3.config(yscrollcommand=scrollbar_3.set)
    scrollbar_3.config(command=listbox_3.yview)
    btn_4 = tk.Button(window, text='选择集', font=('simkai', 12), width=10, height=1, command=btn_4_episodeChooser)
    #link copier
    frame_4 = tk.Frame(window, width=52, height=12)
    listbox_4 = tk.Listbox(frame_4, font=('simkai', 10), width=50, height=12)
    listbox_4.pack(side='left', fill='both')
    scrollbar_4 = tk.Scrollbar(frame_4)
    scrollbar_4.pack(side='right', fill='y')
    listbox_4.config(yscrollcommand=scrollbar_4.set)
    scrollbar_4.config(command=listbox_4.yview)
    btn_5 = tk.Button(window, text='复制资源', font=('simkai', 12), width=10, height=1, command=btn_5_srcCopy)
    window.mainloop()

下载点击下载(密码:fuct)
注意:本站资源多为网络收集,如涉及版权问题请及时与站长联系QQ:2766242327,我们会在第一时间内与您协商解决。如非特殊说明,本站所有资源解压密码均为:fulinian.com。
赞(3) 打赏
未经允许不得转载:福利年 » [Python] tk & json 做的GUI 人人影视下载资源解析

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏