当前位置: 首页>>代码示例>>Python>>正文


Python YouTube.filename方法代码示例

本文整理汇总了Python中pytube.YouTube.filename方法的典型用法代码示例。如果您正苦于以下问题:Python YouTube.filename方法的具体用法?Python YouTube.filename怎么用?Python YouTube.filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pytube.YouTube的用法示例。


在下文中一共展示了YouTube.filename方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
def download(args):
	"""
	Downloads youtube video

	args		:	parsed command line arguments

	"""

	# Call the YoutTube Function
	youtube			=	YouTube()

	# Set the video url
	try:
		youtube.url		=	args['u']

	# Catch invalid YouTube URLs
	except YouTubeError:
		print "\n\nError:  Failed on ('{}').\nCheck for valid YouTube URL.\n\n".format(args['u'])
		exit(2)

	# Create menu of video format/resolution options
	video_option_selection	=	menu(map(str, youtube.videos))

	# Extract video types into a list of a single string
	video_format 		=	re.findall(r'\(.(\w{3,4})\)', video_option_selection)[0]
	video_resolution	=	re.findall(r'-\s*(\w{3,4})', video_option_selection)[0]

	# Set filename if -f/--filename option is given
	if args['f']:
		youtube.filename		=		args['f']

	# Set the video format	
	try:
		set_video_format_res	=	youtube.get(video_format, video_resolution)

	# Catch multiple videos returned error
	except MultipleObjectsReturned:
		print '\n\nError: More than one video returned.\n\n'
		exit(1)

	# Download video
	download_video		=	set_video_format_res.download(args['dir'],
						on_progress=print_status, 
						on_finish=video_to_mp3 if args['c'] else None)

	# Delete original video file if -do/--delete and -c/--convert is given
	if args['c'] and args['do']:
	
	# Call remove_original 
		remove_original(youtube.filename, args['dir'], video_format)
开发者ID:b-mcg,项目名称:YouPy,代码行数:52,代码来源:youpy.py

示例2: downloadFisicalFile

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
def downloadFisicalFile(youtubeId, idName):
	yt = YouTube()
	yt.url = ("http://www.youtube.com/watch?v=" + youtubeId)
	yt.filename = idName
	video = 0
	if len(yt.filter('mp4')) > 0:
		if len(yt.filter(resolution='720p')) > 0:
			video = yt.get('mp4','720p')
		else:
			video = yt.get('mp4')

		video.download("tempvideo/")
	else:
		cocomo.printJson("no se puede descargar el archivo", "error")
开发者ID:SpeakerBlack,项目名称:Raptor,代码行数:16,代码来源:track.py

示例3: convert

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
def convert():

    if (request.form):
        url = request.form['url']

        yt = YouTube()
        yt.url = url
        name = yt.filename.encode("UTF-8")
        yt.filename = base64.b64encode(name)


        mp4 = yt.filename
        mp3name = base64.b64decode(yt.filename)

        #check against db
        db = get_db()
        cur = db.execute('select id,timesdownloaded from songs where base64name=? order by id desc', (mp4+".mp3",))
        one = cur.fetchone()

        if(one):
            db.execute('update songs set timesdownloaded=?, lastdownload=? WHERE base64name=?',[one[1]+1, datetime.datetime.now(), mp4+'.mp3' ])
            db.commit()
            return jsonify({'location': 1, "name":mp3name+".mp3"})

        video = yt.get('mp4', '360p')
        video.download('/tmp/')


        call(["ffmpeg -i /tmp/"+mp4+".mp4 -b:a 128K -vn /tmp/"+mp4+".mp3"],shell=True)


        db = get_db()
        db.execute('insert into songs (songname, base64name, dateconverted, timesdownloaded, lastdownload) values (?, ?, ?, ?, ?)',
                 [mp3name+".mp3", mp4+".mp3", datetime.datetime.now(), 1, datetime.datetime.now()])

        db.commit()

        shutil.copy2("/tmp/"+mp4+".mp3", "static/songs/"+mp3name+".mp3")
        os.remove("/tmp/"+mp4+".mp3")
        os.remove("/tmp/"+mp4+".mp4")

        return jsonify({'location': 1, "name":mp3name+".mp3"})

    return jsonify({'message': "There was an error. Something is missing in input."})
