Пример #1
0
 def course_download(self, path='', quality='', download_all=False):
     sys.stdout.write('\033[2K\033[1G\r\r' + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Downloading accessible courses information .. \r")
     courses = acloud.courses(cookies=self.cookies)
     if not download_all:
         sys.stdout.write('\033[2K\033[1G\r\r' + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Downloading accessible courses information .. (done)\r\n")
         counter = 1
         for course in courses:
             title = course.title
             sys.stdout.write(fc + sd + "[" + fm + sb + "%s" % (counter) + fc + sd + "] : " + fg + sb + "%s\n" % (title))
             counter += 1
         question = fc + sd + "[" + fw + sb + "?" + fc + sd + "] : " + fy + sb + "select course number between (1/%s/all): " % (len(courses))+ fg + sb
         ask_user = self._getuser(prompt=question)
         if ask_user and ask_user == "all":
             download_all = True
         elif ask_user and ask_user[-1] == '+':
             course_number = int(ask_user.split('+')[0])-1
             if course_number > 0 and course_number < len(courses):
                 courses = courses[course_number:len(courses)]
         else:
             course_number = int(ask_user)-1
             if course_number > 0 and course_number < len(courses):
                 courses = [courses[course_number]]
         if not ask_user:
             download_all = True
     for course in courses:
         course_name = course.title
         sys.stdout.write ("\n" + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Course " + fb + sb + "'%s'.\n" % (course_name))
         sys.stdout.write('\033[2K\033[1G\r\r' + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Downloading course information .. \r")
         course = course.get_course(keep_alive=download_all)
         sys.stdout.write('\033[2K\033[1G\r\r' + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Downloaded course information .. (done)\r\n")
         chapters = course.get_chapters()
         total_lectures = course.lectures
         total_chapters = course.chapters
         sys.stdout.write (fc + sd + "[" + fm + sb + "+" + fc + sd + "] : " + fg + sd + "Chapter(s) (%s).\n" % (total_chapters))
         sys.stdout.write (fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sd + "Lecture(s) (%s).\n" % (total_lectures))
         if path:
           if '~' in path:
               path = os.path.expanduser(path)
           course_path = "%s\\%s" % (path, course_name) if os.name == 'nt' else "%s/%s" % (path, course_name)
         else:
           path = os.getcwd()
           course_path = "%s\\%s" % (path, course_name) if os.name == 'nt' else "%s/%s" % (path, course_name)
         for chapter in chapters:
           # chapter_id = chapter.id
           chapter_index = chapter.index
           chapter_title = chapter.title
           lectures = chapter.get_lectures()
           lectures_count = chapter.lectures
           filepath = "%s\\%s" % (course_path, chapter_title) if os.name == 'nt' else "%s/%s" % (course_path, chapter_title)
           _ = course.create_chapter(filepath=filepath)
           sys.stdout.write (fc + sd + "\n[" + fm + sb + "*" + fc + sd + "] : " + fm + sb + "Downloading chapter : ({index} of {total})\n".format(index=chapter_index, total=total_chapters))
           sys.stdout.write (fc + sd + "[" + fw + sb + "+" + fc + sd + "] : " + fw + sd + "Chapter (%s)\n" % (chapter_title))
           sys.stdout.write (fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sd + "Found (%s) lectures ...\n" % (lectures_count))
           for lecture in lectures:
               # lecture_id = lecture.id
               lecture_index = lecture.index
               lecture_title = lecture.title
               lecture_best = lecture.getbest()
               lecture_streams = lecture.streams
               lecture_assets = lecture.assets
               lecture_subs = lecture.subtitle
               lecture_best = lecture.get_quality(best_quality=lecture_best, streams=lecture_streams, requested=quality)
               self.download_lectures_only(lecture_best=lecture_best, lecture_title=lecture_title, inner_index=lecture_index, lectures_count=lectures_count, lecture_assets=lecture_assets, lecture_subs=lecture_subs, filepath=filepath)
Пример #2
0
 def course_list_down(self, download_all):
     sys.stdout.write('\033[2K\033[1G\r\r' + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Downloading accessible courses information .. \r")
     courses = acloud.courses(cookies=self.cookies)
     if not download_all:
         sys.stdout.write('\033[2K\033[1G\r\r' + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Downloading accessible courses information .. (done)\r\n")
         counter = 1
         for course in courses:
             title = course.title
             sys.stdout.write(fc + sd + "[" + fm + sb + "%s" % (counter) + fc + sd + "] : " + fg + sb + "%s\n" % (title))
             counter += 1
         question = fc + sd + "[" + fw + sb + "?" + fc + sd + "] : " + fy + sb + "select course number between (1/%s/all): " % (len(courses))+ fg + sb
         ask_user = self._getuser(prompt=question)
         if ask_user and ask_user == "all":
             download_all = True
         if ask_user and ask_user != "all":
             course_number = int(ask_user)-1
             if course_number > 0 and course_number < len(courses):
                 courses = [courses[course_number]]
         if not ask_user:
             download_all = True
     for course in courses:
         course_name = course.title
         sys.stdout.write ("\n" + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Course " + fb + sb + "'%s'.\n" % (course_name))
         sys.stdout.write('\033[2K\033[1G\r\r' + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Downloading course information .. \r")
         course = course.get_course(keep_alive=download_all)
         sys.stdout.write('\033[2K\033[1G\r\r' + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Downloaded course information .. (done)\r\n")
         chapters = course.get_chapters()
         total_lectures = course.lectures
         total_chapters = course.chapters
         sys.stdout.write (fc + sd + "[" + fm + sb + "+" + fc + sd + "] : " + fg + sd + "Chapter(s) (%s).\n" % (total_chapters))
         sys.stdout.write (fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sd + "Lecture(s) (%s).\n" % (total_lectures))
         for chapter in chapters:
             chapter_id = chapter.id
             chapter_index = chapter.index
             chapter_title = chapter.title
             lectures = chapter.get_lectures()
             lectures_count = chapter.lectures
             sys.stdout.write ('\n' + fc + sd + "[" + fw + sb + "+" + fc + sd + "] : " + fw + sd + "Chapter (%s)\n" % (chapter_title))
             sys.stdout.write (fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sd + "Lecture(s) (%s).\n" % (lectures_count))
             for lecture in lectures:
                 lecture_id = lecture.id
                 lecture_index = lecture.index
                 lecture_title = lecture.title
                 lecture_best = lecture.getbest()
                 lecture_streams = lecture.streams
                 lecture_assets = lecture.assets
                 # lecture_subs = lecture.subtitle
                 if lecture_streams:
                     sys.stdout.write(fc + sd + "     - " + fy + sb + "duration   : " + fm + sb + str(lecture.duration)+ fy + sb + ".\n")
                     sys.stdout.write(fc + sd + "     - " + fy + sb + "Lecture id : " + fm + sb + str(lecture_id)+ fy + sb + ".\n")
                     for stream in lecture_streams:
                         content_length = stream.get_filesize()
                         if content_length != 0:
                             if content_length <= 1048576.00:
                                 size = round(float(content_length) / 1024.00, 2)
                                 sz = format(size if size < 1024.00 else size/1024.00, '.2f')
                                 in_MB = 'KB' if size < 1024.00 else 'MB'
                             else:
                                 size = round(float(content_length) / 1048576, 2)
                                 sz = format(size if size < 1024.00 else size/1024.00, '.2f')
                                 in_MB = "MB " if size < 1024.00 else 'GB '
                             if lecture_best.dimention[1] == stream.dimention[1]:
                                 in_MB = in_MB + fc + sb + "(Best)" + fg + sd
                             sys.stdout.write('\t- ' + fg + sd + "{:<23} {:<8}{}{}{}{}\n".format(str(stream), str(stream.dimention[1]) + 'p', sz, in_MB, fy, sb))
                             time.sleep(0.5)
                 if lecture_assets:
                     for asset in lecture_assets:
                         if asset.mediatype != 'external_link':
                             content_length = asset.get_filesize()
                             if content_length != 0:
                                 if content_length <= 1048576.00:
                                     size = round(float(content_length) / 1024.00, 2)
                                     sz = format(size if size < 1024.00 else size/1024.00, '.2f')
                                     in_MB = 'KB' if size < 1024.00 else 'MB'
                                 else:
                                     size = round(float(content_length) / 1048576, 2)
                                     sz = format(size if size < 1024.00 else size/1024.00, '.2f')
                                     in_MB = "MB " if size < 1024.00 else 'GB '
                                 sys.stdout.write('\t- ' + fg + sd + "{:<23} {:<8}{}{}{}{}\n".format(str(asset), asset.extension, sz, in_MB, fy, sb))
Пример #3
0
    def courses_downloaded(self, path='', download_all=False, download_only_new=False):
        sys.stdout.write('\033[2K\033[1G\r\r' + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb +
                         "Downloading accessible courses information .. \r")
        courses = self.courses_not_downloaded(acloud.courses(cookies=self.cookies), path, download_only_new)

        if not download_all:
            sys.stdout.write('\033[2K\033[1G\r\r' + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb +
                             "Downloading accessible courses information .. (done)\r\n")
            counter = 1
            for course in courses:
                title = course.title
                sys.stdout.write(fc + sd + "[" + fm + sb + "%s" % counter + fc + sd + "] : " + fg + sb + "%s\n" % title)
                counter += 1
            question = fc + sd + "[" + fw + sb + "?" + fc + sd + "] : " + fy + sb + "select course number or range (1/%s/range): " % (len(courses)) + fg + sb
            ask_user = self._getuser(prompt=question)
            # setting default to download all if no user input is provided
            if ask_user and ask_user[-1] == '+':
                course_number = int(ask_user.split('+')[0])
                if 0 < course_number <= len(courses):
                    course_number = course_number - 1
                    courses = courses[course_number:len(courses)]
            elif ask_user and ask_user[-1] != "+":
                course_number = int(ask_user)
                if 0 < course_number <= len(courses):
                    course_number = course_number - 1
                    courses = [courses[course_number]]
            else:
                download_all = True

        for course in courses:
            course_name = course.title
            sys.stdout.write(
                "\n" + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Course " + fb + sb + "'%s'.\n" % course_name)
            sys.stdout.write(
                '\033[2K\033[1G\r\r' + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Downloading course information .. \r")
            course = course.get_course(keep_alive=download_all)
            sys.stdout.write(
                '\033[2K\033[1G\r\r' + fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Downloaded course information .. (done)\r\n")
            chapters = course.get_chapters()
            total_lectures = course.lectures
            total_chapters = course.chapters
            sys.stdout.write(
                fc + sd + "[" + fm + sb + "+" + fc + sd + "] : " + fg + sd + "Chapter(s) (%s).\n" % total_chapters)
            sys.stdout.write(
                fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sd + "Lecture(s) (%s).\n" % total_lectures)
            for chapter in chapters:
                chapter_title = chapter.title
                lectures = chapter.get_lectures()
                lectures_count = chapter.lectures
                sys.stdout.write(
                    '\n' + fc + sd + "[" + fw + sb + "+" + fc + sd + "] : " + fw + sd + "Chapter (%s)\n" % chapter_title)
                sys.stdout.write(
                    fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sd + "Lecture(s) (%s).\n" % lectures_count)
                for lecture in lectures:
                    lecture_id = lecture.id
                    lecture_best = lecture.getbest()
                    lecture_streams = lecture.streams
                    lecture_assets = lecture.assets
                    if lecture_streams:
                        sys.stdout.write(fc + sd + "     - " + fy + sb + "duration   : " + fm + sb + str(
                            lecture.duration) + fy + sb + ".\n")
                        sys.stdout.write(fc + sd + "     - " + fy + sb + "Lecture id : " + fm + sb + str(
                            lecture_id) + fy + sb + ".\n")
                        for stream in lecture_streams:
                            content_length = stream.get_filesize()
                            if content_length != 0:
                                if content_length <= 1048576.00:
                                    size = round(float(content_length) / 1024.00, 2)
                                    sz = format(size if size < 1024.00 else size / 1024.00, '.2f')
                                    in_megabytes = 'KB' if size < 1024.00 else 'MB'
                                else:
                                    size = round(float(content_length) / 1048576, 2)
                                    sz = format(size if size < 1024.00 else size / 1024.00, '.2f')
                                    in_megabytes = "MB " if size < 1024.00 else 'GB '
                                if lecture_best.dimention[1] == stream.dimention[1]:
                                    in_megabytes = in_megabytes + fc + sb + "(Best)" + fg + sd
                                sys.stdout.write('\t- ' + fg + sd + "{:<23} {:<8}{}{}{}{}\n".format(str(stream), str(
                                    stream.dimention[1]) + 'p', sz, in_megabytes, fy, sb))
                                time.sleep(0.5)
                    if lecture_assets:
                        for asset in lecture_assets:
                            if asset.mediatype != 'external_link':
                                content_length = asset.get_filesize()
                                if content_length != 0:
                                    if content_length <= 1048576.00:
                                        size = round(float(content_length) / 1024.00, 2)
                                        sz = format(size if size < 1024.00 else size / 1024.00, '.2f')
                                        in_megabytes = 'KB' if size < 1024.00 else 'MB'
                                    else:
                                        size = round(float(content_length) / 1048576, 2)
                                        sz = format(size if size < 1024.00 else size / 1024.00, '.2f')
                                        in_megabytes = "MB " if size < 1024.00 else 'GB '
                                    sys.stdout.write(
                                        '\t- ' + fg + sd + "{:<23} {:<8}{}{}{}{}\n".format(str(asset), asset.extension,
                                                                                           sz, in_megabytes, fy, sb))