Skip to content

Instantly share code, notes, and snippets.

@carlosplanchon
Created November 5, 2018 06:51
Show Gist options
  • Save carlosplanchon/128f6bd1908736a41683e4774db9e21a to your computer and use it in GitHub Desktop.
Save carlosplanchon/128f6bd1908736a41683e4774db9e21a to your computer and use it in GitHub Desktop.
Plays a song from YouTube.
#!/usr/bin/env python3
import mps_youtube
def play_song_from_youtube(song_title, extra="lyrics HQ"):
"""It plays a song from YouTube."""
# It search the song based on title.
mps_youtube.commands.search.search(f"{song_title} {extra}")
# Setting encoder to OGG 256K
mps_youtube.commands.config.setconfig("encoder", "5")
# Setting video off.
mps_youtube.commands.config.setconfig("show_video", "0")
try:
mps_youtube.commands.play.play("1", "1")
except Exception:
print("Song couldn't be played")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment