-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
126 lines (103 loc) · 4.06 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
import database as db
import youtube as yt
import Tkinter as tk
import ttk
import webbrowser
import math
YT_KEY = 'AI39si5Hoj2If4u1UHi0FuPGJVLEhEvpku1Aox01MSs23PHQObHuLrkhS7qsdJrIDS_cfkT4ZrhOzDbbh_a6377FP8b1Ykcu3A'
class VideoObject:
title, date, url, viewed = '', '', '', False
def __init__(self, title, date, url):
self.title = title
self.date = date
self.url = url
class VideoControl(tk.Frame):
def __init__(self, video, master=None):
tk.Frame.__init__(self, master)
#self.grid(sticky=tk.W)
self.see = tk.Button(self, text=video.title)
self.see.grid(row=0,column=0,sticky=tk.W)
class ChannelTab(ttk.Frame):
text, videos, controls, actualPage = '', [], [], 1
def __init__(self, channel, videos, master=None):
ttk.Frame.__init__(self, master)
self.text = channel
self.setVideos(videos)
self.grid(row=0,column=0,sticky=tk.W)
self.previous=tk.Button(self, text='<', command=self.draw(self.actualpage - 1))
self.previous.grid(row=1, column=1, stick=tk.W)
self.next=tk.Button(self, text='<', command=self.draw(self.actualpage - 1))
self.next.grid(row=1, column=1, stick=tk.W)
def setVideos(self, videos):
self.videos = videos
for video in self.videos:
self.controls.append(VideoControl(video))
self.draw()
def draw(self, page=1):
if page in range(1,int(math.ceil(len(self.videos) / 25.0))):
for control in self.controls[((page-1)*25):(page*25)]:
control.grid(sticky=tk.W)
self.actualPage = page
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid(sticky=tk.N+tk.S+tk.E+tk.W)
self.createWidgets()
def createWidgets(self):
top=self.winfo_toplevel()
#Adding channels panel
self.channel = tk.Entry(self)
self.channel.grid(row=0, column=0, stick=tk.W)
self.add = tk.Button(self, text='Add', command=self.addChannel)
self.add.grid(row=0, column=1, stick=tk.W)
self.quit = tk.Button(self, text='Close', command=top.destroy)
self.quit.grid(row=0, column=2, stick=tk.E)
#Show added channels panel
self.tabs = ttk.Notebook(self)
self.tabs.grid(row=1, column=0, stick=tk.W)
self.frames = []
for key in lista.keys():
self.frames.append(ChannelTab(key, lista[key], self.tabs))
self.tabs.add(self.frames[-1], text=key)
def addChannel(self):
print(self.channel.get())
saveEntryResults(self.channel.get(), yt_service)
self.channel.delete(0, tk.END)
#------------------------------------------------------------------------
def entryToVideoObject(entry):
return VideoObject(entry.media.title.text,
entry.published.text,
entry.media.player.url)
def addToList(channel, video):
result = True
if lista.has_key(channel):
result = videoExists(video, lista[channel])
if not result:
lista[channel].append(video)
else:
lista[channel] = [video]
def videoExists(video, videos):
result = False
for item in videos:
result = (video.url == item.url)
if result: break
def printEntryDetails(entry):
print 'Video title: %s - %s - %s' % entry.media.title.text % entry.published.text % entry.media.player.url
def saveEntryResults(channel, yt_service, index=1):
entries = yt_service.getUserUploads(channel, index)
if entries:
for entry in entries:
if not addToList(channel, entryToVideoObject(entry)):
more = False
break
if more:
saveEntryResults(channel, yt_service, index+50)
db.saveDB(lista)
if __name__ == '__main__':
yt_service = yt.MyYouTubeService(YT_KEY)
lista = db.loadDB()
for key in lista.keys():
saveEntryResults(key, yt_service)
app = Application()
app.master.title('YTperUploader')
app.mainloop()