0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

youtubeから出力したsrtファイルを結合

Last updated at Posted at 2021-06-17

srtフォルダにsrtファイルを置いてください。

この記事でsrtファイルが作れます。
https://qiita.com/saber72237/items/a62f2c035a8df820f987

srtフォルダに置いたsrtファイルが結合されて一つのテキストファイルで出力されます。

srt.py
from bs4 import BeautifulSoup
import urllib.request
import re
from time import sleep
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import csv
import time
import datetime
import pandas as pd
from selenium.webdriver.common.action_chains import ActionChains
import glob

now = datetime.datetime.now()
filename = now.strftime('%Y%m%d_%H%M%S') + '.txt'
fa = open(filename,'a', encoding='cp932',errors='ignore')

for file in glob.glob('srt/*.srt'):
    with open(file, mode='rt', encoding='utf-8')  as f:
        for line in f:
            
            list=re.sub('\d{2}:\d{2}:\d{2}.+', '', line)
            list=re.sub('^\d+$', '', list)
            print(list.strip())
            fa.write(list.strip())

f.close()
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?