Esempio n. 1
0
def download_youtube(link):
	global sem	
	if(len(link)==0):
		return;
	fname=re.findall("\?v=(.*?)\&",link+"&")[0]
	try:
		if(len(re.findall("http",link))==0):
			link="http://"+link
		nl=re.findall("span id=\"eow-title\".*?title=\"(.*?)\"",urllib.urlopen(link).read())
		if(len(nl)==0): 
			nl=fname
		else:
		 	nl=nl[0]
	except:
		nl=fname
	infname=fname+".info.json"
	ninffile=nl+".info.json"
	if(chkexisting(os.path.join(CACHEFOLDER,fname))==True):
		shutil.move(os.path.join(CACHEFOLDER,fname),os.path.join(CACHEFOLDER,nl))
		shutil.move(os.path.join(CACHEFOLDER,infname),os.path.join(CACHEFOLDER,ninffile))
	if(chkexisting(os.path.join(CACHEFOLDER,nl))==False):
		loc=os.path.join(CACHEFOLDER,"%(id)s")
		fd=youtubedl.FileDownloader({"outtmpl":loc})
		for e in youtubedl.gen_extractors():
			fd.add_info_extractor(e)
		fd.download([link])
		shutil.move(os.path.join(CACHEFOLDER,fname),os.path.join(CACHEFOLDER,nl))
		shutil.move(os.path.join(CACHEFOLDER,infname),os.path.join(CACHEFOLDER,ninffile))
	addsong(os.path.join(CACHEFOLDER,nl),nl)
Esempio n. 2
0
def download_youtube(link):
	global sem
	if(len(link)==0):
		return;
#	print "DOWNLOADING       " + link
#	os.system("python youtube-dl "+link)
	fname=re.findall("\?v=(.*?)\&",link+"&")[0]
	print os.getcwd()+fname+".mp4"
	if not os.path.isfile(os.getcwd()+"/"+fname+".mp4") :
		fd=youtubedl.FileDownloader({"outtmpl":u'%(id)s.%(ext)s'})
		for e in youtubedl.gen_extractors():
			fd.add_info_extractor(e)
		fd.download([link])
	if(len(re.findall("http",link))==0):
		link="http://"+link
	nl=re.findall("span id=\"eow-title\".*?title=\"(.*?)\"",urllib.urlopen(link).read())

	if(len(nl)==0):
		namelist.append("nameless")
	else:
	 	namelist.append(nl[0])
#	print "NAME=====================================+++>" +nl[0]
	songlist.append(fname+".mp4")
	sem.release()