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 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 diff --git a/Download playlist from cmd using python/playlist.py b/Download playlist from cmd using python/playlist.py index 2b91357..d4e3f6b 100644 --- a/Download playlist from cmd using python/playlist.py +++ b/Download playlist from cmd using python/playlist.py @@ -131,12 +131,11 @@ 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" + driver = "" + system = sys.platform 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 +143,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 +162,47 @@ def main(): try: - # Phantom JS + choice = args.driver + 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 = 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.replace('|', '-') + print(path) _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 +210,22 @@ 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 + '"') + # path = os.path.abspath(path) + # print(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( + ' ', '').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") @@ -261,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__': 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