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


Python YouTube.get_video_data方法代码示例

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


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

示例1: get_song_info

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import get_video_data [as 别名]
def get_song_info(given_url="", local_dir=cur_dir, quality=1):
    """Returns song info for given YouTube url"""
    url = is_valid_youtube_url(given_url)
    yt = YouTube(url)
    raw_info = yt.get_video_data()
    if 'args' in raw_info:
        song_info = copy.copy(empty_record)
        song_info['url'] = url
        song_info['title'] = raw_info['args']['title']
        song_info['author'] = raw_info['args']['author']
        try:
            song_info['video_id'] = raw_info['args']['vid']
        except KeyError:
            song_info['video_id'] = url.replace(youtube_base_url, '')
        song_info['duration'] = int(raw_info['args']['length_seconds'])
        song_info['view_count'] = int(raw_info['args']['view_count'])
        song_info['thumbnail_url'] = raw_info['args']['thumbnail_url']
        filter_index = get_filter_index(quality, len(yt.filter()))
        video = yt.filter()[filter_index]
        local_file_name = "{0}.{1}".format(yt.filename, video.extension)
        local_file_path = os.path.join(local_dir, local_file_name)
        if os.path.exists(local_file_path):
            song_info['local_file_path'] = local_file_path
        return song_info
    else:
        return None
开发者ID:ashishnitinpatil,项目名称:internalRadio,代码行数:28,代码来源:utilities.py

示例2: TestYouTube

# 需要导入模块: from pytube import YouTube [as 别名]
# 或者: from pytube.YouTube import get_video_data [as 别名]
class TestYouTube(unittest.TestCase):
	'''Test all methods of Youtube class'''

	def setUp(self):
		'''Set up the all attributes required for a particular video'''

		self.url="https://www.youtube.com/watch?v=Ik-RsDGPI5Y"
		self.video_id = 'Ik-RsDGPI5Y'
		self.filename = 'Pulp Fiction - Dancing Scene'
		self.yt = YouTube(self.url)
		#: don't hard code, make is universal
		self.videos = ['<Video: MPEG-4 Visual (.3gp) - 144p - Simple>',
 					   '<Video: MPEG-4 Visual (.3gp) - 240p - Simple>',
					   '<Video: Sorenson H.263 (.flv) - 240p - N/A>',
					   '<Video: H.264 (.mp4) - 360p - Baseline>',
				       '<Video: H.264 (.mp4) - 720p - High>',
					   '<Video: VP8 (.webm) - 360p - N/A>']
		# using flv since it has only once video
		self.flv = '<Video: Sorenson H.263 (.flv) - 240p - N/A>'

	def test_url(self):

		self.assertEqual(self.yt.url ,self.url)

	def test_video_id(self):

		self.assertEqual(self.yt.video_id, self.video_id )

	def test_filename(self):

		self.assertEqual(self.yt.filename, self.filename)

	def test_get_videos(self):

		self.assertEqual ( map( str, self.yt.get_videos() ), self.videos )

	def test_get_video_data(self):

		self.assertEqual((self.yt.get_video_data()['args']['loaderUrl']),
						  self.url)
		                                        
	def test_get_false(self):
	    with self.assertRaises(MultipleObjectsReturned):
	        self.yt.get()

	def test_get_true(self):
		self.assertEqual( str( self.yt.get('flv') ), self.flv )

	def test_filter(self):
		self.assertEqual( str( self.yt.filter('flv')[0] ), self.flv )
开发者ID:garg10may,项目名称:pytube,代码行数:52,代码来源:test.py


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