mirror of
https://github.com/jasons-gh/the-chomsky-index.git
synced 2026-03-11 08:54:36 +00:00
Create base.py
This commit is contained in:
parent
428eae73fd
commit
0f7ddc80ce
1 changed files with 42 additions and 0 deletions
42
base.py
Normal file
42
base.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import sources
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from unidecode import unidecode
|
||||
|
||||
|
||||
# youtube-dl - download the subtitles as .vtt files
|
||||
|
||||
urls_yt = sources.urls_yt()
|
||||
|
||||
for url in urls_yt:
|
||||
subprocess.run(['youtube-dl', '-i', '--skip-download', '--write-auto-sub', '-o%(title)s %(id)s', url])
|
||||
|
||||
|
||||
# ffmpeg - convert them from .vtt to .srt
|
||||
|
||||
for file in [x for x in Path(__file__).parent.glob('**/*.vtt') if x.is_file()]:
|
||||
subprocess.run('ffmpeg.exe -i "' + str(file.name) + '" -- "' + str(file.name[:-4]) + '".srt')
|
||||
|
||||
|
||||
# unidecode - replace some characters if present
|
||||
|
||||
unidecoded_files = set()
|
||||
|
||||
for file in [x for x in Path(__file__).parent.glob('**/*.srt') if x.is_file()]:
|
||||
with open(file, 'r', encoding='utf-8') as file_object:
|
||||
data = file_object.read()
|
||||
for line in data:
|
||||
if line != unidecode(line):
|
||||
data = data.replace(line, unidecode(line))
|
||||
unidecoded_files.add(str(file.name))
|
||||
|
||||
with open(file, 'w', encoding='utf-8') as file_object:
|
||||
file_object.write(data)
|
||||
|
||||
|
||||
# information
|
||||
|
||||
print(str(len(urls_yt)) + ' subtitle files requested')
|
||||
print(str(len([x for x in Path(__file__).parent.glob('**/*.vtt') if x.is_file()])) + ' .vtt subtitle files in this folder')
|
||||
print(str(len([x for x in Path(__file__).parent.glob('**/*.srt') if x.is_file()])) + ' .srt subtitle files in this folder')
|
||||
print(str(len(unidecoded_files)) + ' subtitle files unidecoded')
|
||||
Loading…
Reference in a new issue