Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- from tkinter import *
- def main():
- inputTimeCodes = timecodes.get("1.0","end-1c")
- TimeCodes = inputTimeCodes.splitlines()
- if '### стрим' not in TimeCodes[0]:
- print ('ERROR')
- lc3 = Label(root, bg="#ff3737", text='В первой строчке введите текст в формате "### стрим N - №a,b..."')
- lc3.grid(row=4, columnspan=2)
- nname = TimeCodes[0].replace('### стрим', '').replace(' ', '')
- nname = nname.split('-')
- print ('nname', nname)
- nomerStrima = nname[0]
- zadaniaStrima = nname[1]
- TimeCodes.pop(0)
- count = -1
- for i in TimeCodes:
- count += 1
- if '№' in i:
- number = True
- else:
- number = False
- print ('//////////////////')
- print ('[log] count =', count)
- print ('[log] number =', number)
- # print ('//////////////////')
- if 'youtube.com' in TimeCodes[0] or 'youtu.be' in TimeCodes[0]:
- url = TimeCodes[0]
- else:
- print('Введите ссылку во второй строке, затем новой строчке введите таймкоды')
- url = False
- TimeCodes.pop(0)
- finalRes = ''
- if url != False:
- lc = Label(root, bg="#32ff1c", text="Успех! Найдено " + str(count) + " фрагментов для скачивания")
- else:
- lc = Label(root, bg="#ff3737", text='Введите ссылку в первой строке, затем новой строчке введите таймкоды')
- lc.grid(row=4, columnspan=2)
- d1 = 0
- d2 = 0
- d3 = 0
- z = 0
- for i in TimeCodes:
- timecd = i
- if timecd[1] == ' ':
- n = timecd[0]
- timecd = timecd[1:]
- timecd = timecd[1:]
- elif timecd[1] != ' ':
- n = str(timecd[0]) + str(timecd[1])
- timecd = timecd[1:]
- timecd = timecd[1:]
- timecd = timecd[1:]
- z += 1
- if number == False:
- timecd = timecd.replace(' ', '').split('-')
- begin = timecd[0]
- end = timecd[1]
- begin = begin.split(':')
- end = end.split(':')
- duration = datetime.timedelta(hours=int(end[0]), minutes=int(end[1]), seconds=int(end[2])) - datetime.timedelta(hours=int(begin[0]), minutes=int(begin[1]), seconds=int(begin[2]))
- if z == count:
- q1 = int(end[0])*60*60
- q2 = int(end[1])*60
- q3 = int(end[2])
- res1 = str('ffmpeg -ss ')
- res2 = str(begin[0])
- res3 = str(':')
- res4 = str(begin[1])
- res5 = str(':')
- res6 = str(begin[2])
- res7 = str(' -i $(youtube-dl -f 22 -g "')
- res8 = str(url)
- res9 = str('") -t ')
- res10 = str(duration)
- res11 = str(' -c:v copy -c:a copy ')
- res12 = str(n)
- res13 = str('.mp4')
- dur = int(res10.split(':'))
- d1 += int(dur[0])
- d2 += int(dur[1])
- d3 += int(dur[2])
- res = res1+res2+res3+res4+res5+res6+res7+res8+res9+res10+res11+res12+res13
- finalRes = finalRes + res + ' && '
- else:
- timecd = timecd.replace(' ', '').split('-')
- begin = timecd[0]
- nend = timecd[1]
- nend = nend.replace('(', '').replace(')', '').split('№')
- end = nend[0]
- zadanie = nend[1]
- begin = begin.split(':')
- end = end.split(':')
- duration = datetime.timedelta(hours=int(end[0]), minutes=int(end[1]), seconds=int(end[2])) - datetime.timedelta(hours=int(begin[0]), minutes=int(begin[1]), seconds=int(begin[2]))
- if z == count:
- q1 = int(end[0])*60*60
- q2 = int(end[1])*60
- q3 = int(end[2])
- res1 = str('ffmpeg -ss ')
- res2 = str(begin[0])
- res3 = str(':')
- res4 = str(begin[1])
- res5 = str(':')
- res6 = str(begin[2])
- res7 = str(' -i $(youtube-dl -f 22 -g "')
- res8 = str(url)
- res9 = str('") -t ')
- res10 = str(duration)
- res11 = str(' -c:v copy -c:a copy ')
- res12 = str(n)
- res13 = str('_№')
- res14 = str(zadanie)
- res15 = str('.mp4')
- dur = res10.split(':')
- d1 += int(dur[0])
- d2 += int(dur[1])
- d3 += int(dur[2])
- res = res1+res2+res3+res4+res5+res6+res7+res8+res9+res10+res11+res12+res13+res14+res15
- finalRes = finalRes + res + ' && '
- d1 = d1*60*60
- d2 = d2*60
- d = d1+d2+d3
- q = q1+q2+q3
- finalRes = finalRes[:-4]
- kkpd = int((d/q)*100)
- # kpdStr = 'КПД стрима = ' + str(kkpd) + ' %'
- kpdStr = 'КПД стрима = ' + str(kkpd) + '%'
- print (kpdStr)
- print ('//////////////////')
- whywhat = '"'
- nameFolder = whywhat + nomerStrima + ' (' + zadaniaStrima + ') - ' + str(kkpd) + '%' + whywhat + ' && '
- createFolder = 'mkdir ' + nameFolder
- gotoFolder = 'cd ' + nameFolder
- finalRes = createFolder + gotoFolder + finalRes
- print (finalRes)
- lc2 = Label(root, bg="#9099C1", text=kpdStr)
- lc2.grid(row=5, columnspan=2)
- def about():
- root2 = Toplevel(root)
- Labl1 = Label(root2, font="Times 15", text="Программа, созданная для помощи при скачивании определенных моментов из видео без полной их загрузки.").pack()
- Labl2 = Label(root2, font="Times 15", text="Полученный результат выводится в консоль.").pack()
- Labl3 = Label(root2, font="Times 15", text="Необходимо его скопировать и вставить в эту же консоль.").pack()
- Labl4 = Label(root2, font="Times 15", text="Для скачивания потребуются бесплатные ffmpeg и youtube-dl.").pack()
- Labl5 = Label(root2, font="Times 15", text="").pack()
- Labl6 = Label(root2, font="Times 15", text="Пример ввода данных в программу:").pack()
- Labl7 = Label(root2, font="Courier 14", fg="#686868", text="https://www.youtube.com/watch?v=jtTOVmx_PsE").pack()
- Labl8 = Label(root2, font="Courier 14", fg="#686868", text="1 00:09:48 - 00:14:45").pack()
- Labl9 = Label(root2, font="Courier 14", fg="#686868", text="2 00:15:05 - 00:20:14").pack()
- Labl10 = Label(root2, font="Times 15", text="").pack()
- Labl11 = Label(root2, font="Times 15", text="Пример вывода данных:").pack()
- Labl12 = Label(root2, font="Courier 9", fg="#686868", text='ffmpeg -ss 00:09:48 -i $(youtube-dl -f 22 -g "https://www.youtube.com/watch?v=jtTOVmx_PsE") -t 0:04:57 -c:v copy -c:a copy 1.mp4 && ffmpeg -ss 00:15:05 -i $(youtube-dl -f 22 -g "https://www.youtube.com/watch?v=jtTOVmx_PsE") -t 0:05:09 -c:v copy -c:a copy 2.mp4').pack()
- root2.mainloop()
- root = Tk()
- root.title("youtube download desired time interval")
- timecodes = Text(root, width=50, height=20)
- timecodes.grid(row=3, columnspan=2)
- l1 = Label(root, text="url").grid(row=0, columnspan=2)
- l2 = Label(root, text="n 00:00:00 - 01:02:03").grid(row=2, columnspan=2)
- button = Button(root, text="Конвертировать", command=lambda: main()).grid(row=6, column=0)
- button = Button(root, text="?", bg="#b64949", fg="white", command=lambda: about()).grid(row=6, column=1)
- root.resizable(False, False)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement