Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
12
Browse files Browse the repository at this point in the history
  • Loading branch information
lock committed May 11, 2019
1 parent 80134a0 commit 0ec8918
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 59 deletions.
2 changes: 1 addition & 1 deletion create_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ def has_file(dir: str) -> bool:


if __name__ == '__main__':
save(**parse_args())
save(storage_dir='./test')
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>玩很大转播(在线: 0 人)</title>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<link href="https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/hls.js/0.12.4/hls.min.js"></script>
<script src="https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.js"></script>
<script src="https://cdn.bootcss.com/socket.io/2.2.0/socket.io.slim.js"></script>
<!--<script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>-->
Expand All @@ -28,7 +28,7 @@
<div id="dplayer">
</div>
<script>
var socket_url = {{ socket_url }};
var socket_url = {{socket_url}};
if (socket_url === '1')
socket_url = 'http://' + window.location.host + '/danmaku';
var config = {
Expand Down
46 changes: 31 additions & 15 deletions layout_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, root, local_frame: layout_local.Frame, video_frame: layout_vi
self.root = root

frame = tkinter.Frame(root)
frame.pack(fill=tkinter.BOTH, padx=5, pady=5)
frame.pack(fill=tkinter.X, padx=5, pady=5, side=tkinter.BOTTOM)

self.local_frame = local_frame
self.video_frame = video_frame
Expand Down Expand Up @@ -193,7 +193,6 @@ def clear_cache(self):
messagebox.showerror('出现错误', '清空文件夹失败\n' + dir + '\n' + e.__str__())

def create_mp4(self):

if not utils.has_ffmpeg():
return messagebox.showerror('错误', '没有安装 ffmpeg')

Expand All @@ -211,27 +210,44 @@ def create_mp4(self):
command_line = 'ffmpeg -f concat -safe 0 -i {} -c copy {} -y'.format(list_path, final_mp4_path)

if platform == 'win32':
messagebox.showinfo('开始合并视频')
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
process = subprocess.Popen(command_line, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, startupinfo=si)
else:
process = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=utils.popen_env())

win = tkinter.Toplevel()
tkinter.Label(win, text='正在合并视频文件中,请稍候', font=('times', 20, 'bold')).pack(padx=10, pady=10)
win.resizable(0, 0)
win.after(100, utils.move_to_screen_center, win)

return_code = process.wait()
win.destroy()

if return_code == 0:
if messagebox.askyesno('合并文件成功', '是否打开文件夹?'):
if platform == 'win32':
subprocess.Popen('explorer /select,"{}"'.format(final_mp4_path))
else:
subprocess.Popen(['open', '-R', final_mp4_path])
else:
messagebox.showinfo('合并视频文件错误', process.stdout.read())
def check():
return_code = process.poll()
print('return_code', return_code)
if return_code is None:
win.after(100, check)
return

win.grab_release()
win.destroy()
if return_code == 0:
if messagebox.askyesno('合并文件成功', '是否打开文件夹?'):
if platform == 'win32':
subprocess.Popen('explorer /select,"{}"'.format(final_mp4_path))
else:
subprocess.Popen(['open', '-R', final_mp4_path])
else:
messagebox.showinfo('合并视频文件错误', process.stdout.read())

win.after(100, check)

def on_closing():
if messagebox.askokcancel('警告', '正在合并视频,关闭这个窗口将会中断合并视频'):
process.kill()
win.destroy()

win.protocol("WM_DELETE_WINDOW", on_closing)

win.grab_set()
55 changes: 28 additions & 27 deletions layout_video.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from tkinter import BOTH, Frame as tkFrame, Button as tkButton, LEFT, RIGHT, DISABLED, messagebox as msgbox, LabelFrame, \
StringVar, Label as tkLabel, Entry, Radiobutton, W, X,E
import tkinter
from base_layout import Frame as baseFrame
from diskcache import Cache

