forked from csev/py4e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.py
More file actions
67 lines (56 loc) · 1.69 KB
/
check.py
File metadata and controls
67 lines (56 loc) · 1.69 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# https://pypi.org/project/python-youtube/
import math
import json
import hashlib
import sys
import os
from youtube_transcript_api import YouTubeTranscriptApi
from pyyoutube import Api
import util
import string
if len(sys.argv) != 2 :
print('Please add the language')
quit()
language = sys.argv[1]
if not os.path.isdir(language) :
print("Missing folder for", language)
quit()
newsrts = list()
updates = list()
same = 0
for filename in os.listdir(language):
f = os.path.join(language, filename)
# checking if it is a file
if f.find('_index.json') >= 0 : continue
if not os.path.isfile(f) : continue
videoId = util.get_videoid(f)
if len(videoId) < 5 : continue
filestr = open(f).read()
filemd = util.hash_srt(filestr)
try:
captions = YouTubeTranscriptApi.get_transcript(videoId, languages=[language])
# print(captions)
except:
newsrts.append(f)
continue
output = util.caption2srt(captions)
ymd = util.hash_srt(output)
if ymd == filemd :
same = same + 1
print('.', end='', flush=True)
continue
# {'text': 'Hello everybody and welcome to chapter', 'start': 0.0, 'duration': 1.89}
# {'text': "one of Python for Everybody. I'm Charles", 'start': 1.89, 'duration': 1.92}
updates.append(f)
print()
print('Unchanged', same)
for filename in newsrts:
print('NEW', filename)
videoId = util.get_videoid(filename)
print('open https://studio.youtube.com/video/'+videoId+'/translations');
print()
for filename in updates:
print('UPDATE', filename)
videoId = util.get_videoid(filename)
print('open https://studio.youtube.com/video/'+videoId+'/translations');
print()