Ejemplo n.º 1
0
	def course_list_down(self):
		if not self.organization:
			sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Trying to login as " + fm + sb +"(%s)" % (self.username) +  fg + sb +"...\n")
		if self.organization:
			sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Trying to login as organization " + fm + sb +"(%s)" % (self.organization) +  fg + sb +"...\n")
		course = lynda.course(url=self.url, username=self.username, password=self.password, organization=self.organization)
		course_id = course.id
		course_name = course.title
		chapters = course.get_chapters()
		total_lectures = course.lectures
		total_chapters = course.chapters
		assets = course.assets
		sys.stdout.write (fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Course " + fb + sb + "'%s'.\n" % (course_name))
		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-%s)\n" % (chapter_title, chapter_id))
			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_subtitles = lecture.subtitles
				lecture_best = lecture.getbest()
				lecture_streams = lecture.streams
				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))
		if assets and len(assets) > 0:
			for asset in assets:
				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))
Ejemplo n.º 2
0
	def course_list_down(self):
		if not self.organization:
			sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Trying to login as " + fm + sb +"(%s)" % (self.username) +  fg + sb +"...\n")
		if self.organization:
			sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Trying to login as organization " + fm + sb +"(%s)" % (self.organization) +  fg + sb +"...\n")
		course = lynda.course(url=self.url, username=self.username, password=self.password, organization=self.organization)
		course_id = course.id
		course_name = course.title
		chapters = course.get_chapters()
		total_lectures = course.lectures
		total_chapters = course.chapters
		asset = course.asset
		sys.stdout.write (fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Course " + fb + sb + "'%s'.\n" % (course_name))
		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-%s)\n" % (chapter_title, chapter_id))
			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_subtitles = lecture.subtitles
				lecture_best = lecture.getbest()
				lecture_streams = lecture.streams
				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))
		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\n".format(str(asset), asset.extension, sz, in_MB, fy, sb))
Ejemplo n.º 3
0
	def course_download(self, path='', quality='', caption_only=False, skip_captions=False):
		if self.cookies:
			sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Trying to login using cookies ...\n")
		if not self.cookies:
			if not self.organization:
				sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Trying to login as " + fm + sb +"(%s)" % (self.username) +  fg + sb +"...\n")
			if self.organization:
				sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Trying to login as organization " + fm + sb +"(%s)" % (self.organization) +  fg + sb +"...\n")
		course = lynda.course(url=self.url, username=self.username, password=self.password, organization=self.organization, cookies=self.cookies)
		course_id = course.id
		course_name = course.title
		chapters = course.get_chapters()
		total_lectures = course.lectures
		total_chapters = course.chapters
		assets = course.assets
		sys.stdout.write (fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Course " + fb + sb + "'%s'.\n" % (course_name))
		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)
		course.course_description(filepath=course_path)
		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)
			status = 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_subtitles = lecture.subtitles
				lecture_best = lecture.getbest()
				lecture_streams = lecture.streams
				if caption_only and not skip_captions:
					self.download_captions_only(subtitle=lecture_subtitles, filepath=filepath)
				elif skip_captions and not caption_only:
					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, filepath=filepath)
				else:
					lecture_best = lecture.get_quality(best_quality=lecture_best, streams=lecture_streams, requested=quality)
					self.download_lectures_and_captions(lecture_best=lecture_best, lecture_title=lecture_title, inner_index=lecture_index, lectures_count=lectures_count, subtitle=lecture_subtitles, filepath=filepath)
		if assets and len(assets) > 0:
			for asset in assets:
				self.download_assets(assets=asset, filepath=course_path)