Expand All @@ -8,43 +7,45 @@ class Frame(baseFrame):

def __init__(self, root, my_cache) -> None:
super().__init__()
self.layout = layout = LabelFrame(root, text='网络源设置(*为必填)')
layout.pack(fill=BOTH, padx=5, pady=5)
self.layout = layout = tkinter.LabelFrame(root, text='网络源设置(*为必填)')
layout.pack(fill=tkinter.BOTH, padx=5, pady=5)

# 直播源 选择
self.__select = select = StringVar()
self.__select = select = tkinter.StringVar()
my_cache.tkVariable(select, 'video_source_select', '2')
frame = tkFrame(layout)
frame.pack(fill=BOTH)
Radiobutton(frame, text='四季TV视频源(需要台湾IP)', variable=select, value='1').pack(anchor=W)
Radiobutton(frame, text='软件开发者的视频源(每周六晚21点55分左右开启)', variable=select, value='2').pack(
anchor=W)
Radiobutton(frame, text='自填', variable=select, value='3').pack(anchor=W)
frame = tkinter.Frame(layout)
frame.pack(fill=tkinter.BOTH)
tkinter.Radiobutton(frame, text='四季TV视频源(需要台湾IP)', variable=select, value='1').pack(anchor=tkinter.W)
tkinter.Radiobutton(frame, text='软件开发者的视频源(每周六晚21点55分左右开启)', variable=select, value='2').pack(
anchor=tkinter.W)
tkinter.Radiobutton(frame, text='自填', variable=select, value='3').pack(anchor=tkinter.W)
select.trace('w', callback=self.__radio_change)

# 直播源 输入框
self.__video_frame = frame = tkFrame(layout)
self.__video_frame = frame = tkinter.Frame(layout)
frame.pack(fill=tkinter.BOTH, pady=2)

tkLabel(frame, text='直播源(*)', width=8, anchor=E).pack(side=LEFT)
self.__video = StringVar()
tkinter.Label(frame, text='直播源(*)', width=8, anchor=tkinter.E).pack(side=tkinter.LEFT)
self.__video = tkinter.StringVar()
my_cache.tkVariable(self.__video, 'video_url')
Entry(frame, textvariable=self.__video).pack(fill=X, padx=5, expand=True)
tkinter.Entry(frame, textvariable=self.__video).pack(fill=tkinter.X, padx=5, expand=True)

# 弹幕源 输入框
self.__danmaku_frame = frame = tkFrame(layout)
self.__danmaku_frame = frame = tkinter.Frame(layout)
frame.pack(fill=tkinter.BOTH, pady=2)

tkLabel(frame, text='弹幕源', width=8, anchor=E).pack(side=LEFT)
self.__danmaku = StringVar()
tkinter.Label(frame, text='弹幕源', width=8, anchor=tkinter.E).pack(side=tkinter.LEFT)
self.__danmaku = tkinter.StringVar()
my_cache.tkVariable(self.__danmaku, 'damaku_url')
Entry(frame, textvariable=self.__danmaku).pack(fill=X, padx=5, expand=True)
tkinter.Entry(frame, textvariable=self.__danmaku).pack(fill=tkinter.X, padx=5, expand=True)

# 代理 输入框
frame = tkFrame(layout)
frame.pack(fill=BOTH)
tkLabel(frame, text='网络代理', width=8, anchor=E).pack(side=LEFT)
self.__proxy = StringVar()
frame = tkinter.Frame(layout)
frame.pack(fill=tkinter.BOTH, pady=2)
tkinter.Label(frame, text='网络代理', width=8, anchor=tkinter.E).pack(side=tkinter.LEFT)
self.__proxy = tkinter.StringVar()
my_cache.tkVariable(self.__proxy, 'proxy_url')
Entry(frame, textvariable=self.__proxy).pack(fill=X, padx=5, expand=True)
tkinter.Entry(frame, textvariable=self.__proxy).pack(fill=tkinter.X, padx=5, expand=True)

