public FutureLearnDownloader(FutureLearn futureLearn)
 {
     _futureleanCourse = futureLearn;
     Ignorefiles = _futureleanCourse.Ignorefiles as List<string>;
 }
Example #2
0
 public FutureLearnDownloader(FutureLearn futureLearn)
 {
     _futureleanCourse = futureLearn;
     Ignorefiles       = _futureleanCourse.Ignorefiles as List <string>;
 }
Example #3
0
        private static int Main(string[] args)
        {
            // parse the commandline arguments
            OptionSet optionSet = new OptionSet();

            Console.WriteLine("Download Coursera.org course videos/docs for offline use.");
            optionSet.WriteOptionDescriptions(Console.Out);

            optionSet.Add("u=", "coursera username (.netrc used if omitted)", value => username = value);
            optionSet.Add("p=", "coursera password", value => password = value);

            optionSet.Add("d:", "destination directory where everything will be saved", value => dest_dir = value);
            optionSet.Add("n:", "comma-separated list of file extensions to skip, e.g., \"ppt,srt,pdf\"", value => ignorefiles     = value);
            optionSet.Add("reverse-sections:", "download and save the sections in reverse order", value => reverse                 = value);
            optionSet.Add("course_names=", "one or more course names from the url (e.g., comnets-2012-001)", value => course_names = value.Split('+'));
            optionSet.Add("gz:", "Tarball courses for archival storage (folders get deleted)", value => gzip_courses               = (value == "true"));
            optionSet.Add("mppl:", "Maximum length of filenames/dirs in a path", value => mppl = int.Parse(value));
            optionSet.Add("w:", "Comma separted list of week numbers to download e.g., 1,3,8", value => wkfilter = value);
            List <string> unparsedArgs = optionSet.Parse(args);

            Console.WriteLine("Coursera-dl v{0} ({1})", Assembly.GetExecutingAssembly().GetName().Version, optionSet.GetType().ToString());

            if (unparsedArgs.Contains("u"))
            {
                Console.WriteLine("Please enter your username:"******"p")) // prompt the user for his password if not specified
            {
                Console.WriteLine("Please enter your password:"******"mppl"))
            {
                // if mppl is not specified set manually
                mppl = 260;
                Console.WriteLine("Maximum length of a path component set to {0}", mppl);
            }

            List <IMooc> courseList  = new List <IMooc>();
            Coursera     coursera    = null;
            FutureLearn  futureLearn = null;
            Edx          edx         = null;
            int          i           = 0;

            foreach (string courseName in course_names)
            {
                string[] courseLocationName = courseName.Split(':');
                switch (courseLocationName[0]) //which site
                {
                case "coursera":
                    // instantiate the downloader class
                    coursera = new Coursera(username, password, proxy, parser, ignorefiles, mppl, gzip_courses, wkfilter);
                    // authenticate, only need to do this once but need a classaname to get hold
                    // of the csrf token, so simply pass the first one
                    Console.WriteLine("Logging in as \"{0}\"...", username);
                    coursera.Login(courseLocationName[1]);     //the actual course name
                    Course courseContent = coursera.GetDownloadableContent(courseLocationName[1]);
                    coursera.Courses.Add(courseContent);
                    Console.WriteLine("Course {0} of {1}", i + 1, course_names.Length);
                    break;

                case "futurelearn":
                    // instantiate the downloader class
                    futureLearn = new FutureLearn(username, password, proxy, parser, ignorefiles, mppl, gzip_courses, wkfilter);
                    // authenticate, need to get hold of the csrf token
                    Console.WriteLine("Logging in as \"{0}\"...", username);
                    futureLearn.Login();
                    Course flCourseContent = futureLearn.GetDownloadableContent(courseLocationName[1]);
                    futureLearn.Courses.Add(flCourseContent);
                    Console.WriteLine("Course {0} of {1}", i + 1, course_names.Length);
                    break;

                case "udacity":
                    break;

                case "edx":
                    // instantiate the downloader class
                    edx = new Edx(username, password, proxy, parser, ignorefiles, mppl, gzip_courses, wkfilter);
                    // authenticate, need to get hold of the csrf token
                    Console.WriteLine("Logging in as \"{0}\"...", username);
                    if (!edx.Login())
                    {
                        return(1);
                    }
                    Course edxCourseContent = edx.GetDownloadableContent(courseLocationName[1]);
                    edx.Courses.Add(edxCourseContent);
                    Console.WriteLine("Course {0} of {1}", i + 1, course_names.Length);
                    break;

                case "canvas":
                    break;
                }
                i++;
            }

            // download the content
            if (coursera != null)
            {
                foreach (Course course in coursera.Courses)
                {
                    coursera.Download(course.CourseName, dest_dir, false, gzip_courses, course);
                }
            }
            if (futureLearn != null)
            {
                foreach (Course course in futureLearn.Courses)
                {
                    futureLearn.Download(course.CourseName, dest_dir, false, gzip_courses, course);
                }
            }
            if (edx != null)
            {
                foreach (Course course in edx.Courses)
                {
                    edx.Download(course.CourseName, dest_dir, false, gzip_courses, course);
                }
            }
            return(0);
        }