Nick Ficano
commited on
Commit
·
aee8e93
1
Parent(s):
27b0198
pep8, removed calls to deprecated methods.
Browse files- scripts/pytubectl +33 -31
scripts/pytubectl
CHANGED
@@ -1,50 +1,50 @@
|
|
1 |
#!/usr/bin/env python
|
|
|
2 |
from __future__ import print_function
|
|
|
|
|
|
|
3 |
|
4 |
from pytube import YouTube
|
5 |
-
from pytube.utils import print_status
|
6 |
-
from pytube.utils import FullPaths
|
7 |
from pytube.exceptions import YouTubeError
|
8 |
from pprint import pprint
|
9 |
|
10 |
-
import sys
|
11 |
-
import os
|
12 |
-
import argparse
|
13 |
-
|
14 |
|
15 |
-
def
|
16 |
parser = argparse.ArgumentParser(description='YouTube video downloader')
|
17 |
-
parser.add_argument("url", help=
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
help="The path to save the video to."
|
25 |
-
parser.add_argument("--filename", "-f",
|
26 |
-
|
27 |
-
help=("The filename, without extension, "
|
28 |
-
"to save the video in."))
|
29 |
|
30 |
args = parser.parse_args()
|
31 |
|
32 |
-
yt = YouTube()
|
33 |
try:
|
34 |
-
yt
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
37 |
except YouTubeError:
|
38 |
print("Incorrect video URL.")
|
39 |
sys.exit(1)
|
40 |
|
41 |
if args.filename:
|
42 |
-
yt.
|
43 |
|
44 |
if args.ext or args.res:
|
45 |
if not all([args.ext, args.res]):
|
46 |
-
print("
|
47 |
-
|
|
|
48 |
sys.exit(1)
|
49 |
|
50 |
if args.ext and args.res:
|
@@ -52,8 +52,9 @@ def _main():
|
|
52 |
vid = yt.get(args.ext, args.res)
|
53 |
# Check if there's a video returned
|
54 |
if not vid:
|
55 |
-
print("
|
56 |
-
|
|
|
57 |
sys.exit(1)
|
58 |
|
59 |
elif args.ext:
|
@@ -70,13 +71,14 @@ def _main():
|
|
70 |
videos = yt.filter(res=args.res)
|
71 |
# Check if we have a video
|
72 |
if not videos:
|
73 |
-
print("There are no videos in the specified in the specified
|
|
|
74 |
sys.exit(1)
|
75 |
# Select the highest resolution one
|
76 |
vid = max(videos)
|
77 |
else:
|
78 |
# If nothing is specified get the highest resolution one
|
79 |
-
vid = max(yt.
|
80 |
|
81 |
try:
|
82 |
vid.download(path=args.path, on_progress=print_status)
|
@@ -85,4 +87,4 @@ def _main():
|
|
85 |
sys.exit(1)
|
86 |
|
87 |
if __name__ == '__main__':
|
88 |
-
|
|
|
1 |
#!/usr/bin/env python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
from __future__ import print_function
|
4 |
+
import sys
|
5 |
+
import os
|
6 |
+
import argparse
|
7 |
|
8 |
from pytube import YouTube
|
9 |
+
from pytube.utils import print_status, FullPaths
|
|
|
10 |
from pytube.exceptions import YouTubeError
|
11 |
from pprint import pprint
|
12 |
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
def main():
|
15 |
parser = argparse.ArgumentParser(description='YouTube video downloader')
|
16 |
+
parser.add_argument("url", help=(
|
17 |
+
"The URL of the Video to be downloaded"))
|
18 |
+
parser.add_argument("--extension", "-e", dest="ext", help=(
|
19 |
+
"The requested format of the video"))
|
20 |
+
parser.add_argument("--resolution", "-r", dest="res", help=(
|
21 |
+
"The requested resolution"))
|
22 |
+
parser.add_argument("--path", "-p", action=FullPaths, default=os.getcwd(),
|
23 |
+
dest="path", help=("The path to save the video to."))
|
24 |
+
parser.add_argument("--filename", "-f", dest="filename", help=(
|
25 |
+
"The filename, without extension, to save the video in."))
|
|
|
|
|
26 |
|
27 |
args = parser.parse_args()
|
28 |
|
|
|
29 |
try:
|
30 |
+
yt = YouTube(args.url)
|
31 |
+
videos = []
|
32 |
+
for i, video in enumerate(yt.get_videos()):
|
33 |
+
ext = video.extension
|
34 |
+
res = video.resolution
|
35 |
+
videos.append("{} {}".format(ext, res))
|
36 |
except YouTubeError:
|
37 |
print("Incorrect video URL.")
|
38 |
sys.exit(1)
|
39 |
|
40 |
if args.filename:
|
41 |
+
yt.set_filename(args.filename)
|
42 |
|
43 |
if args.ext or args.res:
|
44 |
if not all([args.ext, args.res]):
|
45 |
+
print("Make sure you give either of the below specified "
|
46 |
+
"format/resolution combination.")
|
47 |
+
pprint(videos)
|
48 |
sys.exit(1)
|
49 |
|
50 |
if args.ext and args.res:
|
|
|
52 |
vid = yt.get(args.ext, args.res)
|
53 |
# Check if there's a video returned
|
54 |
if not vid:
|
55 |
+
print("There's no video with the specified format/resolution "
|
56 |
+
"combination.")
|
57 |
+
pprint(videos)
|
58 |
sys.exit(1)
|
59 |
|
60 |
elif args.ext:
|
|
|
71 |
videos = yt.filter(res=args.res)
|
72 |
# Check if we have a video
|
73 |
if not videos:
|
74 |
+
print("There are no videos in the specified in the specified "
|
75 |
+
"resolution.")
|
76 |
sys.exit(1)
|
77 |
# Select the highest resolution one
|
78 |
vid = max(videos)
|
79 |
else:
|
80 |
# If nothing is specified get the highest resolution one
|
81 |
+
vid = max(yt.get_videos())
|
82 |
|
83 |
try:
|
84 |
vid.download(path=args.path, on_progress=print_status)
|
|
|
87 |
sys.exit(1)
|
88 |
|
89 |
if __name__ == '__main__':
|
90 |
+
main()
|