self.__radio_change()

Expand All @@ -54,7 +55,7 @@ def __radio_change(self, *args):
self.__video.set('1')
self.__danmaku.set('')
self.__video_frame.pack_forget()
self.__danmaku_frame.pack(fill=BOTH)
self.__danmaku_frame.pack(fill=tkinter.BOTH, pady=2)

elif select == '2':
self.__video.set('http://home.js2.me:2333/video/live.m3u8')
Expand All @@ -65,8 +66,8 @@ def __radio_change(self, *args):
else:
self.__video.set('')
self.__danmaku.set('')
self.__video_frame.pack(fill=BOTH)
self.__danmaku_frame.pack(fill=BOTH)
self.__video_frame.pack(fill=tkinter.BOTH, pady=2)
self.__danmaku_frame.pack(fill=tkinter.BOTH, pady=2)

def video_url(self) -> str:
return self.__video.get()
Expand Down
10 changes: 6 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
cache.set('m3u8_stop', False)

root = tkinter.Tk()
root.title('综艺玩很大 转播程序 v0.5')
root.title('综艺玩很大 转播程序 v0.6')
# 设置windows窗口图标
if platform == 'win32':
icon = resource_path.path('icon.ico')
Expand All @@ -33,20 +33,20 @@

# 禁止改变窗口大小
root.resizable(False, False)
root.minsize(450, 550)

# 流程开始

menu = menu.Menu(root=root, cache=cache)

local = layout_local.Frame(root=root, my_cache=my_cache)

video = layout_video.Frame(root=root, my_cache=my_cache)

url = layout_url.Frame(root=root)

# buttons = ButtonsFrame(root=root, local_frame=local, video_frame=video, url_frame=url)
buttons = layout_button.Frame(root=root, local_frame=local, video_frame=video, url_frame=url, my_cache=my_cache)

menu = menu.Menu(root=root, cache=cache)

root.after(100, utils.move_to_screen_center, root)


Expand All @@ -61,6 +61,8 @@ def on_closing():

root.protocol("WM_DELETE_WINDOW", on_closing)

root.update()

# 进入消息循环
root.mainloop()
print('退出程序')
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ jinja2
Pillow
pyquery
requests
sanic
sanic
python-socketio
36 changes: 27 additions & 9 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import hashlib
import socket
import subprocess
from sys import platform
import os
import json
from urllib.parse import urlparse

from requests import get


def has_ffmpeg() -> bool:
p = subprocess.Popen('ffmpeg -version', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
msg = ''
for line in p.stdout.readlines():
msg += line.decode()
p.wait()
if platform == 'win32':
p = subprocess.Popen('ffmpeg -version', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
msg = out.decode()
p.terminate()
else:
p = subprocess.Popen('ffmpeg -version', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=popen_env())
out, err = p.communicate()
msg = out.decode()
p.terminate()
return 'ffmpeg version' in msg


Expand Down Expand Up @@ -56,10 +65,13 @@ def is_int(s) -> bool:
def move_to_screen_center(target):
width = target.winfo_screenwidth()
height = target.winfo_screenheight()
x = int((width - target.winfo_reqwidth()) / 2)
y = int((height - target.winfo_reqheight()) / 2)
target.geometry('+{}+{}'.format(x, y))
w = target.winfo_width() + 1
h = target.winfo_height() + 1
x = int((width - w) / 2)
y = int((height - h) / 2)
target.geometry('{}x{}+{}+{}'.format(w, h, x, y))
target.update()
pass


def to_md5(string):
Expand All @@ -71,3 +83,9 @@ def to_md5(string):
m = hashlib.md5()
m.update(string.encode())
return m.hexdigest()


def popen_env()->dict:
env = os.environ.copy()
env['PATH'] = '/usr/local/bin:' + env['PATH']
return env

0 comments on commit 0ec8918

Please sign in to comment.