📌  相关文章
📜  Pafy – 获取每个播放列表项目的元数据

📅  最后修改于: 2022-05-13 01:54:22.651000             🧑  作者: Mango

Pafy – 获取每个播放列表项目的元数据

在本文中,我们将了解如何获取 pafy 中每个播放列表项的元数据。 Pafy 是一个Python库,用于下载 YouTube 内容和检索元数据。 Pafy 对象是包含有关给定视频的所有信息的对象。 YouTube 中的播放列表是一个按顺序播放的视频列表或一组视频,一个视频接一个视频。元数据是“提供有关其他数据的信息的数据”。换句话说,它是“关于数据的数据”。存在许多不同类型的元数据,包括描述性元数据、结构元数据、管理元数据、参考元数据和统计元数据。

我们可以借助get_playlist方法从 youtube 中获取播放列表,下面是执行此操作的命令

pafy.get_playlist(url)

播放列表 url 应该存在于 youtube 上,因为它会获取 youtube 上存在的那些视频的信息。 YouTube 是美国的在线视频分享平台。

下面是实现

# importing pafy
import pafy 
    
# url of playlist
url = "https://www.youtube.com / playlist?list = PLqM7alHXFySGqCvcwfqqMrteqWukz9ZoE"
  
# getting playlist
playlist = pafy.get_playlist(url)
  
# getting playlist items
items = playlist["items"]
  
# selecting single item
item = items[1]
  
# getting pafy object
i_pafy = item['pafy']
      
# getting meta data
metadata = item['playlist_meta']
  
# printing meta data
print(metadata)

输出 :

{'added': '06/01/2016', 'is_cc': False, 'is_hd': True, 'likes': 1111, 'title': 'Write a program to print all permutations of a given string | GeeksforGeeks', 'views': '334, 905', 'rating': 4.0, 'author': 'GeeksforGeeks', 'user_id': '0RhatS1pyxInC00YKjjBqQ', 'privacy': 'public', 'start': 0.0, 'dislikes': 227, 'duration': '11:52', 'comments': '116', 'keywords': '', 'thumbnail': 'https://i.ytimg.com/vi/AfxHGNRtFac/default.jpg', 'cc_license': False, 'category_id': 22, 'description': 'Explanation for the Article: https://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/\n\nThis video is contributed by Sephiri.\n#geeksforgeeks', 'encrypted_id': 'AfxHGNRtFac', 'time_created': 1490874673, 'time_updated': None, 'length_seconds': 712, 'end': 712}

另一个例子

# importing pafy
import pafy 
    
# url of playlist
url = "https://www.youtube.com / playlist?list = PLqM7alHXFySE71A2bQdYp37vYr0aReknt"
    
# getting playlist
playlist = pafy.get_playlist(url)
  
# getting playlist items
items = playlist["items"]
  
# selecting single item
item = items[2]
  
# getting meta data
metadata = item['playlist_meta']
  
# printing meta data
print(metadata)

输出 :

{'added': '27/09/2017', 'is_cc': True, 'is_hd': True, 'likes': 192, 'title': 'Find subarray with given sum | Set 1 (Non-negative Numbers) | GeeksforGeeks', 'views': '32, 716', 'rating': 3.0, 'author': 'GeeksforGeeks', 'user_id': '0RhatS1pyxInC00YKjjBqQ', 'privacy': 'public', 'start': 0.0, 'dislikes': 78, 'duration': '2:50', 'comments': '24', 'keywords': 'GeeksforGeeks Programming Algorithms "Data Structures" Coding Tutorial array "non-negative numbers"', 'thumbnail': 'https://i.ytimg.com/vi/GY-KULykGaw/default.jpg', 'cc_license': False, 'category_id': 27, 'description': "Find Complete Code at GeeksforGeeks Article: https://www.geeksforgeeks.org/find-subarray-with-given-sum/\n\nPractice Problem Online Judge: http://practice.geeksforgeeks.org/problems/subarray-with-given-sum/0\n\nThis video is contributed by Shubham Kumar\n\nPlease Like, Comment and Share the Video among your friends.\n\nAlso, Subscribe if you haven't already! :)", 'encrypted_id': 'GY-KULykGaw', 'time_created': 1506577926, 'time_updated': None, 'length_seconds': 170, 'end': 170}