开发者ID:goors,项目名称:youtubetomp3-flask,代码行数:46,代码来源:run.py

示例4: download_yt_video

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
def download_yt_video(yt_url, filename, path, sim=False):
    global needs
    global gots
    yt = YouTube()
    yt.url = yt_url
    yt.filename = u'{}'.format(filename.replace('/', '-').replace(':', ','))
    if os.path.isfile(os.path.join(path, u'{}.mp4'.format(yt.filename))):
        print('              Got it!')
        gots += 1
    else:
        if sim:
            print('              Need It!')
            needs += 1
        else:
            print('              Downloading... ', end='')
            max_res = yt.filter('mp4')[-1].resolution
            video = yt.get('mp4', max_res)
            video.download(path, verbose=False)
            print('Done!')
            gots += 1
开发者ID:johnnycakes79,项目名称:pyvideo_scraper,代码行数:22,代码来源:pyvideo_scraper.py

示例5: download_video_yt

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
def download_video_yt(link, output_path):
    """
    :param link: a Youtube link
    :param output_path: path where the downloaded video is saved
    :return:
    """
    try:
        video_folder = output_path  # folder where videos are put
        yt = YouTube(link)  # get the video
        video = yt.get('mp4', '360p')  # select the video in mp4 format
        yt.filename=re.sub(' ', '-', yt.filename)
        new_path=os.path.join(output_path, remove_accents(yt.filename))

        if not os.path.exists(new_path):  # We use this condition to see if the video has already been treated
            os.makedirs(new_path)
            yt.set_filename('Video')
            video.download(new_path)  # downloads the video

        return new_path  # return the path of the folder where the video has been downloaded
    except:
        print('The link is not valid !')
        return False
开发者ID:NicolasSchreuder,项目名称:SarkozyVectorMachine,代码行数:24,代码来源:Functions.py

示例6: _main

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
def _main():
    parser = argparse.ArgumentParser(description='YouTube video downloader')
    parser.add_argument("url", help="The URL of the Video to be downloaded")
    parser.add_argument("--extension", "-e",
                        help="The requested format of the video", dest="ext")
    parser.add_argument("--resolution", "-r",
                        help="The requested resolution", dest="res")
    parser.add_argument("--path", "-p",
                        help="The path to save the video to.", dest="path")
    parser.add_argument("--filename", "-f",
                        dest="filename",
                        help=("The filename, without extension, "
                              "to save the video in."))

    args = parser.parse_args()

    yt =  YouTube()
    try:
        yt.url = args.url
    except YouTubeError:
        print "Incorrect video URL."
        sys.exit(1)

    if args.filename:
        yt.filename = args.filename

    if args.ext and args.res:
        # There's only ope video that matches both so get it
        vid = yt.get(args.ext, args.res)
        # Check if there's a video returned
        if not vid:
            print "There's no video with the specified format/resolution combination."
            sys.exit(1)

    elif args.ext:
        # There are several videos with the same extension
        videos = yt.filter(extension=args.ext)
        # Check if we have a video
        if not videos:
            print "There are no videos in the specified format."
            sys.exit(1)
        # Select the highest resolution one
        vid = max(videos)
    elif args.res:
        # There might be several videos in the same resolution
        videos = yt.filter(res=args.res)
        # Check if we have a video
        if not videos:
            print "There are no videos in the specified in the specified resolution."
            sys.exit(1)
        # Select the highest resolution one
        vid = max(videos)
    else:
        # If nothing is specified get the highest resolution one
        vid = max(yt.videos)

    try:
        vid.download(path=args.path, on_progress=print_status)
    except KeyboardInterrupt:
        print "Download interrupted."
        sys.exit(1)
