コード例 #1
0
def download_video_by_command(dtype, form, video, uri, *args):
	if dtype.lower() == 'video':
		try:
			# Get code
			if video.endswith('/'):
				video = video[:-1]
			video = video.split('/')[-1]
			download_video(form, vidme.Video(code=video), uri, *args)
		except Exception as e:
			print '[-] ERROR:', e
	elif dtype.lower() == 'album':
		# album_id - 90822
		album = vidme.Album(video)

		for video_to_download in album.get_videos():
			try:
				download_video(form, video_to_download, uri, *args)
			except Exception as e:
				print '[-] ERROR:', e
	elif dtype.lower() == 'user':
		# Get username
		if video.endswith('/'):
			video = video[:-1]
		video = video.split('/')[-1]

		user = vidme.User(video)

		for video_to_download in user.get_videos():
			# Has formats but only hls. >.>
			video_to_download = vidme.Video(video_to_download.get_full_url())
			try:
				download_video(form, video_to_download, uri, *args)
			except Exception as e:
				print '[-] ERROR:', e
コード例 #2
0
def upload_folder(directory, regex="*.mp4"):
	import glob

	directory = directory.replace('\\', '\\\\')

	videos = [
		vidme.Video(uri=video_uri)
		for video_uri in glob.glob(directory + "/"+ regex)
	]

	print videos

	for video in videos:
		video.upload(session)

		# Prepare for thumbnail
		video_dir = os.path.dirname(video.get_uri())
		video_name = os.path.splitext(os.path.basename(video.get_uri()))[0]

		# Try to get jpg thumbnail.
		# If no jpg, try png.
		video_thumb1 = video_dir + "/" + video_name + ".jpg"
		video_thumb2 = video_dir + "/" + video_name + ".png"

		if os.path.isfile(video_thumb1):
			video.set_thumbnail(video_thumb1)
		elif os.path.isfile(video_thumb2):
			video.set_thumbnail(video_thumb2)
コード例 #3
0
def upload_video(video_filename, title = "My Super Epic 1337 Video", thumbnail=None, category_id=None):
	if not session: 
		print "User is not set!"
		return

	print "[+] Uploading file:", video_filename

	# Create a new instance with the path to our file
	video = vidme.Video(uri = video_filename)

	# Upload our file and get if_successful
	video_upload = video.upload(session, title, no_output=False)

	if thumbnail:
		video.set_thumbnail(session, thumbnail)

	if category_id:
		video.set_channel(session, category_id)

	if video_upload:
		print "Video title:", video.get_title()
	else:
		print "[-] Failed to upload video."
コード例 #4
0
def add_video_to_album(album, url):
	return album.add_video(session, vidme.Video(url=url).get_video_id())
コード例 #5
0
def download_video(form, video, uri, *args):
	"""

		Helper functions START

	"""
	def _to_ascii(title):
		return ''.join([i if ord(i) < 128 and i.isalnum() else '-' for i in title])

	def _download_file(url, size=1024 * 3000, chunk_count=-1, no_output=False):
		count = 0.0
		start_time = time.time()

		try:
			file_size = float(url.info().getheaders('Content-Length')[0])
		except:
			file_size = 1.0

		if not no_output:
			print "[*] Dowloading in", size / 1000000.0, "MB sized chunks."

		while chunk_count < 0:
			data = url.read(size)
			count += len(data)
			if not data:
				break

			yield data

			if not no_output:
				per_left = count / file_size * 100.0

				out = "[*] Download at: {0:6.2f}%.".format(per_left)

				# Output and go up one line. This is so it auto updates.
				sys.stdout.write(out + "\r")

			chunk_count -= 1

		if not no_output:
			print "[*] Download at: {0:6.2f}%. Took: {1:7.2f} seconds.".format(
				100.0, time.time() - start_time
			)

	"""

		Helper functions END

	"""

	# Convert title to ascii.
	video.title = _to_ascii(video.get_title())

	# Get our URI path without extension.
	final_path = uri + '/' + video.get_title()

	if '--no-overwrites' in args or '-w' in args:
		if os.path.isfile(final_path + ".mp4"):
			print "[-] File exists. Not downloading."
			return False

	if uri.endswith('/') or uri.endswith('\\'):
		uri = uri[:-1]

	code = video.get_url()

	if not video._get_safe('formats'):
		video = vidme.Video(video.get_full_url())

	if '--no-download' not in args:
		forms = video.get_formats()

		if form not in forms:
			print "[-] Format not found! ", form
			return False
		else:
			print "[*] Downloading video:", video.get_title()

			url = forms[form]['uri']
			success = False

		try:
			video_url = urllib2.urlopen(url)

			# Open our local file for writing
			with open(final_path + ".mp4", "wb") as f:
				for c in _download_file(video_url):
					f.write(c)

			success = True
		except urllib2.HTTPError, e:
			print "HTTP Error:", e.code, url
		except urllib2.URLError, e:
			print "URL Error:", e.reason, url
コード例 #6
0
def get_video_by_code(code):
	# code = "Z47b"
	return vidme.Video(code = code)
コード例 #7
0
def get_video_by_video_id(video_id):
	# video_id = 14854593
	return vidme.Video(video_id = video_id)
コード例 #8
0
def get_video_by_url(url):
	# url = "https://vid.me/Z47b"
	return vidme.Video(url = url)