How to play a video from url in a terminal in python

  Kiến thức lập trình

I wanted to play a anime in my terminal and i got to write a simple url finder, but i am struck as i don’t know how to play the video in my terminal.

I used this website:https://www2.gogoanime.ma/category/ as my base url and any name of the show will be changed to lowercase and add to the base url.

raw_show = input("Enter the show name: ")
show_name = raw_show.lower().replace(' ', '-')
url = base_url + show_name
print("URL:", url)

it works, but i don’t know how i am going to play this without interacting with the webpage as directly and i wanted to play it in my terminal using vlc as my player and try to got to this:

import vlc

base_url = "https://www2.gogoanime.ma/category/"

raw_show = input("Enter the show name: ")
show_name = raw_show.lower().replace(' ', '-')
url = base_url + show_name
print("URL:", url)

# Create a VLC media player     
player = vlc.MediaPlayer()

# Load the URL into the media player
media = vlc.Media(url)
player.set_media(media)

# Start playing the media
player.play()

# Wait for playback to finish
while True:
    state = player.get_state()
    if state in (vlc.State.Ended, vlc.State.Stopped, vlc.State.Error):
        break

# Release the media player resources
player.release()

LEAVE A COMMENT