Home » programming » Some nice music on your linux pc

Some nice music on your linux pc


Are you too lazy to fire up a full media player, select music tracks or radio station and only then listen to music?

In case you always keep an open terminal, here is a solution for you:

Create a file named radio.py and write:

import random
import os

PLAY = "mplayer -prefer-ipv4 -playlist "

STATIONS = ['http://www.radioswissclassic.ch/live/aacp.m3u',
station = random.choice(STATIONS)

os.system(PLAY + station)

Append the following two lines in your ~/.bash_aliases file:

alias music='find ~/Music -name *.mp3 > my_playlist.txt; mplayer -quiet -shuffle -playlist my_playlist.txt'
alias radio='python ~/scripts/radio.py'

Make sure your ~/.bashrc contains:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases

Given that your music is encoded in mp3 format and is under your ~/Music folder, you can listen to the songs in random order using:

$ music

On the other hand, if you like listening to radio stations, you will find yourself listening to a random (from the predefined list) station by writing:

$ radio

You need mplayer for both functionalities.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: