Module documentation¶
Main player class¶
The main player providing most functionality you would need
- class pYTerm.pYTerm.Player(songs=None, playlists=None, shuffle: bool = False, volume: int = 100, muted: bool = False, rich_presence: bool = True, enable_input: bool = False, vlclogs: bool = False, debuglogs: bool = False, legacystreams: bool = False)¶
Main player class
- Parameters
songs (list, str) – one or more song titles/urls
playlists (list, str) – one or more urls to youtube playlists/paths to local playlist files
shuffle (bool) – whether or not to randomise the song queue
volume (int >= 0) – volume level (>100 gets distorted and LOUD)
rich_presence (bool) – whether or not to use discord rich presence to display the current song
muted (bool) – whether or not to start the player muted
enable_input (bool) – whether or not to allow users to control the player through commandline input
vlclogs (bool) – whether or not to print VLC logs
debuglogs (bool) – whether or not to print pYTerm debug logs
legacystreams (bool) – whether or not to use legacy streams, enable if some songs dont load
- add_local_playlist(file)¶
Adds songs from a local playlist file to the queue. playlist files are a list of youtube URLs or search words, with each entry on its own line
- Parameters
file (str) – path to local playlist file
- add_playlist(playlists)¶
Checks type of playlist and hands it off to the right function, which will then add it’s songs to the queue
- Parameters
playlists (str, list) – one or more urls to youtube playlists or paths to local playlist files
- add_song(songs)¶
Add one or multiple songs to the queue
- Parameters
songs (list, str) – one or more songs or youtube urls to add to the queue
- add_youtube_playlist(url)¶
Adds songs from a youtube playlist to the queue
- Parameters
url (str) – url to youtube playlist
- debug(*args)¶
Print debug-level log
- get_current_time()¶
Returns a nicely formatted string of the current timestamp of the playing song
- get_total_time()¶
Returns a nicely formatted string of the total duration of the current song
- increment_song_index(positive=True, wrap=True)¶
increments or decrements the song_index by one, with optional wrapping
- interrupt()¶
stops current song without exiting the player. Will default to having the same effect as .next(), not advised unless you know what youre doing
- is_alive()¶
returns true if vlc is either paused or playing
- is_paused()¶
returns true if the player is paused, False if playing or if there is no song at all
- is_vlc_alive()¶
compatibility alias for is_alive
- mute()¶
mutes player and fades music out
- next()¶
play next song in the queue
- pause()¶
pauses the player
- play(song, halting=False)¶
Play a single song
- Parameters
song (str, Song) – keyword or url of a song on YouTube
= False (halting) – set to False to not halt the program
- play_all(halting=False, **kwargs)¶
play entire song queue.
- Parameters
= False (loop) – set to False to not halt the program
= True (keep_alive) – keep loop running even when the queue has ended, useful if you want to add more songs later (Note that this will halt indefinitely if halting=True)
= False – whether or not to restart the song queue once its played the final song
- play_at_index(index, wrap=True)¶
plays the song at the given position in the queue
- play_current_song(*args, **kwargs)¶
play queue song at the current index
- previous()¶
play previous song in the queue
- run_input()¶
allows user input. halts if called, initialise Player with enable_input = True to not halt
- scrub(seconds)¶
scrub the current song left or right in seconds
- Parameters
seconds (int) – positive or negative int indicating seconds to fast forward/backwards
- set_volume(new_volume, fadetime=0.5, desync_volume=None)¶
change volume smoothly over fadetime seconds
- Parameters
new_volume (int) – volume to transition to
fadetime (foat) – transition time in seconds
desync_volume (int) – don’t use this, its for muting
- shuffle()¶
shuffle song queue
- stop()¶
Stops player and exits
- toggle_mute()¶
toggles between muted and unmuted player
- toggle_pause()¶
toggles between paused and unpaused player
- unmute()¶
unmutes player and fades music back in
- unpause()¶
unpauses the player
- update_rich_presence()¶
Update discord rich presence if self.rich_presence == True
- wait_on_song_end()¶
waits until the current song has ended playing
- wait_on_song_load()¶
waits until the current song is loaded
- pYTerm.pYTerm.commandline()¶
Handles arguments if run from the commandline
- pYTerm.pYTerm.get_args()¶
Parses argparse arguments from commandline and returns the namespace object mapped to the correct .play_all() and Player() kwargs
- pYTerm.pYTerm.info(*args)¶
Print info-level log
Tools module¶
The tools is full of extremely messy code that we banned to its own file so we dont have to look at it. It provides a bunch of functions to make the main player work more nicely without filling up the .py
- pYTerm.tools.clear_line()¶
Clear current line
- pYTerm.tools.clear_previous_line()¶
Clear previous line
- pYTerm.tools.ensure_list(input_object)¶
Returns any input as a list. Tuples and sets get converted to lists, lists are returned as-is, and all other types get returned as a single element list
- pYTerm.tools.is_url(url)¶
Checks if a given string is an URL using regular expression, returns a bool
- pYTerm.tools.is_youtube_url(url)¶
Checks if a given string is a youtube url, returns a bool
- class pYTerm.tools.mdict(startDict=None)¶
fucked up little multiple dict class made by yours truly :)
- pYTerm.tools.previous_line()¶
Move cursor to previous line
- pYTerm.tools.secs_to_string(seconds)¶
Gets time from seconds to human readable
- pYTerm.tools.song_from_search(search)¶
Looks up a song with search terms and returns a Song object
- pYTerm.tools.songs_from_yt_playlist(url)¶
Returns a list of songs from a youtube playlist link
- pYTerm.tools.yt_playlist_to_rss_url(playlist_url)¶
Gets the rss url from a youtube playlist