用Python从YouTube、SoundCloud等平台获取元数据和mrl [英] Get meta data and mrl from YouTube, SoundCloud and other platforms in Python

查看:48
本文介绍了用Python从YouTube、SoundCloud等平台获取元数据和mrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在使用 LibVLC 来获取在线视频和音乐的元数据和 mrl.但这只是为了获取这些信息而产生的大量愚蠢开销.

Currently i am using LibVLC to get the metadata and mrl of online Videos and Music. But this is a lot of stuppid overhead just to get this information.

...
from vlc import Instance as vlcInstance, MediaList, MediaListPlayer, Event, EventType, State
...
self.player = MediaListPlayer(vlcInstance(options))
...
        self.list = MediaList(self._mrls)
        self.player.set_media_list(self.list)
...
        media = self.player.get_media_player().get_media()
        if media.get_meta(1) is not None and self.trackChangedEventCallback is not None:
            self.trackChangedEventCallback(
                media.get_meta(0),  # Title
                media.get_meta(1),  # Artist
                media.get_meta(6),  # Description
                media.get_meta(10), # URL
                media.get_meta(15)  # Artlink
            )
        print(media.get_mrl()) # MRL
...

当然有适用于不同平台的软件包,但我不想用另一个替换一个愚蠢的开销.我快速查看了 VLC 的 youtube.lua 脚本,但没有找到一个好主意.LibVLC 是怎么做这个解析得到meta 和mrl 的?

Of course there are packages for different platforms but i don't want to replace one stupid overhead with another one. I have taken a quick look into the youtube.lua script of VLC but not found a good idea. How does LibVLC do this parsing to get the meta and mrl?

网页抓取是另一个想法,但在这一点上对我来说似乎不太可靠.

Webscraping was another idea but seems not very reliable to me at this point.

那么如何在不使用巨大开销的情况下执行与我的 LibVLC-Code 相同的操作?希望有一个基于 urllib 的工作解决方案或其他东西.

So how to do the same as my LibVLC-Code without using an huge overhead? Hopefully there is an urllib based working solution or something else.

非常感谢!:-)

可能重复:如何解析 YouTube 和 Soundcloud使用 python 和 LibVLC?

推荐答案

经过一些测试我决定使用 youtube_dl 因为它非常容易使用并且支持很多平台:http://ytdl-org.github.io/youtube-dl/supportedsites.html

After some testing i decided to use youtube_dl because it is very easy to use and supports a lot of platforms: http://ytdl-org.github.io/youtube-dl/supportedsites.html

这是我的示例代码:

#!/usr/bin/env python3
import youtube_dl as ydl

url = "https://www.youtube.com/watch?v=6qEzh3wKVJc"

with ydl.YoutubeDL(
    {
        "forcejson": True,
        "noplaylist": True,
        "format": "bestaudio"
    }
) as parser:
    meta = parser.extract_info(
        url,
        download=False
    )

print(meta['thumbnail'])
print(meta['title'])
print(meta['url'])

这篇关于用Python从YouTube、SoundCloud等平台获取元数据和mrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