开发者ID:Oize,项目名称:python-youtube-download,代码行数:63,代码来源:pytube.py

示例7: StringIO

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
'''27 Jul 2015'''
from cStringIO import StringIO
import sys,io,os,time
global sys
import Tkinter as tk
from Tkinter import StringVar
from PIL import Image,ImageDraw,ImageFont,ImageTk
import numpy as np
global np,tk,Image,ImageDraw,ImageFont,ImageTk
global win,frame1,j,text,Picture1,Picture2,Picture2_1,Picture3,task,dotask,Font2,v
global Button,Button_im,Button_p,Button_im_p,Button_a,Button_im_a,Button_v,Button_im_v
if not os.path.isfile("9Things.mp4"):
	from pytube import YouTube
	yt=YouTube()
	yt.url="https://www.youtube.com/watch?v=4nP4PJL-9bg"
	yt.filename="9Things"
	video=yt.get('mp4')
	video.download()
FFMPEG_BIN = "ffmpeg.exe"
import subprocess as sp
Picture3=[]
old_stdout = sys.stdout
old_stderr = sys.stderr
sys.stdout = mystdout = StringIO()
sys.stderr = mystderr = StringIO()
for i in range(10):
	if os.path.isfile("out"+str(i)+".jpg"):
		# from StackOverflow.com Q#6996603 answer by RichieHindle 9 Aug 2011
		os.remove("out"+str(i)+".jpg")
	if i>5:
		ss=str((i-5)*10)
开发者ID:supotmaild,项目名称:activebutton,代码行数:33,代码来源:abutton.py

示例8: YouTube

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
from __future__ import print_function
from pytube import YouTube
from pprint import pprint



yt = YouTube()

yt.url = "http://www.youtube.com/watch?v=Ik-RsDGPI5Y"
pprint(yt.videos)
# view the auto generated filename:

print(yt.filename)
yt.filename = 'Dancing'
video = yt.get('mp4', '720p')
video.download('/home/user/') #video.download('/tmp/')
开发者ID:pj-parag,项目名称:pytube,代码行数:18,代码来源:testdl.py

示例9: YouTube

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
#!/usr/bin/python
import os, sys
from pprint import pprint

sys.path.insert(0, '.')

from pytube import YouTube

sys.stderr.write( 'ok' )

yt = YouTube()

# Set the video URL.
yt.url = "http://www.youtube.com/watch?v=Ik-RsDGPI5Y"
yt.url = sys.argv[1]

pprint(yt.videos)

print yt.filename

yt.filename = 'Dancing Scene from Pulp Fiction'

pprint(yt.filter('flv'))
pprint(yt.filter('mp4'))

print yt.filter('mp4')[-1]

video = yt.get('mp4', '720p')

video.download('/tmp/', fhd=sys.stdout)
开发者ID:sauloal,项目名称:PiCastPy,代码行数:32,代码来源:stream.py

示例10: YouTube

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
from __future__ import print_function
from pytube import YouTube

yt = YouTube()
# Set the video URL.
yt.url = raw_input("Enter url: ")
# yt.url = "http://www.youtube.com/watch?v=Ik-RsDGPI5Y"

print("Video Name: %s" % yt.filename)
yt.filename = "video"
video = yt.get("mp4", "720p")
video.download("video")
开发者ID:NoInfo07,项目名称:YouTubeToMp3,代码行数:14,代码来源:pytubetest.py

