Skip to main content

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

Reason this release was yanked:

I did a goof and classes didnt match up for some reason.

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: p-yt-erm-0.5b2.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.tar.gz
Algorithm Hash digest
SHA256 05712e903e1d0962b0b41807dd2db06f42fbc8a31749e2df1df5425bd224b5c9
MD5 b8584ac96cbde26874655979e8aeb648
BLAKE2b-256 a990f1c0662ba941e7381eedbc76012fd1d36a05537370286b321f5756cfb535

See more details on using hashes here.

File details

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

File metadata

  • Download URL: p_yt_erm-0.5b2-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.5b2-py3-none-any.whl
Algorithm Hash digest
SHA256 de5948f84c6dedaeb428ee71d316de9ad69f390c7cb6927494c83b153906633b
MD5 163b84a2dade7cba430ca11685d52b3d
BLAKE2b-256 a765b00a9626a50245d3ce7d838853abc26b3a7c4458537f8e2484e75dfa1253

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