Пример #1
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);
        }
Пример #2
0
        // Example:
        //
        //   eax=7ffdb000 ebx=00000000 ecx=00000000 edx=7785f17d esi=00000000 edi=00000000
        //   eip=777f410c esp=040ef770 ebp=040ef79c iopl=0         nv up ei pl zr na pe nc
        //   cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
        //   ntdll!DbgBreakPoint:
        //
        public override ColorString ToColorString()
        {
            if (null == m_colorString)
            {
                ConsoleColor color;
                ColorString  cs = new ColorString("eax=");
                color = GetColorForDiffAgainstBaseline("eax");
                cs.Append(Eax.GetColorizedValueString(color));
                cs.Append(" ebx=");
                color = GetColorForDiffAgainstBaseline("ebx");
                cs.Append(Ebx.GetColorizedValueString(color));
                cs.Append(" ecx=");
                color = GetColorForDiffAgainstBaseline("ecx");
                cs.Append(Ecx.GetColorizedValueString(color));
                cs.Append(" edx=");
                color = GetColorForDiffAgainstBaseline("edx");
                cs.Append(Edx.GetColorizedValueString(color));
                cs.Append(" esi=");
                color = GetColorForDiffAgainstBaseline("esi");
                cs.Append(Esi.GetColorizedValueString(color));
                cs.Append(" edi=");
                color = GetColorForDiffAgainstBaseline("edi");
                cs.Append(Edi.GetColorizedValueString(color));
                cs.AppendLine();

                cs.Append("eip=");
                color = GetColorForDiffAgainstBaseline("eip");
                cs.Append(Eip.GetColorizedValueString(color));
                cs.Append(" esp=");
                color = GetColorForDiffAgainstBaseline("esp");
                cs.Append(Esp.GetColorizedValueString(color));
                cs.Append(" ebp=");
                color = GetColorForDiffAgainstBaseline("ebp");
                cs.Append(Ebp.GetColorizedValueString(color));
                cs.Append(" iopl=");
                color = GetColorForDiffAgainstBaseline("iopl");
                cs.AppendPushPopFg(color, ((uint)Iopl.Value).ToString("x"));
                // TODO:
                cs.AppendLine("   TBD: flags");

                cs.Append("cs=");
                color = GetColorForDiffAgainstBaseline("cs");
                cs.AppendPushPopFg(color, ((uint)Cs.Value).ToString("x4"));
                cs.Append("  ss=");
                color = GetColorForDiffAgainstBaseline("ss");
                cs.AppendPushPopFg(color, ((uint)Ss.Value).ToString("x4"));
                cs.Append("  ds=");
                color = GetColorForDiffAgainstBaseline("ds");
                cs.AppendPushPopFg(color, ((uint)Ds.Value).ToString("x4"));
                cs.Append("  es=");
                color = GetColorForDiffAgainstBaseline("es");
                cs.AppendPushPopFg(color, ((uint)Es.Value).ToString("x4"));
                cs.Append("  fs=");
                color = GetColorForDiffAgainstBaseline("fs");
                cs.AppendPushPopFg(color, ((uint)Fs.Value).ToString("x4"));
                cs.Append("  gs=");
                color = GetColorForDiffAgainstBaseline("gs");
                cs.AppendPushPopFg(color, ((uint)Gs.Value).ToString("x4"));
                cs.Append("             efl=");
                color = GetColorForDiffAgainstBaseline("efl");
                cs.Append(Efl.GetColorizedValueString(color));
                cs.AppendLine();

                cs.Append(DbgProvider.ColorizeSymbol(StackFrame.SymbolName));
                if (0 != StackFrame.Displacement)
                {
                    cs.Append("+0x");
                    cs.Append(StackFrame.Displacement.ToString("x"));
                }
                cs.AppendLine(":");
                cs.Append(Disasm(Eip.ValueAsPointer));

                m_colorString = cs;
            }
            return(m_colorString);
        } // end ToString()