示例11: len

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
            'https://www.youtube.com/watch?v=jEpbjve5iHk', 'https://www.youtube.com/watch?v=tTihyXaz4Bo',
            'https://www.youtube.com/watch?v=2CdivtU5ytY', 'https://www.youtube.com/watch?v=ZvWftlp7TKY',
            'https://www.youtube.com/watch?v=WX03ODuzkSY', 'https://www.youtube.com/watch?v=Bcv46xKJH98',
            'http://egghead.io/lessons/angularjs-animating-with-javascript', 'http://egghead.io/lessons/angularjs-animating-the-angular-way',
            # 50 ... currently goes all the way to 77 with no more on YouTube
            )

    uris_len = len(uris)
    for idx, uri in enumerate(uris):
        print 'Processing: {0:02d} / {1}\n({2})\n'.format(idx+1, uris_len, uri)
        
        if uri[12:19] != 'youtube':
            continue   # Not a YouTube link, but we still need idx incremented for filenames
        
        yt = YouTube()
        yt.url = uri
        yt.filename = '{0:02d}{1}'.format(idx, yt.filename[23:])

        video = None
        if not video:
            video = yt.get('mp4', '1440p')
        if not video:
            video = yt.get('mp4', '1080p')
        if not video:
            video = yt.get('mp4', '720p')
        #if not video:
        #    exit("Couldn't find high-quality download")

        if video:
            video.download(realpath(''))
开发者ID:theharshbhatia,项目名称:Scrapping,代码行数:32,代码来源:bulk_youTube_downloader.py

示例12: VP8

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
# <Video: H.264 (.flv) - 480p>,
# <Video: H.264 (.mp4) - 360p>,
# <Video: H.264 (.mp4) - 720p>,
# <Video: VP8 (.webm) - 360p>,
# <Video: VP8 (.webm) - 480p>]

# The filename is automatically generated based on the video title.
# You can override this by manually setting the filename.

# view the auto generated filename:
print yt.filename

#Pulp Fiction - Dancing Scene [HD]

# set the filename:
yt.filename = 'minobrnauki_1.mp4'

# You can also filter the criteria by filetype.

pprint(yt.filter('flv'))

#[<Video: Sorenson H.263 (.flv) - 240p>,
# <Video: H.264 (.flv) - 360p>,
# <Video: H.264 (.flv) - 480p>]

# notice that the list is ordered by lowest resolution to highest. If you 
# wanted the highest resolution available for a specific file type, you
# can simply do: 
print yt.filter('mp4')[-1]
#<Video: H.264 (.mp4) - 720p>
开发者ID:TransparenCEE,项目名称:hubofdata,代码行数:32,代码来源:downl.py

示例13: enumerate

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import filename [as 别名]
  for count, x in enumerate(targetVid.videos, 1):
    v = x.video_codec
    e = x.extension
    r = x.resolution
    vDict.update({count:[v, e, r]})
    print("{}. Format: {:<20} || Extension: .{:<20} || Resolution: {:^10}".format(count, v, e, r))

  try:
    videoKey = input("Select the number of the video:> ")
    assert re.match(r"^[^a-zA-Z]", videoKey), "Ambiguous Entry."
    videoKey = int(videoKey)
    assert videoKey in vDict.keys(), "Invalid Number"
  except (AssertionError, ValueError):
    print("Expected a number from the provided list.")
    sys.exit()
  targetVid.filename = input("Save file as:> ")
  targetVid.filename = targetVid.filename + "." + vDict[videoKey][1]
  video = targetVid.get(vDict[videoKey][1], vDict[videoKey][2])
  downloadOK = input("Download(yes-ok/no):> ")
  if not re.match(r"(yes|ok)", downloadOK):
    sys.exit()
  else:
    try:
      downloadURL(targetVid.filename, video.url)
      sys.stdout.write(chr(27) + "[?25h")
    except KeyboardInterrupt:
      print("\nDeleteing file....")
      os.remove(targetVid.filename)
      sys.stdout.write(chr(27) + "[?25h")
      sys.exit()
开发者ID:abdalla-alothman,项目名称:fetchVideo,代码行数:32,代码来源:fetchVideo.py


注:本文中的pytube.YouTube.filename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。