2018年12月19日星期三

171108 将Youtube自动翻译字幕转换成srt文件本地播放


Step1
打开YouTube的字幕显示,手动复制到txt文件保存


Step2
将保存的txt程序运用下面代码转换成需要的srt文件,拖拽至视频即可播放


# -*- coding: utf-8 -*-
"""
Created on Wed Nov  8 09:22:22 2017

@author: brucelau
"""
import re
#%% define a function to transform the date format
def time_format(cur):
   time = cur.split(':')
   hour = str(int(time[0])//60)
   minute = str(int(time[0])-int(time[0])//60*60)
   second = time[1]
   return hour+':'+minute+':'+second +',000'    

def txt2srt(filename):
   #%% generate new titles
   num = re.sub("\D", "", filename)
   f1 = open(filename)
   f2 = []
   lines = f1.readlines()
   for idx,time in enumerate(lines):
       if idx%2==0 & idx<len(lines)-4:
           cur = lines[idx]
           try:
               nex = lines[idx+2]
               t1 = time_format(cur).replace('\n','')
               t2 = time_format(nex).replace('\n','')
               t3 = t1+" --> "+t2
               f2.append(int(idx/2+1)) # order number
               f2.append(t3) # time
               f2.append(lines[idx+1]) # titles    
           except IndexError:
               continue
   f1.close()
   #%% save the new titles to .txt file
   srt_name = num + '. '+'Convex Optimization I Lecture '+num+'.srt'
   title3 = open(srt_name,'w')
   title3.writelines(["%s\n" % item  for item in f2])

#%% genertate txt file for saving the titles
#for i in range(19):
#    title3 = open('title'+str(i+1)+'.txt','w')

# 处理多个文件
for i in range(19):
   txtname = 'titles\\title'+str(i+1)+'.txt'
   txt2srt(txtname)
# 处理一个文件
txtname = 'RNN.txt'
txt2srt(txtname)
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
Step3
已整理好,可前往此处下载
http://download.csdn.net/download/qq_33039859/10109206
---------------------
作者:GoHust_Liu

30 条评论:


  1. Move up to Office 365 and get the most recent Office applications, introduces on different PCs and sMacs and gadgets, 1 TB OneDrive distributed storage per client, technical support,
    office.com/setup and different administrations with your membership.

    回复删除

  2. To enact the Norton setup, select the Activate Now option at the base. To recharge the membership for Norton, select the Help choice and snap on Enter item key. Cautiously type the right Norton item key in the clear. Snap on the Next catch.
    norton.com/setup
    Go through with for more details.

    回复删除


  3. Visit
    avg.com/retail and enter avg retail activation code to install and activate your avg antivirus software instantly

    回复删除
  4. With mcafee.com/activate you can prevent devices and network against threats like malware, worms, spyware and runs in the background and does not cause any problem nor slows down the computer.

    回复删除

  5. Microsoft Office install has required the removal of the previously installed version of your Office product on the device or system. Office 365 and other subscription offers the various features, which you do not get when you do not purchase the Office product. The office can be used free, as Microsoft provides the trial versions of every tool.
    office.com/setup visit here.

    回复删除


  6. mcafee antivirus is widely used aantivirus helps to detect and neutralize computer virus, the mail worms,the trojan programs,and also helps your system free of virus and other malware is quite a daily challenge. for more details visit mcafee.com/activate here.

    回复删除

  7. Microsoft Office has numerous projects like MS Word, Excel, Outlook, and so forth. office.com/setup In the wake of finishing the downloading procedure of MS Office, experience the means given beneath and download it on your gadget

    回复删除

  8. Download norton antivirus to make your computer virus free with the best support and tech team.
    norton.com/setup Feel free to contact us

    回复删除

  9. Download Norton Mobile Security and Antivirus application that can norton.com/setup shield your records from getting affected from any online malware or contamination norton setup product key.

    回复删除


  10. If you are getting trouble in your hulu activation code Then you are at the best we will give you a complete guide of setup ing your Hulu Device instantly with out any trouble.
    hulu.com/activate click hulu activate here.

    回复删除
  11. Windows or Mac computers: 123.hp.com/setup and follow the instructions to install and set up the printer for your connection type. note: If you connect the printer USB cable to a Windows computer instead of setting up the connection with the HP driver, in most cases the operating system automatically detects the printer and installs a 'built-in' driver for basic functionality.

    回复删除
  12. If you want to protect all the important data files as well as laptops mcafee.com/activate to get damaged may download McAfee activate for your protection.

    回复删除
  13. ppcoffice it the bundle of office apparatuses to make your working smooth and effective.visit: office.com/setup to downloaded in your PC with the quick help.

    回复删除

  14. office setup is the best programming which is broadly utilized in globe .It is an amazing administration that causes you release your best thoughts, complete things, and remain associated on the go.for more subtleties visit: office.com/setup today.

    回复删除


  15. Mcafee offers you the McAfee activate option to give best Home network protection, mcafee.com/activate Multi-device protection, Web Protection, and Identity Theft.

    回复删除
  16. webroot cyber security is a ultimate internet security suite for complete protection against today's diverse range of threat on windows. key features are 100% secure secure shopping, 1 click virus scanning, malicious website filtering, unblock antivirus.
    webroot.com/safe if you want to install it then visit our site:

    回复删除


  17. Roku gives the least complex approach to stream stimulation to your TV. roku.com/link On your terms. With a large number of accessible channels to look over.

    回复删除

  18. Roku.com/link - Steps to interface your Player to your TV. roku.com/link
    Roku activate gadget is the easiest method to stream stimulation to your TV. visit for roku .

    回复删除

  19. Roku gathers data from devices you use to get to our services
    roku.com/link
    , similar to your IP addresses, device identifiers, search and review history, and other use data.if you want more information about roku link click here.

    回复删除

  20. Norton web security is commonly used antivirus gives the least requesting to use and most intutive affirmation for your PC and your mobiles .present it and negligence viruses,spyware,root-units - , Download norton 360 hackers.
    norton.com/setup
    for more nuances visit.

    回复删除
  21. Get instant help for downloading webroot antivirus to protect your device appoint webroot.com/safe
    where you can find all your problems solved.

    回复删除
  22. webroot is a light weighted software,install extreme digital security at webroot safe or at webroot safe introduce , webroot.com/safe click here to download webroot safe.

    回复删除

  23. norton setup offers a fee-based suite of antivirus products which provide various malware detection method. User can protect their devices by regularly scanning the computer with Norton antivirus. norton.com/setup anti-virus suite uses virus definitions, suspicious behavior, emulation and the sandbox method to detect viruses

    回复删除
  24. McAfee AntiVirus Plus is a smart next gen security for your computer that detects and blocks viruses and malware.
    mcafee.com/activate
    It protects everything on your PC and keeps it safe from viruses, spyware and Trojans.

    回复删除
  25. Activate roku device Follow the Quick Start Guide that accompanied your Roku gadget. For extra help setting up your Roku gadget,
    roku.com/link visit the Setup and Troubleshooting segment of the Roku site given above.

    回复删除

  26. Giving users an unparalleled streaming experience, Team roku.com/link
    takes great pride in being the number one streaming service providers in the world.

    回复删除


  27. roku link this is least problematic approach to manage stream impelling to your TV. On your terms. With a significant number of accessible channels to explore for roku.com/link
    more details.visit: today

    回复删除

  28. Sophos Antivirus provides the most secure and latest services, such as web security, email security and network monitoring, and more. If you have some problems related to harmful bugs, ransomware, or other risks, then using Sophos is the best solution for you. As a result, future customers can now easily access Sophos.com, and install Sophos.
    Activate Sophos

    回复删除
  29. Do you need to increase your credit score?
    Do you intend to upgrade your school grade?
    Do you want to hack your cheating spouse Email, whatsapp, Facebook, instagram or any social network?
    Do you need any information concerning any database.
    Do you need to retrieve deleted files?
    Do you need to clear your criminal records or DMV?
    Do you want to remove any site or link from any blog?
    you should contact this hacker, he is reliable and good at the hack jobs..
    contact : cybergoldenhacker at gmail dot com

    回复删除

  30. I can’t say much but with my experience through divorce, I had no one until I met hackingsetting50@gmail.com online then I contacted him, surprisingly he helped me hack into my partner's phone and all his social media platforms and i can now access everything and even documented and printed stuffs to show as evidence , now I’m happy with my kids and working for Riches. I hope this helps anyone in need.

    Thanks.

    回复删除

注意:只有此博客的成员才能发布评论。

Also Read: