-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (48 loc) · 1.46 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
import youtube_dl
import logging
import sys
import os
import json
def main():
print("Running YouTube Download Script")
print(sys.argv)
if len(sys.argv) > 1:
download_youtube_video(sys.argv[1])
return
def download_youtube_video(youtube_url_passed_in):
# detect files in current directory
dirs = os.listdir(".")
file_list = []
for file in dirs:
file_list.append(str(file))
print(file_list)
# download youtube video
youtube_url = "https://www.youtube.com/watch?v=Z9ZIuoQDtL0"
if len(youtube_url_passed_in) > 15:
youtube_url = youtube_url_passed_in
youtube_url_array = [youtube_url]
ydl_opts = {
'outtmpl': "%(id)s.%(ext)s",
'forcejson' : True,
'writeinfojson' : True,
'write_all_thumbnails' : True,
'writesubtitles' : True,
'writeautomaticsub' : True
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(youtube_url_array)
# get new file list
dirs = os.listdir(".")
new_file_list = []
for file in dirs:
new_file_list.append(str(file))
print(new_file_list)
# remove files that were in the list previously
for old_item in file_list:
new_file_list.remove(old_item)
# now iterate through the new files list
for new_file in new_file_list:
os.system("gsutil cp " + str(new_file) + " gs://farmtwitter.appspot.com/")
print(__name__)
if __name__ == "__main__":
main()