-
Notifications
You must be signed in to change notification settings - Fork 0
/
ytgrep.py
46 lines (36 loc) · 1.27 KB
/
ytgrep.py
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
from ytcc.download import Download
import argparse
import sys
def main():
parser = argparse.ArgumentParser(description='ytgrep')
parser.add_argument(
'-e',
action="store_true",
help='Interpret PATTERN as an extended regular expression')
parser.add_argument(
'-v',
action="store_true",
help='Print debug information while searching')
parser.add_argument(
'-links',
action="store_true",
help='include shortcut links to video at matched time i.e. ?t=<time>')
parser.add_argument('pattern', type=str, help='term to search for')
parser.add_argument('urls', nargs='+', help='video URL(s)')
args = parser.parse_args()
args_dict = vars(args)
download = Download(args_dict)
try:
captions = download.get_captions()
if len(captions) == 0:
print("No matches found.")
sys.exit(1)
print(captions)
except Exception as err:
print("Unable to retrieve captions, {}".format(err))
if __name__ == "__main__":
main()
# related project: https://github.com/antiboredom/videogrep
# caption downloading:
# https://github.com/mkly/youtube-closed-captions/tree/master/ytcc
# packaging: https://packaging.python.org/tutorials/packaging-projects/