From 49af42eaae74ee22f7378d5655f3df78ae98dee6 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Sat, 7 Oct 2017 23:59:43 +0530 Subject: [PATCH 1/5] Added requirements.txt --- .../requirements.txt | 8 ++++++++ Download Youtube Video from cmd using python/youtube.py | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 Download Youtube Video from cmd using python/requirements.txt diff --git a/Download Youtube Video from cmd using python/requirements.txt b/Download Youtube Video from cmd using python/requirements.txt new file mode 100644 index 0000000..5acd314 --- /dev/null +++ b/Download Youtube Video from cmd using python/requirements.txt @@ -0,0 +1,8 @@ +colorama>=0.3.7 +bs4>=3.5.0 +json +argparse +requests==2.10.0 +selenium==3.4.3 +urllib +subprocess diff --git a/Download Youtube Video from cmd using python/youtube.py b/Download Youtube Video from cmd using python/youtube.py index 0a86c23..0142450 100644 --- a/Download Youtube Video from cmd using python/youtube.py +++ b/Download Youtube Video from cmd using python/youtube.py @@ -7,7 +7,6 @@ from selenium.webdriver.firefox.firefox_binary import FirefoxBinary from selenium.webdriver.common.keys import Keys from urllib.request import urlopen -from getopt import GetoptError, getopt import sys import os from getpass import getuser From 88136155c64db08fe38ebee201e67d853eaa9e35 Mon Sep 17 00:00:00 2001 From: Aman gupta Date: Fri, 10 Nov 2017 15:56:12 +0530 Subject: [PATCH 2/5] Added README #3 (#10) * Added README * Update README #3 --- .../README.md | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Execute Commands From Terminal or cmd/README.md diff --git a/Execute Commands From Terminal or cmd/README.md b/Execute Commands From Terminal or cmd/README.md new file mode 100644 index 0000000..8f91a9e --- /dev/null +++ b/Execute Commands From Terminal or cmd/README.md @@ -0,0 +1,29 @@ +# Execute Commands From Terminal or cmd + + This script helps you to execute multiple CLI commands directly using single script. + +## Requirements + + 1. Python >= 3.0 + 2. pip +  + ## Installation + +1. Get the source code on your machine via git. + ``` shell + git clone https://github.com/ankitjain28may/pythonResources.git + ``` +2. Get into the directory by using + ```shell + cd pythonResources + cd "Execute Commands From Terminal or cmd" + ``` +3. Run this script using python. + ```shell + python setup.py + ``` + +## Contribution guidelines + +If you are interested in contributing to this project, open Issues and send PR. +> Feel free to code and contribute \ No newline at end of file From 5e0cee23e655f1f5e78ed5c7a51193ab768f2ec1 Mon Sep 17 00:00:00 2001 From: Kartik Khare Date: Fri, 10 Nov 2017 15:56:34 +0530 Subject: [PATCH 3/5] Added README.md (#8) --- Download from cmd using python/README.md | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Download from cmd using python/README.md diff --git a/Download from cmd using python/README.md b/Download from cmd using python/README.md new file mode 100644 index 0000000..5fd10f4 --- /dev/null +++ b/Download from cmd using python/README.md @@ -0,0 +1,42 @@ +# Download from CMD or Terminal using python +This project helps you to download any file from internet via CMD or Terminal. Just run this pthon script and enter the URL and the file name you want. + + +## Requirements + +1. Python (higher than ver. 3) +2. pip (download urllib) + + + ``` shell + pip install urllib + ``` + + +## Installation +1. Get the source code on your machine via git. + + ``` shell + git clone https://github.com/ankitjain28may/pythonResources.git + ``` + +2. Get into the directory by using- + + ```shell + cd pythonResources + cd "Download from cmd using python" + ``` + +3. Run this script as python. + ```shell + python run.py + ``` + +4. Now enter the URL and the desired name you want. + + + +## Contribution guidelines + +If you are interested in contributing to this project, open Issues and send PR. +> Feel free to code and contribute From f982eb2fe23b035d67cb7da7c14f191ade65f998 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 2 Jan 2018 14:34:10 +0530 Subject: [PATCH 4/5] Updated with latest UI of youtube --- .../playlist.py | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/Download playlist from cmd using python/playlist.py b/Download playlist from cmd using python/playlist.py index 2b91357..364f0b6 100644 --- a/Download playlist from cmd using python/playlist.py +++ b/Download playlist from cmd using python/playlist.py @@ -131,12 +131,9 @@ def main(): start = 0 end = 0 path = "playlist" - # url = input("Enter the Youtube-url\n") - # name = input("Enter the name for the video\n") - # name = name + ".mp4" parser = argparse.ArgumentParser() - parser.add_argument('-d', '--url', nargs='?', + parser.add_argument('-u', '--url', nargs='?', help="Complete download link of the playlist", type=str) parser.add_argument('-l', '--list', nargs='?', help="List id of the playlist", type=str) @@ -144,6 +141,9 @@ def main(): help="Start no. of playlist", type=int) parser.add_argument('-e', '--end', nargs='?', help="End no. of playlist", type=int) + parser.add_argument("-d", "--driver", type=str, default="phantomjs", + help="which driver to use [option: phantomjs, firefox, chrome]") + args = parser.parse_args() if args.url: @@ -160,32 +160,34 @@ def main(): try: - # Phantom JS + choice = args.driver + driver = "" + if choice == "firefox": + binary = FirefoxBinary('firefox') + driver = webdriver.Firefox(firefox_binary=binary) + elif choice == "chrome": + driver = webdriver.Chrome(); + elif choice == "phantomjs": + driver = webdriver.PhantomJS() + else: + print("Invalid Choice"); + sys.exit(1); - driver = webdriver.PhantomJS( - executable_path=r'C:\Users\ankit\Downloads\phantomjs-2.1.1-windows (1)\phantomjs-2.1.1-windows\bin\phantomjs.exe') driver.set_window_size(1120, 550) - # FireFox - - # binary = FirefoxBinary( - # 'C:\Program Files (x86)\Mozilla Firefox\Firefox.exe') - # driver = webdriver.Firefox(firefox_binary=binary) - # driver.set_window_size(1120, 550) - driver.get(url) WebDriverWait(driver, 10000).until( EC.presence_of_element_located( - (By.CSS_SELECTOR, ".pl-header-title") + (By.CSS_SELECTOR, ".yt-formatted-string") ) ) soup = BeautifulSoup(driver.page_source, 'html.parser') path = soup.find( - "h1", class_="pl-header-title").string.replace('\n', '').replace(' ', '').replace(',', '').replace('.', '').replace(':', '') + "a", class_="yt-formatted-string").string _urls = soup.find_all( - "a", class_="pl-video-title-link") + "ytd-playlist-video-renderer", class_="ytd-playlist-video-list-renderer") totalVideos = len(_urls) if end == 0: @@ -193,21 +195,20 @@ def main(): print("There are total of " + str(totalVideos) + " Videos in the playlist") - if not os.path.exists(path): - os.system('mkdir %s' % path) + if not os.path.exists(r'"'+path+'"'): + os.system('mkdir %s' % r'"'+path+'"') for i in range(start, end): _url = _urls[i] - _name = _url.string.replace('\n', '').replace( - ' ', '').replace(',', '').replace('.', '').replace(':', '') - + _name = _url.find("h3").find("span").string.replace('\n', '').replace( + ' ', '') _name += '.mp4' - _url = prefix + _url.get("href") - - driver.get("http://en.savefrom.net") + _url = prefix + _url.find("a").get("href") + driver.get("https://en.savefrom.net") + sleep(1) WebDriverWait(driver, 10000).until( EC.presence_of_element_located( (By.CSS_SELECTOR, "#sf_url") @@ -238,7 +239,7 @@ def main(): "a", class_="link link-download subname ga_track_events download-icon") url_parse = click.get("href") print(str(i + 1) + "- Downloading " + _name) - with open(path + "\\" + _name, 'wb') as out_file: + with open(path + "//" + _name, 'wb') as out_file: with urlopen(url_parse) as fp: info = fp.info() if 'Content-Length' in info: From dd165d16aeb0cee60ee3bdb7becdebf8df597eb3 Mon Sep 17 00:00:00 2001 From: ankitjain28may Date: Tue, 2 Jan 2018 20:36:03 +0530 Subject: [PATCH 5/5] Modified as per windows --- .../playlist.py | 55 ++++++++++++------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/Download playlist from cmd using python/playlist.py b/Download playlist from cmd using python/playlist.py index 364f0b6..d4e3f6b 100644 --- a/Download playlist from cmd using python/playlist.py +++ b/Download playlist from cmd using python/playlist.py @@ -131,6 +131,8 @@ def main(): start = 0 end = 0 path = "playlist" + driver = "" + system = sys.platform parser = argparse.ArgumentParser() parser.add_argument('-u', '--url', nargs='?', @@ -142,7 +144,7 @@ def main(): parser.add_argument('-e', '--end', nargs='?', help="End no. of playlist", type=int) parser.add_argument("-d", "--driver", type=str, default="phantomjs", - help="which driver to use [option: phantomjs, firefox, chrome]") + help="which driver to use [option: phantomjs, firefox, chrome]") args = parser.parse_args() @@ -161,17 +163,30 @@ def main(): try: choice = args.driver - driver = "" - if choice == "firefox": - binary = FirefoxBinary('firefox') - driver = webdriver.Firefox(firefox_binary=binary) - elif choice == "chrome": - driver = webdriver.Chrome(); - elif choice == "phantomjs": - driver = webdriver.PhantomJS() - else: - print("Invalid Choice"); - sys.exit(1); + if system == "linux" or system == "linux2": + if choice == "firefox": + binary = FirefoxBinary('firefox') + driver = webdriver.Firefox(firefox_binary=binary) + elif choice == "chrome": + driver = webdriver.Chrome() + elif choice == "phantomjs": + driver = webdriver.PhantomJS() + else: + print("Invalid Choice") + sys.exit(1) + + elif system == "win32": + if choice == "firefox": + binary = FirefoxBinary('firefox.exe') + driver = webdriver.Firefox(firefox_binary=binary) + elif choice == "chrome": + driver = webdriver.Chrome('chromedriver.exe') + elif choice == "phantomjs": + driver = webdriver.PhantomJS( + executable_path=r'phantomjs.exe') + else: + print("Invalid Choice") + sys.exit(1) driver.set_window_size(1120, 550) @@ -184,8 +199,8 @@ def main(): soup = BeautifulSoup(driver.page_source, 'html.parser') path = soup.find( - "a", class_="yt-formatted-string").string - + "a", class_="yt-formatted-string").string.replace('|', '-') + print(path) _urls = soup.find_all( "ytd-playlist-video-renderer", class_="ytd-playlist-video-list-renderer") @@ -195,15 +210,17 @@ def main(): print("There are total of " + str(totalVideos) + " Videos in the playlist") - if not os.path.exists(r'"'+path+'"'): - os.system('mkdir %s' % r'"'+path+'"') + if not os.path.exists(r'"' + path + '"'): + os.system('mkdir %s' % r'"' + path + '"') + # path = os.path.abspath(path) + # print(path) for i in range(start, end): _url = _urls[i] _name = _url.find("h3").find("span").string.replace('\n', '').replace( - ' ', '') + ' ', '').replace('|', '-') _name += '.mp4' _url = prefix + _url.find("a").get("href") @@ -239,7 +256,7 @@ def main(): "a", class_="link link-download subname ga_track_events download-icon") url_parse = click.get("href") print(str(i + 1) + "- Downloading " + _name) - with open(path + "//" + _name, 'wb') as out_file: + with open(path + "\\" + _name, 'wb') as out_file: with urlopen(url_parse) as fp: info = fp.info() if 'Content-Length' in info: @@ -262,9 +279,9 @@ def main(): print("\n") print("Successfully download " + _name) sys.stdout.write("\a") + driver.quit() except Exception as e: print(e) - driver.quit() if __name__ == '__main__':