예제 #1
0
def Convert():
	Folder = raw_input('Nhap thu muc can chuyen doi [DOWNLOAD]: ')
	if Folder == "":
		Folder = os.path.join(g_CurrentDir, "DOWNLOAD")
	ffmpeg.ConvertInFolder(Folder)
예제 #2
0
def DonwloadLessions():
	print ""
	email = raw_input(' Email: ')
	password = raw_input(' Password: '******' (%s)$: ' % email)
	try:
		lenCourses = len(Courses)
		index = int(rawOption) - 1
		if index > lenCourses:
			index = lenCourses - 1
		if index < 0:
			index = 0
		course = Courses[index]
	except ValueError:
		print " Lam on nhap SO"
		return

	DirDownload = os.path.join(g_CurrentDir, "DOWNLOAD")
	if not os.path.exists(DirDownload): os.mkdir(DirDownload)
	print 30*"="
	print ""
	print course[1]
	pathDirCourse = os.path.join(DirDownload, removeCharacters(course[1], '.<>:"/\|?*\r\n'))
	if not os.path.exists(pathDirCourse): os.mkdir(pathDirCourse)
	pathDirComplete = os.path.join(pathDirCourse, "complete")
	if not os.path.exists(pathDirComplete): os.mkdir(pathDirComplete)
	
	#DirDocuments = os.path.join(pathDirComplete, "Documents")
	#if not os.path.exists(DirDocuments): os.mkdir(DirDocuments)
	
	Lessions = GetLessions(course[0])
	if not Lessions: return
	print "Danh sach cac bai giang: "
	i = 1
	for Lession in Lessions:
		print "\t %d. %s" % (i, Lession[1])
		i += 1

	print "\n  Lua chon tai ve cac bai giang"
	print "  Vd: 1, 2 hoac 1-5, 7"
	print "  Mac dinh la tai ve het\n"

	rawOption = raw_input(' >> ')

	LessionsDownload = Lessions
	if rawOption != "":
		try:
			LessionsDownload = []
			option = rawOption.split(",")
			lenLessions = len(Lessions)
			for i in option:
				if i.find("-") != -1:
					c = i.split("-")
					c = map(int, c)
					c[0] -= 1
					if c[0] < 0:
						c[0] = 0
					LessionsDownload += Lessions[c[0]:c[1]]
				else:
					index = int(i) - 1
					if index > lenLessions - 1:
						index = lenLessions - 1
					if index < 0:
						index = 0
					LessionsDownload.append(Lessions[index])
			LessionsDownload = list(set(LessionsDownload))
		except ValueError:
			print ">>> Lam on nhap so."
			return

	try:
		NumOfThread = raw_input(' So luong download cung luc [5]: ')
		if NumOfThread == "":
			NumOfThread = 5
		NumOfThread = int(NumOfThread)
	except ValueError:
		print ">>> Nhap so"
		return

	IsConvert = False
	Convert = raw_input(' Convert Ts to Mp4 [yes]: ')
	if (Convert == "") or (Convert.lower() == "yes") or (Convert.lower() == 'y'):
		IsConvert = True

	listPathDirLession = []
	for Lession in LessionsDownload:
		print Lession[1]
		pathDirLession = os.path.join(pathDirCourse, removeCharacters(Lession[1], '.<>:"/\|?*\r\n'))
		if not os.path.exists(pathDirLession): os.mkdir(pathDirLession)
		listPathDirLession.append(pathDirLession)	
		urlVideo, urlDocuments = GetUrlMasterPlaylistFromLession(Lession[0])
	
		if not urlVideo: continue
		'''
		if urlDocuments:
			threadDownloadDocument = threading.Thread(target = DownloadDocuments, args = (urlDocuments, DirDocuments))
			threadDownloadDocument.setDaemon(True)
			threadDownloadDocument.start()
		'''

		urlM3u8HD =  GetM3u8HD(urlVideo)
		if not urlM3u8HD: continue

		listUrlTs = GetPlaylist(urlM3u8HD, True, pathDirLession)
		if not listUrlTs: continue
		listOfThread = []
		for i in range(NumOfThread):
			l = listUrlTs[i::NumOfThread] 
			thread = threading.Thread(target = DownloadTss, args = (l, pathDirLession))
			thread.setDaemon(True)
			thread.start()
			listOfThread.append(thread)

		for thread in listOfThread:
			thread.join()
		#threadDownloadDocument.join()

		time.sleep(10)
		
	print 40*"="
	
	if IsConvert:
		print "Converting ..."
		for i in listPathDirLession:
			ffmpeg.ConvertInFolder(i)