Skip to main content

Easy to use youtube music streamer command line tool written in python3

Project description

------------------------------------
pYTerminal r0.1 by anne & lynice
------------------------------------

=============================================================================================================

youtube music player in the command line


This program requires python3, the libraries in requirements.txt & vlc media player to be installed to work

=============================================================================================================






THIS DOCUMENT IS OUT OF DATE AND APPLIES TO THE PREVIOUS, MAIN BRANCH VERSION. NOTE THAT LIKELY NONE OF
THE THINGS DESCRIBED HERE WILL WORK WITH THIS VERSION OF pYTerminal REWRITE






=============================================================================================================

Input actions:
> [p/s/m/e/v]: p
// pauses playback

> [p/s/m/e/v]: s
// skips the current song

> [p/s/m/e/v]: m +20
// moves the playback cursor 20 seconds forwards

> [p/s/m/e/v]: m -14
// moves the playback cursor 14 seconds backwards

> [p/s/m/e/v]: e
// stops playback & exits

> [p/s/m/e/v]: v 20
// sets volume level to 20

=============================================================================================================

commandline options for main.py


USAGE: python3 main.py [-p][-r][-v][-s] "Song1" "Song2"

-p <filename> // specify a file that contains a list of song names, one on each line
-r <True/False> // specify if you want to enable Discord Rich Presence
-i <True/False> // specify if you want to enable input
-v <int> // specify the volume level
-s // enabled playlist shuffling
-a // enable forcing ytplayer to use audiostreams*
-d // enables debug logging
-l // enables infinite playlist looping


*this can cause playback issues on some videos but might offer better audio quality

=============================================================================================================

examples:


python3 main.py -p playlist.txt
// plays all the songs in playlist.txt in descending order

python3 main.py -v 50 "foals spanish sahara"
// plays the song "spaish sahara" at volume level 50

python3 main.py -s -p playlist.txt
// plays the songs in playlist.txt in random order

pythhon3 main.py -p playlist.txt "foals spanish sahara" "icicles the scary jokes"
// plays the songs "spanish sahara" & "icicles" before playing everything in playlist.txt


============================================================================================================

ytplayer can be used on its own in different scripts by importing it

view the source code to get a vague idea how it works

=============================================================================================================

jk heres a quick rundown



---- initial setup ----

first step is to import it (obv)

> import ytplayer

now make a new instance of the player by creating the object variable. Decide if you want to supress output or enable debug info.
Enabling debug will always disable quiet mode too

> player = ytplayer.YtPlayer(quiet=False,debug=False,vlclogs=False,forceaudiostream=False)
// quiet determines if it prints song info when a song gets played
// debug determines if some debug prints get printed
// vlclogs enabled/disables vlclib logging
// forceaudiostream determines if playing a song will always use the audiostream [See note in commandline options up above]

thats all the setup you need.


---- playing songs ----

There are several ways of playing songs:

> YtPlayer.play(query,wait=True)
// this will search for the 'query' search terms and immediatly play the top result. Enabling 'wait' means it will sleep until the song is finished.


> YtPlayer.playPlaylist(songlist,shuffle=False)
// very similar to play, but for multiple song. it will play every song in the list 'songlist'. Enable shuffle to randomise the order of songs.


> YtPlayer._vlcPlay(url)
// this is more backend-ish but if you really want to play an audio file from the web directly and for some reason dont want to use python-vlc on it's own, use this.


> YtPlayer.search(query)
// this doesnt actually play anything, but it returns the highest quality youtube audio url for the top search result of the query. Could be useful if you want to use a different audio library instead of vlc i suppose.


---- controlling playback ----

> YtPlayer.pause():
// pauses playback

> YtPlayer.unpause():
// resumes playback

> YtPlayer.stop():
// stops playback entirely

> YtPlayer.setVolume(volumenum):
// this will set the volume to the int given as long as it is between 0-200
There are two other ways to change the volume, both applicable to niche uses
The fist would be to overwrite 'YtPlayer._volumeLvl'. This would change the volume level to the one specified when the next song in the playlist starts playing.
The other option is to call 'YtPlayer.vlcPlayer.audio_set_volume(volumenum)'. This changes the vlc volume for the *current song only* and will be changed back to the _volumeLvl value when the next song plays.


---- finer playback controls ----

i decided not to wrap the entire python-vlc library needlessly, because it is still acessible.
You can access any vlc function by calling the 'YtPlayer.vlcPlayer' or 'YtPlayer.vlcInstance' objects


---- getting playback info ----

both 'YtPlayer.YtInfo' & 'YtPlayer._ydl_info' are exposed. You may use either to get pretty much any info about the youtube video.

> YtPlayer.getTimeStamp()
if you happen to need a nicely formatted current timestamp + the complete length of the current video, use this. It will return a tuple like this '(MM:SS,MM:SS)' where [0] is current time and [1] is total lenght

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

p-yt-erm-0.5b5.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

p_yt_erm-0.5b5-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file p-yt-erm-0.5b5.tar.gz.

File metadata

  • Download URL: p-yt-erm-0.5b5.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for p-yt-erm-0.5b5.tar.gz
Algorithm Hash digest
SHA256 d55588775da6d28f2b92ae6ec809fe642218bd4c5f29f6f70e54f4c64d96befa
MD5 ed6f6f82758d6c7d970ec62c87f0bcdc
BLAKE2b-256 e564ea58a13d777e07c8e14e05fabd74fe82ca00c21cf2becfee6a493b6732a1

See more details on using hashes here.

File details

Details for the file p_yt_erm-0.5b5-py3-none-any.whl.

File metadata

  • Download URL: p_yt_erm-0.5b5-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for p_yt_erm-0.5b5-py3-none-any.whl
Algorithm Hash digest
SHA256 c85c1aa2473a7d7320c80459b11b50a85691942b8741571df3323398c0fd5a8a
MD5 e93f844d64dcb89e5da0eca1dd079dec
BLAKE2b-256 e3f2aea92eab9fe3c65c890e809069956f0ecf2bd6447040cf4f47954dd4f72a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page