Exemple #1
0
	def __init__(it, logger=None, dst_dn=None):
		it.iddle = True
		it.downloading = False
		it.start_time = t_s()
		it.size = None
		it.vidid = ''
		it.logger = logger
		it.dst_dn = dst_dn
		it.lenght = it.done = 0
Exemple #2
0
	def go(it, vidid, reslimit):
		if it.iddle==False:
			_dbg("Busy")
			return True # busy
		it.iddle = False
		it.done = 0
		it.vidid = vidid
		try:
			resp = urlopen("https://www.youtube.com/get_video_info?video_id=%s" % vidid)
		except HTTPError as e:
			it.logger("\nThe server couldn\'t fulfill the request.\n")
			it.logger("Error code: %s\n" % str(e.code))
		except URLError as e:
			it.logger("\nWe failed to reach a server.\n")
			it.logger("Reason: %s\n" % str(e.reason))
		else:
			data = resp.read()
			resp.close()
			info = parse_qs(data)
			if info.has_key('title') and info.has_key('url_encoded_fmt_stream_map'):
				it.title = info['title'][0]
				_dbg("Downloading %s\n" % it.title)
				dst_fn = "%s/%s-%s.mp4" % (it.dst_dn, it.title.replace('/', '_'), vidid)
				stream_map = info['url_encoded_fmt_stream_map'][0]
				for v_info in stream_map.split(','):
					item = parse_qs(v_info)
					tags = 'quality type url'.split()
					if not(False in map(lambda key: item.has_key(key), tags)):
						_dbg('\n'.join(map(lambda tag: item[tag][0], tags))+'\n')
						url = item['url'][0]
						try:
							h_url = urlopen(url)
						except HTTPError as e:
							it.logger("\nThe server couldn\'t fulfill the request.\n")
							it.logger("Error code: %s\n" % str(e.code))
						except URLError as e:
							it.logger("\nWe failed to reach a server.\n")
							it.logger("Reason: %s\n" % str(e.reason))
						else:
							_dbg("%s\n" % h_url.headers)
							lenght = int(h_url.headers['Content-Length'])
							if lenght:
								it.lenght = lenght
								it.start_time = t_s()
								it.route_fd(h_url, dst_fn)
								break
		it.iddle = True
		return False