pythonvlclibvlcpython-vlc

How to get audiostream metadata using vlc.py


for a little project I need to get the metadata(mainly title and artist) from songs on audio streams, for this I am using the vlc python library. This is my code with a Belgian radio station as an example:

import vlc
def getData(url):
    Instance = vlc.Instance()
    player = Instance.media_player_new()
    Media = Instance.media_new(url)
    Media.get_mrl()
    player.set_media(Media)
    player.play()
    return player.audio_get_track_description()

print(getData("http://icecast.vrtcdn.be/mnm-high.mp3"))

But all I get is an empty array: []

I got a part of the code from another stackoverflow thread and am not entirely sure on how it works: https://stackoverflow.com/a/34244909/14788941

How can I solve this?


Solution

  • The media has to have been parsed before the meta information is available.
    On these webcasts, it appears the only way to do this is play it and then the meta item to check is NowPlaying. The Title comes back with a generic string, something like Title 1.
    To add to the misery, callback events registered on vlc.EventType.MediaMetaChanged don't seem to be activated.

    A quick look as follows:

    import vlc
    import time
    
    def getData(url):
        Instance = vlc.Instance()
        player = Instance.media_player_new()
        Media = Instance.media_new(url)
        Media.get_mrl()
        player.set_media(Media)
        player.play()
        prev = ""
        while True:
            time.sleep(1)
            m = Media.get_meta(12) # vlc.Meta 12: 'NowPlaying',
            if m != prev:
                print("Now playing", m)
                prev = m
        return player.audio_get_track_description()
    
    print(getData("http://icecast.vrtcdn.be/mnm-high.mp3"))
    

    Right now, this has given:

    Now playing None
    [00007fc830005ab0] prefetch stream error: unimplemented query (264) in control
    Now playing JUSTIN BIEBER feat. LUDACRIS - BABY
    Now playing LAUV & ANNE-MARIE - FUCK, I'M LONELY
    Now playing MODJO - LADY (HEAR ME TONIGHT)
    Now playing MILOW - AYO TECHNOLOGY