-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_check_data.py
More file actions
288 lines (246 loc) · 14.6 KB
/
Python_check_data.py
File metadata and controls
288 lines (246 loc) · 14.6 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#Так, тут не обычная ситуация, так как с какой стороны я не посмотрел, лучшее звонить в exe файл
#Почему будем звонить в exe файл? А что если пользователь захочет перегестрировать пользователя,
#Вроде можно здесь оставить код, но тогда как узнать когда пользователь захочет поменять пользователя?
#Можно куча выходов найти, но по мне оставить exe более чем элегатный ход, ведь его может и пользователь открыть и наткнутся на html doc
#Тут лишь проверка пользователя
import json
import os
import sys
import httplib2
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from googleapiclient.http import MediaFileUpload
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import argparser, run_flow
#Хер знает что это такое, оно было в коде, вдруг влияет на что-то...
httplib2.RETRIES = 1
MAX_RETRIES = 10
RETRIABLE_EXCEPTIONS = (httplib2.HttpLib2Error, IOError)
RETRIABLE_STATUS_CODES = [500, 502, 503, 504]
def __file_extension(path, file_endswith = ".mp4"):
'Если есть хоть один файл, определённого пути, то функция возврощает 1'
path_file = ""
for root, _, files in os.walk(path):
for file in files:
if(file.endswith(file_endswith) == True):
return 1
return 0
def __find_file(path, search_file, file_endswith = ".exe"):
'Ищет файл с определёным именим и расширением в определёном пути'
path_file = ""
for root, _, files in os.walk(path):
for file in files:
if(file.endswith(file_endswith) == True):
if(file == search_file):
path_file = os.path.join(root, file).replace("\\","/")
return path_file
def __find_file_global(search_file = "ffmpeg.exe"):
'Ищет на уровень ниже определёный файл, более глобальный поиск'
path_execute_prog = os.path.abspath(os.getcwd())
path_file = __find_file(path_execute_prog, search_file)
if(path_file == ""):
path_execute_prog = os.path.abspath(os.path.dirname('../'))
path_file = __find_file(path_execute_prog, search_file) #Ищем отчайно на уровень выше это может потребовать больше времени
return path_file
def CheckVideo(path_video, file_endswith = ".mp4"):
'Возврощает True, если в папки есть хоть один видео файл'
return __file_extension(path_video)
def CheckSound(path_video, file_endswith = ".mp3"):
'Возврощает True, если в папки есть хоть один звукувой файл'
return __file_extension(path_video)
def CheckFfmpegFfprobe():
'Возврощает True, если в папке есть ffmpeg.exe и ffprobe.exe'
path_ffmpeg = __find_file_global("ffmpeg.exe")
path_ffprobe = __find_file_global("ffprobe.exe")
if(path_ffmpeg == ""):
return 0
if(path_ffprobe == ""):
return 0
return 1
def TestConnectionGoogleApi(CLIENT_SECRETS_FILE, YOUTUBE_UPLOAD_SCOPE = "https://www.googleapis.com/auth/youtube.upload", test_google = True):
'Возврощает True, если пользователь зарегестрирован на Google Api'
if(test_google == False):
return -1
flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE, scope=YOUTUBE_UPLOAD_SCOPE)
storage = Storage("%s-oauth2.json" % sys.argv[0])
credentials = storage.get()
if credentials is None or credentials.invalid:
return 0
return 1
def CheckFolderStruct(ifNotCreate=False):
'Проверяет структуру папок, может их создать либо выдать ошибку, при завершение в хорошем случае выдаёт True'
path_data = "data"
path_cache = "data/cache"
path_temp = "data/cache/Temp"
path_output = "output"
path_video = "data/video"
if(os.path.exists(path_data) == False):
if(ifNotCreate == True): os.mkdir(path_data)
else: return 0
if(os.path.exists(path_cache) == False):
if(ifNotCreate == True): os.mkdir(path_cache)
else: return 0
if(os.path.exists(path_temp) == False):
if(ifNotCreate == True): os.mkdir(path_temp)
else: return 0
if(os.path.exists(path_output) == False):
if(ifNotCreate == True): os.mkdir(path_output)
else: return 0
if(os.path.exists(path_video) == False):
if(ifNotCreate == True): os.mkdir(path_video)
else: return 0
return 1
#Опасно проверять ключ, а тратить квоты для проверки, мне кажется не разумным, поэтому оставим на совести пользоваетля
def CheckConnectionYoutubeApi(DEVELOPER_KEY, gadalka_mode = False):
'Возврощает True, если есть подключение к Youtube Api. \nКрайне не желательная функция так как тратит квоту для проверки.\nТакже есть режим гадалка, который догадывается ключ это или нет'
if(gadalka_mode == False):
youtube = build("youtube", "v3", developerKey = DEVELOPER_KEY)
request = youtube.videos().list(
part="contentDetails",
id="jNQXAC9IVRw"
)
error = 1
try:
response_video = request.execute()
except:
error = 0
return error
if(gadalka_mode == True):
error = 1
if(len(DEVELOPER_KEY) <= 10): #Проверяем длину обычно ключ длиный...
error = 0
return error
def CheckJsonFile(check_client_secrets = True, check_video_data = True, check_youtube_data = True):
'Возврощает True, если json файлы существуют'
error = 1
if(check_client_secrets == True):
error *= os.path.isfile("data/client_secrets.json")
if(check_video_data == True):
error *= os.path.isfile("data/video_data.json")
if(check_youtube_data == True):
error *= os.path.isfile("data/youtube_data.json")
return error
def CheckAllPrintText(check_google = True, youtubeApi_gadalka=False, youtube_api_key = "", path_client_secrets="", path_sound="", type_sound_format=".mp3", path_video="", type_video_format=".mp4"):
'Безопасная функция, проверяет все пункты для рендера, возрощает массив\n Где первый элемент, это строки для вывода в консоль, второй элемент массива это словарь с \n\n(1) - успешным подключением\n(0) - не успешным подключением\n(-1) - не удавшемся проверка чаще всего по вине программиста'
text_output = ""
array_check_list = {}
return_array_all = []
#Интернет проверки
check_youtube_api = 0
check_google_api = 0
#Обычные проверки
check_video_file = 0
check_sound_file = 0
check_folder_struct = 0
check_ffmpeg_file = 0
check_json_file = 0
try:
check_folder_struct = CheckFolderStruct(True)
except:
check_folder_struct = -1
try:
check_ffmpeg_file = CheckFfmpegFfprobe()
except:
check_ffmpeg_file = -1
try:
check_sound_file = CheckSound(path_sound, type_sound_format)
except:
check_sound_file = -1
try:
check_video_file = CheckVideo(path_video, type_video_format)
except:
check_video_file = -1
try:
check_json_file = CheckJsonFile()
except:
check_json_file = -1
try:
check_youtube_api = CheckConnectionYoutubeApi(youtube_api_key, youtubeApi_gadalka)
except:
check_youtube_api = -1
try:
check_google_api = TestConnectionGoogleApi(path_client_secrets, "https://www.googleapis.com/auth/youtube.upload", check_google)
except:
check_google_api = -1
if(check_youtube_api == 1):
text_output += "✓ - Подключение к youtube успешное\n"
elif(check_youtube_api == -1):
text_output += "? - Подключение к youtube не известно\n"
else:
text_output += "✖ - Не удалось подключится к youtube успешно\n"
if(check_google_api == 1):
text_output += "✓ - Подключение к google успешное\n"
elif(check_google_api == -1):
text_output += "? - Подключение к google не известно\n"
else:
text_output += "✖ - Не удалось подключится к google успешно\n"
#Проверяем обязательную информацию
if(check_folder_struct == 1):
text_output += "✓ - Структура папок правильная\n"
elif(check_folder_struct == -1):
text_output += "? - Структура папок не известно\n"
else:
text_output += "✖ - Структура папок не правильная\n"
if(check_ffmpeg_file == 1):
text_output += "✓ - файлы ffmpeg.exe и ffprobe.exe существуют\n"
elif(check_ffmpeg_file == -1):
text_output += "? - файлы ffmpeg.exe и ffprobe.exe не известно\n"
else:
text_output += "✖ - файлы ffmpeg.exe и ffprobe.exe не существует\n"
if(check_sound_file == 1):
text_output += "✓ - файлы звука существуют\n"
elif(check_sound_file == -1):
text_output += "? - файлы звука не известны\n"
else:
text_output += "✖ - файлы звука не существуют\n"
if(check_video_file == 1):
text_output += "✓ - файлы видео существуют\n"
elif(check_video_file == -1):
text_output += "? - файлы видео не известны\n"
else:
text_output += "✖ - файлы видео не существуют\n"
if(check_json_file == 1):
text_output += "✓ - файлы json существуют\n"
elif(check_json_file == -1):
text_output += "? - файлы json не известны\n"
else:
text_output += "✖ - файлы json не существуют\n"
array_check_list = {
"video": check_video_file,
"sound": check_sound_file,
"struct_folder": check_folder_struct,
"ffmpeg_ffprobe": check_ffmpeg_file,
"json": check_json_file,
"youtube_api": check_youtube_api,
"google_api": check_google_api
}
return_array_all.append(text_output)
return_array_all.append(array_check_list)
return return_array_all
#здесь я напишу код, условия соглашения, если код выполнился успешно
from tkinter import *
from tkinter import scrolledtext
def checkda():
text_use = """Вы соглашаетесь с правилами использование этой программы, а именно:
1. Сразу после регестрации и первого успешного выпуска видео на канал, программа не выдаст вам не единного уведомления, даже если в программе произодёт критический сбой она не выдаст никакого сигнала. Такова политика великого создателя Влад икей dalV, то-есть for_example, готов фитом с моргерштерном, в любом случае вы можете просто проверять папки на добавление файлов в программе и делать, то что вы хотите\n
2. Программа имеет права распорежатся ресурсами компа, каждый день, по несколько часов в день (примерное использование ресурсов 1 часовой ролик - 1-2 час рендера 35% - CPU, 700MB - RAM\n
3. В принцепи из-за чего всё это право, то писал, я не несу отвестности, за то что эта программа нанесёт вред - пользователю, организации, компании, учебному заведению и тд... Эту программу можно использовать как так называемый - "Майнер" и использовать в злых намерниях, автор не одобряет такого поведение и если вы провохранительные органы, то не ищите меня, пожалуйста, а если найдете, то возьмите меня работать как того хакера, Славика\n
4. Программа не пересылает не куда данные кроме как в Google и обращение к Youtube, данные работает у вас локально, я не имею никакого контакта к вам, вы лишь доверяете политики Google и YouTube\n
@All rights dalV
"""
backround_color = "F0F0F0"
bg_text = "6B8FD4"
fg_text = "000000"
bg_button = "6B8FD4"
fg_button = "FFE573"
root = Tk()
root.geometry("700x400")
root["bg"] = "#"+backround_color
text = scrolledtext.ScrolledText(width=100, height=11, bg="#"+bg_text, fg="#"+fg_text)
text.insert('1.0', text_use)
text['state'] = 'disabled'
text.place(relx=0, relwidth=1, y=0)
button = Button(root, text="Я согласен", font=("Arial Bold", 30), bg="#"+bg_button, fg="#"+fg_button)
button.place(relx=0.5, y=300, anchor="c", bordermode=OUTSIDE)
root.mainloop()