-
Notifications
You must be signed in to change notification settings - Fork 0
/
yt_downloader.py
70 lines (57 loc) · 2.42 KB
/
yt_downloader.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
60
61
62
63
64
65
66
67
68
69
70
from pytube import YouTube
import csv
import os
print(
'''
############################################################
# #
# YouTube Video Downloader #
# #
# This python script can be used by law enforcement to #
# capture YT videos and exhibit them #
# #
# The exhibit reference and video metadata will be #
# captured in a csv file #
# #
# #
# Author: Tom Newman #
# #
# Support: [email protected] #
# #
# #
############################################################
''')
# Enter case reference
case_ref = input("Please enter a case reference: ")
# Create a new directory for files
path = os.getcwd()
os.mkdir(path + "/" + case_ref + "-" + "YouTube Data")
# Change into directory
os.chdir(path + "/" + case_ref + "-" + "YouTube Data")
path = os.getcwd()
# Create CSV log file
outfile = open(
path + '/video_log.csv', 'w', newline='')
writer = csv.writer(outfile)
writer.writerow(["Exh Ref", "Title", "No. Of Views",
"Length of Video", "Description", "Ratings", "Date Published", "Source"])
# Download YT videos and log data to csv
trigger_end = 0
while trigger_end == 0:
exh_ref = input("Please enter an Exhibit Reference: " + "\n")
link = input("Please enter the full Youtube link: " + "\n")
yt = YouTube(link)
writer.writerow([exh_ref, yt.title, yt.views, yt.length,
yt.description, yt.rating, yt.publish_date, link])
ys = yt.streams.get_highest_resolution()
print("Downloading " + yt.title + "\n")
ys.download(path)
print("+++ Downloading complete +++" + "\n")
os.rename(path + "/" +
ys.default_filename, path + "/" + exh_ref + '.mp4')
dl_more = input(
"Do you want to download another video? (please enter Y or N) ")
if dl_more == 'Y':
trigger_end = 0
else:
trigger_end = 1