Skip to content

Commit 39072df

Browse files
Merge pull request ankitjain28may#9 from ankitjain28may/ankit
Added driver choice
2 parents 3701067 + c08e7bb commit 39072df

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

Download Youtube Video from cmd using python/youtube.ide.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import urllib.request
66
import json
77
import time
8+
import argparse
89
import selenium
910
from selenium import webdriver
1011
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
@@ -18,15 +19,27 @@
1819
print(name)
1920
try:
2021

21-
# Phantom JS
22+
ap = argparse.ArgumentParser()
23+
ap.add_argument("-d", "--driver", type=str, default="phantomjs",
24+
help="which driver to use [option: phantomjs, firefox, chrome]")
2225

23-
driver = webdriver.PhantomJS(executable_path=r'C:\Users\ankit\Downloads\phantomjs-2.1.1-windows (1)\phantomjs-2.1.1-windows\bin\phantomjs.exe')
24-
driver.set_window_size(1120, 550)
26+
args = vars(ap.parse_args())
27+
choice = args["driver"]
2528

26-
# FireFox
29+
driver = ""
30+
if choice == "firefox":
31+
binary = FirefoxBinary('firefox')
32+
driver = webdriver.Firefox(firefox_binary=binary)
33+
elif choice == "chrome":
34+
driver = webdriver.Chrome();
35+
elif choice == "phantomjs":
36+
driver = webdriver.PhantomJS(
37+
executable_path=r'phantomjs')
38+
else:
39+
print("Invalid Choice");
40+
sys.exit(1);
2741

28-
# binary = FirefoxBinary('C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')
29-
# driver = webdriver.Firefox(firefox_binary=binary)
42+
driver.set_window_size(1120, 550)
3043

3144
driver.get("http://en.savefrom.net")
3245
shURL = driver.find_element_by_xpath('//input[@id="sf_url" and @type="text"]')
@@ -40,10 +53,6 @@
4053
url_parse = click.get("href")
4154
driver.quit()
4255
path = os.getcwd()
43-
# print("Downloading Starts..\n")
44-
# print(url_parse)
45-
# urllib.request.urlretrieve(url_parse, name)
46-
4756

4857
installs = [
4958
'idman.exe /n /d ' + '"' + url_parse + '"' + ' /p ' + '"' + path + '"' + ' /f ' + '"' + name + '"' + ' /q',

Download Youtube Video from cmd using python/youtube.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import requests
33
import json
44
import selenium
5+
import argparse
56
from selenium import webdriver
67
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
78
from selenium.webdriver.common.keys import Keys
@@ -115,22 +116,36 @@ def reporthook(blocknum, blocksize, total):
115116
sizeType = ''
116117
flag = 0
117118

119+
120+
121+
118122
url = input("Enter the Youtube-url\n")
119123
name = input("Enter the name for the video\n")
120124
name = name+".mp4"
121125
try:
122126

123-
# Phantom JS
127+
ap = argparse.ArgumentParser()
128+
ap.add_argument("-d", "--driver", type=str, default="phantomjs",
129+
help="which driver to use [option: phantomjs, firefox, chrome]")
130+
131+
args = vars(ap.parse_args())
132+
choice = args["driver"]
133+
134+
driver = ""
135+
if choice == "firefox":
136+
binary = FirefoxBinary('firefox')
137+
driver = webdriver.Firefox(firefox_binary=binary)
138+
elif choice == "chrome":
139+
driver = webdriver.Chrome();
140+
elif choice == "phantomjs":
141+
driver = webdriver.PhantomJS(
142+
executable_path=r'phantomjs')
143+
else:
144+
print("Invalid Choice");
145+
sys.exit(1);
124146

125-
driver = webdriver.PhantomJS(
126-
executable_path=r'C:\Users\ankit\Downloads\phantomjs-2.1.1-windows (1)\phantomjs-2.1.1-windows\bin\phantomjs.exe')
127147
driver.set_window_size(1120, 550)
128148

129-
# FireFox
130-
131-
# binary = FirefoxBinary('C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')
132-
# driver = webdriver.Firefox(firefox_binary=binary)
133-
134149
driver.get("http://en.savefrom.net")
135150
shURL = driver.find_element_by_xpath(
136151
'//input[@id="sf_url" and @type="text"]')

0 commit comments

Comments
 (0)