Ejemplo n.º 4
0
	def course_download(self, path='', quality='', caption_only=False, skip_captions=False):
		if self.cookies:
			sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Trying to login using cookies ...\n")
		if not self.cookies:
			if not self.organization:
				sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Trying to login as " + fm + sb +"(%s)" % (self.username) +  fg + sb +"...\n")
			if self.organization:
				sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Trying to login as organization " + fm + sb +"(%s)" % (self.organization) +  fg + sb +"...\n")
		course = lynda.course(url=self.url, username=self.username, password=self.password, organization=self.organization, cookies=self.cookies)
		course_id = course.id
		course_name = course.title
		chapters = course.get_chapters()
		total_lectures = course.lectures
		total_chapters = course.chapters
		assets = course.assets
		sys.stdout.write (fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb + "Course " + fb + sb + "'%s'.\n" % (course_name))
		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)
		course.course_description(filepath=course_path)
		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)
			status = 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_subtitles = lecture.subtitles
				lecture_best = lecture.getbest()
				lecture_streams = lecture.streams
				if caption_only and not skip_captions:
					self.download_captions_only(subtitle=lecture_subtitles, filepath=filepath)
				elif skip_captions and not caption_only:
					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, filepath=filepath)
				else:
					lecture_best = lecture.get_quality(best_quality=lecture_best, streams=lecture_streams, requested=quality)
					self.download_lectures_and_captions(lecture_best=lecture_best, lecture_title=lecture_title, inner_index=lecture_index, lectures_count=lectures_count, subtitle=lecture_subtitles, filepath=filepath)
		if assets and len(assets) > 0:
			for asset in assets:
				self.download_assets(assets=asset, filepath=course_path)
Ejemplo n.º 5
0
    def course_download(self, path='', quality='', caption_only=False, skip_captions=False, target_folder = ''):
        if self.cookies:
            sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd +
                             "] : " + fg + sb + "Trying to login using cookies ...\n")
        if not self.cookies:
            if not self.organization:
                sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb +
                                 "Trying to login as " + fm + sb + "(%s)" % (self.username) + fg + sb + "...\n")
            if self.organization:
                sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sb +
                                 "Trying to login as organization " + fm + sb + "(%s)" % (self.organization) + fg + sb + "...\n")
        course = lynda.course(url=self.url, username=self.username, password=self.password,
                              organization=self.organization, cookies=self.cookies)
        course_id = course.id

        if target_folder != '':
	        downloaded_file_path = "{target_folder}/downloaded.txt".format(target_folder=target_folder)
	        if self.is_downloaded(downloaded_file_path, course_id):
	        	print("Course has been downloaded already! Skip")
	        	return

        course_name = course.title
        course_name = course_name.replace(":", "_")
        course_name = course_name.replace("|", "-")
        course_name = course_name.replace("/", "-")
        chapters = course.get_chapters()
        total_lectures = course.lectures
        total_chapters = course.chapters
        assets = course.assets

        sys.stdout.write(fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " +
                         fg + sb + "Course " + fb + sb + "'%s'.\n" % (course_name))
        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))

        tags_str = ""
        for tag in course.tags:
        	tag = tag.replace("/", "-")
        	tags_str = tags_str + "("+tag+")"
        if len(course.tags) > 0:
        	course_name = course_name + " -- Skills" + tags_str

        course_name = "(" + str(course_id) + ") " + course_name

        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)

        if target_folder != '':
        	target_path = target_folder + '/' + course_name

        # Clean up
        if os.path.exists(course_path):
            shutil.rmtree(course_path)

        course.course_description(filepath=course_path)
        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)

            status = 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_subtitles = lecture.subtitles
                lecture_best = lecture.getbest()
                lecture_streams = lecture.streams
                if caption_only and not skip_captions:
                    self.download_captions_only(
                        subtitle=lecture_subtitles, filepath=filepath)
                elif skip_captions and not caption_only:
                    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, filepath=filepath)
                else:
                    lecture_best = lecture.get_quality(
                        best_quality=lecture_best, streams=lecture_streams, requested=quality)
                    self.download_lectures_and_captions(lecture_best=lecture_best, lecture_title=lecture_title,
                                                        inner_index=lecture_index, lectures_count=lectures_count, subtitle=lecture_subtitles, filepath=filepath)
        if assets and len(assets) > 0:
            for asset in assets:
                self.download_assets(assets=asset, filepath=course_path)

        if target_folder != '':
	        # move files to target folder
	        if os.path.exists(target_path):
	            shutil.rmtree(target_path)
	        print("* Moving files from " + course_path + " to " + target_folder)
	        shutil.move(course_path, target_folder)
	        self.update_downloaded(downloaded_file_path, course_id)