Exemplo n.º 1
0
def load_meta(v) :
	v['max_res']  = ""	# This is default if any of the exceptions skip filling them.
	v['filesize'] = 0 
	v['title']    = "" if not v.has_key('title') else v['title'] 
	
	if(v['title'] in unavail_list): 
		return v 
	try : 
		vmeta = load_video_meta(v['vid'],True) 
	except ytd_exception_meta as e:  
		v['max_res'] = e.vidmeta['max_res'] if e.vidmeta.has_key('max_res') else "" 
		v['author']  = e.vidmeta['author'] if e.vidmeta.has_key('author') else "" 
		v['filesize'] = 0 
		v['flags'] = "" 
		return v
	except ValueError: 	## need to debug.. jsonload gets many a times. 
		return v 

	v['max_res'] = str(vmeta['max_res']) 
	v['author']  = vmeta['author'] 
	
	flags = "V" if vmeta['type'] == "video" else "A"
	flags = flags + "-$" if (vmeta['paid'] == True) else flags  
	flags = flags + "-x" if (vmeta['isFamilyFriendly'] == True) else flags 

	v['flags'] = flags

	status_update(v['index'],v['vid'],v['title']) 
	return v 
Exemplo n.º 2
0
def download_video(vid,folder):
	logr = setup_vid_logger(vid) 

	try:
		vidmeta = load_video_meta(vid)
	except ytd_exception_meta as e: 
		if (e.errtype == "PAGE_FETCH_ERR"): 
			logr.critical("\t{} :{}".format(e.errmsg,e.msgstr))
		if (e.errtype == "YOUTUBE_ERROR"): 
			logr.critical(e.errmsg) 
			logr.info("-"*45+"\n"+e.msgstr+"\n"+"-"*45) 
		if (e.errtype == "BAD_PAGE") : 
			logr.critical("\t"+e.errmsg) 
			print_pretty(logr,"Parsing failed: vid_meta "+"="*20,e.vidmeta) 
		if (e.errtype == "NO_STREAMS") : 
			logr.info("\tTitle:'%s'\n\tAuthor:'%s'",e.vidmeta['title'],e.vidmeta['author'])  
			logr.critical("\t"+e.errmsg) 
			print_pretty(logr,"Parsing failed: vid_meta "+"="*20,e.vidmeta) 
				
		if(deep_debug): 
			write_to_file(vid+".html",e.page['contents']) 
		return 

	print_pretty(logr,"Parsing successful: vid_meta "+"="*20,vidmeta) 

	smap = vidmeta['stream_map']
	sm = smap['std'] + smap['adp_v'] + smap['adp_a'] + smap['caption'] 
	logr.debug("= Available Streams: "+"="*25+"\n"+"\n".join(map(smap_to_str,sm)))
	 
	vidmeta['select_map'] = sl =  select_best_stream(smap) 
	logr.debug("= Selected Streams: "+"="*25+"\n"+"\n".join(map(smap_to_str,sl))+"\n")  

	# stream_map, select_map can be public elements so that they can be logged and print outside. 
	logr.info("\tTitle:'%s'\n\tAuthor:'%s'",vidmeta['title'],vidmeta['author'])  
	download_streams(vidmeta,folder)	
	download_caption(vidmeta,folder)
	logr.info("\tFetch Complete @ %s ----------------",str(datetime.datetime.now()))

	return