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.5b2.post1.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

p_yt_erm-0.5b2.post1-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: p-yt-erm-0.5b2.post1.tar.gz
  • Upload date:
  • Size: 16.2 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.5b2.post1.tar.gz
Algorithm Hash digest
SHA256 154070210583e2c6efac017b9b76c0d29a60beb1a43a68f8146085512ed75a9f
MD5 c44c4fac96aa0346982fd492f3069ad9
BLAKE2b-256 88eb72424c77b28b80f334efb1994e67a05a130840be908d42ffaad8e3b6cc49

See more details on using hashes here.

File details

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

File metadata

  • Download URL: p_yt_erm-0.5b2.post1-py3-none-any.whl
  • Upload date:
  • Size: 14.5 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.5b2.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 6f83a110295ac822dd28e31b7a0694a17fe5dad98abcb581a86dd8bc50708ee4
MD5 8ca2ebe56b09032313c00f064b58594a
BLAKE2b-256 ea00e9dd20d982095549fc2120d17fe0c9c03d0dd21db9b9df10250e879d0119

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