Skip to content

Commit

Permalink
Merge pull request #3 from dewanshrawat15/CI-tests
Browse files Browse the repository at this point in the history
Ci tests
  • Loading branch information
dewanshrawat15 committed Jul 20, 2019
2 parents cc7c005 + 131a72f commit 939348e
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from os import system, name
import urllib.parse as urlparse
import sys
import argparse

def clear():
if name == 'nt':
Expand Down Expand Up @@ -36,15 +37,18 @@ def download(self, link, filename, format):
f.write(data)
print(downloaded_file_name+" downloaded")

def scrape(self, url):
def scrape(self, url, vid_format):
src = urlopen(url)
codebase = BeautifulSoup(src, 'html.parser')
y = codebase.findAll("a")
req = []
names = []
print("Format of videos ? (FLV, MP4 or 3GP): ")
x = input()
x = x.lower()
if vid_format is None:
print("Format of videos ? (FLV, MP4 or 3GP): ")
x = input()
x = x.lower()
else:
x = vid_format
for i in y:
temp = i.get("href")
if x in temp:
Expand All @@ -60,8 +64,33 @@ def scrape(self, url):
for i in range(len(req)):
self.download(req[i], names[i], x)

clear()
x = input("Enter URL address of download page: ")
# Course to be downloaded https://nptel.ac.in/courses/nptel_download.php?subjectid=106102064
download = Downloader()
download.scrape(x)
def fetch_page(self, course_url, vid_format):
src = urlopen(course_url)
codebase = BeautifulSoup(src, 'html.parser')
links = codebase.findAll("a")
for i in links:
urlText = i.getText()
if urlText == "Download Videos & Transcripts":
downloadPageURL = urljoin(course_url, i.get("href"))
break
self.scrape(downloadPageURL, vid_format)

def start():
clear()
parser = argparse.ArgumentParser(description='NPTEL Downloader. Download the videos of your favorite course on NPTEL. Just paste the web address of the course page, and start downloading those videos. ')
parser.add_argument("-u", "--url", help="Enter the course page url")
parser.add_argument("-f", "--format", help="Enter the format in which the videos have to be downloaded")
# parser.add_argument("-p", "--path", help="Enter the path where the videos have to be downloaded")g
args = parser.parse_args()
if not args.url:
x = input("Enter URL address of download page: ")
# Course to be downloaded https://nptel.ac.in/courses/nptel_download.php?subjectid=106102064
download = Downloader()
supported_formats = ['mp4', 'flv', '3gp']
if args.format and args.format.lower() in supported_formats:
download.fetch_page(args.url, args.format.lower())
else:
download.fetch_page(x, None)

if __name__ == "__main__":
start()

0 comments on commit 939348e

Please sign in to comment.