Advertisement
llirik

ytdl-time-interval

Sep 27th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.98 KB | None | 0 0
  1. import datetime
  2. from tkinter import *
  3.  
  4.  
  5. def main():
  6.  
  7.     inputTimeCodes = timecodes.get("1.0","end-1c")
  8.     TimeCodes = inputTimeCodes.splitlines()
  9.  
  10.     if '### стрим' not in TimeCodes[0]:
  11.         print ('ERROR')
  12.         lc3 = Label(root, bg="#ff3737", text='В первой строчке введите текст в формате "### стрим N - №a,b..."')
  13.         lc3.grid(row=4, columnspan=2)
  14.     nname = TimeCodes[0].replace('### стрим', '').replace(' ', '')
  15.     nname = nname.split('-')
  16.     print ('nname', nname)
  17.     nomerStrima = nname[0]
  18.     zadaniaStrima = nname[1]
  19.     TimeCodes.pop(0)
  20.     count = -1
  21.     for i in TimeCodes:
  22.         count += 1
  23.         if '№' in i:
  24.             number = True
  25.         else:
  26.             number = False
  27.     print ('//////////////////')
  28.     print ('[log] count =', count)
  29.     print ('[log] number =', number)
  30.     # print ('//////////////////')
  31.     if 'youtube.com' in TimeCodes[0] or 'youtu.be' in TimeCodes[0]:
  32.         url = TimeCodes[0]
  33.     else:
  34.         print('Введите ссылку во второй строке, затем новой строчке введите таймкоды')
  35.         url = False
  36.     TimeCodes.pop(0)
  37.     finalRes = ''
  38.  
  39.     if url != False:
  40.         lc = Label(root, bg="#32ff1c", text="Успех! Найдено " + str(count) + " фрагментов для скачивания")
  41.     else:
  42.         lc = Label(root, bg="#ff3737", text='Введите ссылку в первой строке, затем новой строчке введите таймкоды')
  43.     lc.grid(row=4, columnspan=2)
  44.  
  45.     d1 = 0
  46.     d2 = 0
  47.     d3 = 0
  48.     z = 0
  49.     for i in TimeCodes:
  50.         timecd = i
  51.         if timecd[1] == ' ':
  52.             n = timecd[0]
  53.             timecd = timecd[1:]
  54.             timecd = timecd[1:]
  55.         elif timecd[1] != ' ':
  56.             n = str(timecd[0]) + str(timecd[1])
  57.             timecd = timecd[1:]
  58.             timecd = timecd[1:]
  59.             timecd = timecd[1:]
  60.         z += 1
  61.         if number == False:
  62.             timecd = timecd.replace(' ', '').split('-')
  63.             begin = timecd[0]
  64.             end = timecd[1]
  65.  
  66.             begin = begin.split(':')
  67.             end = end.split(':')
  68.  
  69.             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])) 
  70.  
  71.             if z == count:
  72.                 q1 = int(end[0])*60*60
  73.                 q2 = int(end[1])*60
  74.                 q3 = int(end[2])
  75.  
  76.             res1 = str('ffmpeg -ss ')
  77.             res2 = str(begin[0])
  78.             res3 = str(':')
  79.             res4 = str(begin[1])
  80.             res5 = str(':')
  81.             res6 = str(begin[2])
  82.             res7 = str(' -i $(youtube-dl -f 22 -g "')
  83.             res8 = str(url)
  84.             res9 = str('") -t ')
  85.             res10 = str(duration)
  86.             res11 = str(' -c:v copy -c:a copy ')
  87.             res12 = str(n)
  88.             res13 = str('.mp4')
  89.  
  90.             dur = int(res10.split(':'))
  91.            
  92.             d1 += int(dur[0])
  93.             d2 += int(dur[1])
  94.             d3 += int(dur[2])
  95.  
  96.             res = res1+res2+res3+res4+res5+res6+res7+res8+res9+res10+res11+res12+res13
  97.  
  98.             finalRes = finalRes + res + ' && '
  99.         else:
  100.            
  101.             timecd = timecd.replace(' ', '').split('-')
  102.             begin = timecd[0]
  103.             nend = timecd[1]
  104.             nend = nend.replace('(', '').replace(')', '').split('№')
  105.             end = nend[0]
  106.             zadanie = nend[1]
  107.  
  108.  
  109.             begin = begin.split(':')
  110.             end = end.split(':')
  111.  
  112.             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]))
  113.            
  114.             if z == count:
  115.                 q1 = int(end[0])*60*60
  116.                 q2 = int(end[1])*60
  117.                 q3 = int(end[2])
  118.  
  119.             res1 = str('ffmpeg -ss ')
  120.             res2 = str(begin[0])
  121.             res3 = str(':')
  122.             res4 = str(begin[1])
  123.             res5 = str(':')
  124.             res6 = str(begin[2])
  125.             res7 = str(' -i $(youtube-dl -f 22 -g "')
  126.             res8 = str(url)
  127.             res9 = str('") -t ')
  128.             res10 = str(duration)
  129.             res11 = str(' -c:v copy -c:a copy ')
  130.             res12 = str(n)
  131.             res13 = str('_№')
  132.             res14 = str(zadanie)
  133.             res15 = str('.mp4')
  134.  
  135.             dur = res10.split(':')
  136.            
  137.             d1 += int(dur[0])
  138.             d2 += int(dur[1])
  139.             d3 += int(dur[2])
  140.  
  141.             res = res1+res2+res3+res4+res5+res6+res7+res8+res9+res10+res11+res12+res13+res14+res15
  142.  
  143.             finalRes = finalRes + res + ' && ' 
  144.  
  145.     d1 = d1*60*60
  146.     d2 = d2*60
  147.     d = d1+d2+d3   
  148.     q = q1+q2+q3
  149.     finalRes = finalRes[:-4]
  150.     kkpd = int((d/q)*100)
  151.     # kpdStr = 'КПД стрима = ' + str(kkpd) + ' %'
  152.     kpdStr = 'КПД стрима = ' + str(kkpd) + '%'
  153.     print (kpdStr)
  154.     print ('//////////////////')
  155.     whywhat = '"'
  156.     nameFolder = whywhat + nomerStrima + ' (' + zadaniaStrima + ') - ' + str(kkpd) + '%' + whywhat + ' && '
  157.     createFolder = 'mkdir ' + nameFolder
  158.     gotoFolder = 'cd ' + nameFolder
  159.     finalRes = createFolder + gotoFolder + finalRes
  160.     print (finalRes)
  161.  
  162.     lc2 = Label(root, bg="#9099C1", text=kpdStr)
  163.     lc2.grid(row=5, columnspan=2)
  164.  
  165.  
  166. def about():
  167.     root2 = Toplevel(root)
  168.     Labl1 = Label(root2, font="Times 15", text="Программа, созданная для помощи при скачивании определенных моментов из видео без полной их загрузки.").pack()
  169.     Labl2 = Label(root2, font="Times 15", text="Полученный результат выводится в консоль.").pack()
  170.     Labl3 = Label(root2, font="Times 15", text="Необходимо его скопировать и вставить в эту же консоль.").pack()
  171.     Labl4 = Label(root2, font="Times 15", text="Для скачивания потребуются бесплатные ffmpeg и youtube-dl.").pack()
  172.     Labl5 = Label(root2, font="Times 15", text="").pack()
  173.     Labl6 = Label(root2, font="Times 15", text="Пример ввода данных в программу:").pack()
  174.     Labl7 = Label(root2, font="Courier 14", fg="#686868", text="https://www.youtube.com/watch?v=jtTOVmx_PsE").pack()
  175.     Labl8 = Label(root2, font="Courier 14", fg="#686868", text="1 00:09:48 - 00:14:45").pack()
  176.     Labl9 = Label(root2, font="Courier 14", fg="#686868", text="2 00:15:05 - 00:20:14").pack()
  177.     Labl10 = Label(root2, font="Times 15", text="").pack()
  178.     Labl11 = Label(root2, font="Times 15", text="Пример вывода данных:").pack()
  179.     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()
  180.  
  181.  
  182.  
  183.  
  184.     root2.mainloop()
  185.  
  186. root = Tk()
  187. root.title("youtube download desired time interval")
  188.  
  189. timecodes = Text(root, width=50, height=20)
  190. timecodes.grid(row=3, columnspan=2)
  191.  
  192. l1 = Label(root, text="url").grid(row=0, columnspan=2)
  193. l2 = Label(root, text="n 00:00:00 - 01:02:03").grid(row=2, columnspan=2)
  194.  
  195.  
  196. button = Button(root, text="Конвертировать", command=lambda: main()).grid(row=6, column=0)
  197. button = Button(root, text="?", bg="#b64949", fg="white", command=lambda: about()).grid(row=6, column=1)
  198. root.resizable(False, False)
  199. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement