0

I tried to build a small webradio with pyhton-vlc. When I directly write the url of the radiostream in the code everything works fine. But I would like to read the urls from the "radiostationen.txt". But when I replace the hard coded url with the first entry of the urls list I get the following error from the vlc-media-player: "VLC is unable to open the MRL 'https://stream.liferadio.tirol/live/mp3-192".

The python code:

import vlc
import keyboard

volume = 10

with open('radiostationen.txt') as f:
    urls = f.readlines()

url = urls[0]

instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
player=instance.media_player_new()
media=instance.media_new(url)
media.get_mrl()
player.audio_set_volume(volume)
player.set_media(media)
player.play()

The radiostationen.txt:

https://stream.liferadio.tirol/live/mp3-192
https://orf-live.ors-shoutcast.at/tir-q2a
https://orf-live.ors-shoutcast.at/fm4-q2a

If I use url = "https://stream.liferadio.tirol/live/mp3-192" instead of url = urls[0] it works.

Also the link in the error works.

1
  • 1
    readlines retains the newline character (\n) at the end of each entry in its returned value. Does url = urls[0].rstrip() work? Commented Feb 20, 2023 at 10:22

1 Answer 1

0

The readline and readlines methods retain the newline character (\n) at the end of the lines they read.

You need to strip off this character before passing the URL to VLC, e.g. url = urls[0][:-1] or url = urls[0].rstrip() should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.