-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
136 lines (130 loc) · 5.08 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import tkinter as tk
import pickle, pandas
from contentFinder import ContentFinder
from multiprocessing import Process, Manager
from downloader import Downloader
from editor import Editor
from poster import Poster
ACCOUNTS = 'accounts.csv'
BLACKLIST = 'savedata/blacklist.pckl'
DOWNLOADQUEUE = 'savedata/downloadQueue.pckl'
EDITQUEUE = 'savedata/editQueue.pckl'
POSTQUEUE = 'savedata/postQueue.pckl'
MANAGER = 'savedata/manager.pckl'
class Application:
def __init__(self):
#create manager
self.manager = Manager()
#load in queues
try:
f = open(DOWNLOADQUEUE, 'rb')
self.downloadQueue = self.manager.list(pickle.load(f))
f.close()
except:
print('Cannot find download queue, creating empty queue!')
self.downloadQueue = self.manager.list()
try:
f = open(EDITQUEUE, 'rb')
self.editQueue = self.manager.list(pickle.load(f))
f.close()
except:
print('Cannot find edit queue, creating empty queue!')
self.editQueue = self.manager.list()
try:
f = open(POSTQUEUE, 'rb')
self.postQueue = self.manager.list(pickle.load(f))
f.close()
except:
print('Cannot find post queue, creating empty queue!')
self.postQueue = self.manager.list()
#load in blacklist
try:
f = open(BLACKLIST, 'rb')
self.blacklist = pickle.load(f)
f.close()
except:
print('Cannot find blacklist, creating empty set!')
self.blacklist = set()
#load in accounts
self.accounts = pandas.read_csv(ACCOUNTS)
#print start state
print('Blacklist: ', self.blacklist)
print('\nDownload Queue: ', self.downloadQueue)
print('\nEdit Queue: ', self.editQueue)
print('\nPost Queue: ', self.postQueue)
#launch backend services
self.downloader = Process(target = Downloader.run, args=(self.downloadQueue, self.editQueue))
self.editor = Process(target=Editor.run, args=(self.editQueue, self.postQueue, self.accounts))
self.poster = Process(target=Poster.run, args=(self.postQueue, self.accounts))
self.downloader.start()
self.editor.start()
self.poster.start()
def mainWindow(self):
#main window with status
window = tk.Tk()
#button selection for accounts to upload to
for i in range(self.accounts.shape[0]):
tk.Button(window, text=f'Get Content for {self.accounts["username"][i]}',\
command=lambda i=i: self.getContent(self.accounts['username'][i], self.accounts['search'][i])).pack()
window.mainloop()
return
def getContent(self, username, searchterms):
#fetch video
content = ContentFinder.query(searchterms, self.blacklist)
#confirmation window
root = tk.Tk()
tk.Label(root, text = f'Found video:\n\
Title: {content["title"]}\n\
Duration: {content["duration"]}\n\
Would you like to use the video? (enter max parts below)').pack()
tk.Label(root, text='New Title:').pack()
t = tk.StringVar(root, content['title'])
tk.Entry(root, textvariable=t).pack()
tk.Label(root, text='Max Parts:').pack()
parts = tk.StringVar(root)
tk.Entry(root, textvariable=parts).pack()
tk.Label(root, text='Part Length (seconds):').pack()
partLen = tk.StringVar(root, 60)
tk.Entry(root, textvariable=partLen).pack()
def no():
self.blacklist.add(content['id'])
root.destroy()
def yes(t, parts, partLen):
try:
maxParts = int(parts.get())
except:
maxParts = 5
try:
partLength = int(partLen.get())
except:
partLength = 60
downloadJob = {'username':username, 'id':content['id'], 'title':t.get(), 'maxParts':maxParts, 'partLength':partLength}
print('Added Job to Download Queue: ', downloadJob)
self.downloadQueue.append(downloadJob)
root.destroy()
tk.Button(root, text='no (add to blacklist)', command=no).pack()
tk.Button(root, text='yes (add to download queue)', command=lambda:yes(t, parts, partLen)).pack()
root.mainloop()
def __del__(self):
#terminate processes
self.downloader.terminate()
self.editor.terminate()
self.poster.terminate()
#save blacklist
f = open(BLACKLIST, 'wb')
pickle.dump(self.blacklist, f)
f.close()
#save queues
f = open(DOWNLOADQUEUE, 'wb')
pickle.dump(list(self.downloadQueue), f)
f.close()
f = open(EDITQUEUE, 'wb')
pickle.dump(list(self.editQueue), f)
f.close()
f = open(POSTQUEUE, 'wb')
pickle.dump(list(self.postQueue), f)
f.close()
if __name__ == "__main__":
app = Application()
app.mainWindow()
del app