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


Python YouTube.url方法代码示例

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


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

示例1: yt_web

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [as 别名]
def yt_web(yt_id):
    video = YouTube()
    try:
        video.url = "http://youtube.com/watch?v=%s" % yt_id
    except:
        return render_template('404.html'), 404
    return render_template("webtable.html", videos=[("%s-%s" % (video.resolution, video.extension) , video.url) for video in video.videos])
开发者ID:MB6,项目名称:flask_yt,代码行数:9,代码来源:app.py

示例2: yt_api

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [as 别名]
def yt_api(yt_id):
    video = YouTube()
    try:
        video.url = "http://youtube.com/watch?v=%s" % yt_id
    except:
        return render_template('404.html'), 404
    return json.dumps({"%s-%s" % (video.resolution, video.extension) : video.url for video in video.videos})
开发者ID:MB6,项目名称:flask_yt,代码行数:9,代码来源:app.py

示例3: downloadSong

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [as 别名]
def downloadSong(url):
    video = pafy.new(url)
    best = video.getbest(preftype="mp4")
    yt = YouTube()
    yt.url = url
    os.system('cls') # os.system('clear') for linux.
    print "Download URL fetched successfully!\n"
    print "1. Get the list of available streams"
    print "2. Get the highest resolution available"
    print "3. Start download the video\n"

    while True:
        print "Select an action: "
        action = raw_input("> ")

        if action == str(1):
            print "Availabile streams for the URL: \n"
            pprint(yt.videos)
            print "\n"

        elif action == str(2):
            print "Highest resolution is:"
            pprint(yt.filter('mp4')[-1])
            print "\n"

        elif action == str(3):
            print "Starting download: \n"
            best.download(quiet=False)
            print "Download finished!, the file has been downloaded to the same folder where the script is located."
            sys.exit(0)

        else:
            print "Not a valid option!\n"
开发者ID:eleweek,项目名称:PyKo,代码行数:35,代码来源:PyKo.py

示例4: post_submit

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [as 别名]
def post_submit():
    yt = YouTube()
    url = request.form.get('url')
    yt.url = url
    video = yt.get('mp4', '360p')
    video.download('./')
    filename = yt.filename
    return redirect(url_for('index', filename=filename))
开发者ID:daniellllllll,项目名称:YoutuberDownloader,代码行数:10,代码来源:index.py

示例5: __init__

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [as 别名]
 def __init__(self,url):
     self.url = url
     yt = YouTube()
     yt.url = url
     video = yt.get('mp4', '480p')
     video = yt.get('mp4')
     video.download()
     self.name = (str(yt.filename) + ".mp4")
开发者ID:kaledj,项目名称:YTKeyframes,代码行数:10,代码来源:download.py

示例6: download

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [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

示例7: downloadFisicalFile

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [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

示例8: download

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [as 别名]
 def download(self, url):
     """
     Парсинг видео с ютуба
     :param url: урла с ютуба или еще откуда-то
     :return: возвращает true, если видео успешно загружено, в противном случае - возникнет исключение
     """
     yt = YouTube()
     yt.url = url
     video = yt.get('3gp', '144p', 'Simple')  # получаем видео в самом плохом качестве
     if not self.id:
         raise NameError('Не задан id для видеофайла!')
     video.filename = self.id
     video.download(self.PATH_TO_VIDEO)
     return True
开发者ID:ckcnik,项目名称:music-finder,代码行数:16,代码来源:models.py

示例9: download

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [as 别名]
def download(list):
    #read url of videos to download
    try:
        n = 0
        e = 0
        f = open(list, "r")
        rowcount = len(f.readlines())
        print str(rowcount) + " links in list....starting\n"
        data = [line.strip() for line in open(list, 'r')]
        while n <= rowcount:
            if len(data) >= 1:
                try:
                    yt = YouTube()
                    #download all videos contained in textfile
                    for item in data:

                        yt.url = item

                        #check if file already exists
                        cwd = os.path.dirname(os.path.realpath(__file__))
                        tmp = os.path.join(cwd, "tmp/")
                        fe = tmp + yt.filename + ".mp4"
                        if os.path.exists(fe) == False:
                            #assume there is atleast one mp4 file with 360p resolution
                            video = yt.get('mp4', '360p')
                            print "\r" + str(n) + " [+] downloading: " + yt.filename
                            #download into tmp folder
                            video.download('tmp/')
                            n += 1
                        else:
                            print "File [" + yt.filename + "] already exists, skipping dowload"
                            n += 1

                except any, e:
                    print "\n" + str(n) + " [-] could not download video: " + yt.filename
                    print "\rTry to download next video in list if theres any\n"
                    print e
                    n += 1
                    e += 1

            else:
                print "Textfile seems to be empty"
                os._exit(1)

    #print "\nDownloaded " + str((n - e)) + " videos of a total of " + str(n) + "\n" + str(e) + " errors occured"

    except any, e:
        print "Im sorry there occured an unhandeld exception."
        print e
开发者ID:niph,项目名称:pytube-extension,代码行数:51,代码来源:download.py

示例10: convert

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [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

示例11: download_yt_video

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [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

示例12: download

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [as 别名]
def download(url):
    """Download a single video

    Arguments:
        url - A single URL to download

    returns:
        None
    """
    if not url.startswith("http://"):
        return

    yt = YouTube()
    yt.url = url

    try:
        video = select_video(yt)
        _download(url, video)
    except ValueError as e:
        print("Failed to retrieve video: {0} - {1}".format(url, e))
    except HTTPError as e:
        print("Oops! Youtube said NO!: {0} - {1}".format(url, e))
开发者ID:cmdswitch,项目名称:ytwatch,代码行数:24,代码来源:ytdl.py

示例13: YouTube

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [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

示例14: ytdownload

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [as 别名]
def ytdownload():
  url = request.args.get('url')
  yt = YouTube()
  yt.url = url
  video = yt.filter('mp4')[0]
  return "/static/"+video.download().split('/')[2]
开发者ID:awishn02,项目名称:PyMusic,代码行数:8,代码来源:views.py

示例15: get_video_and_extension

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import url [as 别名]
def get_video_and_extension(url):
    youtube = YouTube()
    youtube.url = url
    extension = get_extension(youtube)
    return min(youtube.filter(extension=extension)), extension
开发者ID:harokb,项目名称:YouStream,代码行数:7,代码来源:ystream2.py


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