You are not logged in.

#1 2010-07-24 01:26:00

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

sshmc - control music from anywhere via SSH

SSH Music Controller

Information:
* Written in python
* Allows you to play, pause, skip forward, skip backwards, and stop a song on a remote computer
* Adjust volume on a remote computer

Screenshot:

vNTEwMg

Known bugs:
* If the song ends and goes on to the next song, the line of text that displays the current song doesn't change. A workaround is to press play.

Currently supported music players:
* ncmpcpp

Dependencies for client machine (controlling the music):
* python (official repos)
* wxpython (official repos)

Dependencies for remote machine (playing the music):
* one of the supported music players from above

Installation (this requires git):
1) First, clone the files from my github:

$ git clone git://github.com/itsbrad212/sshmc.git

2) Run the install script on the client machine as root

# ./install.sh

3) Edit /usr/share/sshmc/sshmc.py to set the IP address of the remote machine, the SSH port to use, and the user to login as
4) You're done! You should now be able to launch the application by executing the sshmc command from wherever you choose.

Configuration:
* Edit /usr/share/sshmc/sshmc.py to set the IP address of the remote machine, the SSH port to use, and the user to login as

Footnotes:
* Please report any bugs so I can fix them smile
* If you would like support for your music player, just ask
* I am using keychain so I am not prompted with an SSH password. I strongly reccomend using this, or using a public key.

Changelog:
* Added an install script and icons (7/23/10)
* Removed need for amixer-wrapper [falconindy] (7/25/10)

Last edited by cesura (2010-07-25 19:06:53)

Offline

#2 2010-07-25 12:04:56

schen
Member
Registered: 2009-06-06
Posts: 468

Re: sshmc - control music from anywhere via SSH

Very handy, but can you try to support mpd?

Offline

#3 2010-07-25 16:39:13

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: sshmc - control music from anywhere via SSH

A few points:

* You've left yourself hardcoded in def PlaySong. On line 91:

        os.system("ssh -p 22 brad@192.168.1.72 'ncmpcpp play'")

* A separate user based config file would be good to have rather than editing the script itself.
* I don't understand the need for the C wrapper on amixer when a python function would suffice to read and parse the output.
* Consider adopting, updating, and using python-mpdclient. It would allow you to do a lot more things solely in Python rather than constantly forking and calling the OS. ...I suppose at that point, you're moving towards a more full fledged MPD client.

Offline

#4 2010-07-25 17:33:50

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Re: sshmc - control music from anywhere via SSH

falconindy wrote:

A few points:

* You've left yourself hardcoded in def PlaySong. On line 91:

        os.system("ssh -p 22 brad@192.168.1.72 'ncmpcpp play'")

* A separate user based config file would be good to have rather than editing the script itself.
* I don't understand the need for the C wrapper on amixer when a python function would suffice to read and parse the output.
* Consider adopting, updating, and using python-mpdclient. It would allow you to do a lot more things solely in Python rather than constantly forking and calling the OS. ...I suppose at that point, you're moving towards a more full fledged MPD client.

Crap...thanks for those tips falconindy. I had removed that hardcoded portion, but I forgot to commit the changes tongue I'll definitely check out python-mpdclient.

Also, about the C wrapper: It's all I could find at the moment. If you, myself, or someone else could find/write something in python, I'll be happy to replace amixer-wrapper. I will most likely make a seperate config file as well. This release was an sort of an alpha.

Last edited by cesura (2010-07-25 17:36:20)

Offline

#5 2010-07-25 18:29:36

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: sshmc - control music from anywhere via SSH

I'm pretty noobish with Python, but I hacked this together from bits and pieces of my other misguided adventures:

#!/usr/bin/env python
import commands

def GetVolume():
    amixout = [line.lstrip() for line in commands.getoutput("amixer sget PCM").split('\n')]
    for line in amixout:
        if line.startswith("Front Left"):
            print line.split(' ')[3]

GetVolume()

Last edited by falconindy (2010-07-25 18:31:03)

Offline

#6 2010-07-25 18:41:09

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Re: sshmc - control music from anywhere via SSH

falconindy wrote:

I'm pretty noobish with Python, but I hacked this together from bits and pieces of my other misguided adventures:

#!/usr/bin/env python
import commands

def GetVolume():
    amixout = [line.lstrip() for line in commands.getoutput("amixer sget PCM").split('\n')]
    for line in amixout:
        if line.startswith("Front Left"):
            print line.split(' ')[3]

GetVolume()

Thanks smile However...

print line.split(' ')[3]

should be changed to:

print line.split(' ')[4]

(at least on my machine). I'll add something to remove the "[", "]", and "%" characters and repost.

Offline

#7 2010-07-25 18:46:35

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Re: sshmc - control music from anywhere via SSH

Updated function:

#!/usr/bin/env python
import commands

def GetVolume():
    amixout = [line.lstrip() for line in commands.getoutput("amixer sget PCM").split('\n')]
    for line in amixout:
        if line.startswith("Front Left"):
           return int(line.split(' ')[4].strip("[]%"))
        
print GetVolume()

Last edited by cesura (2010-07-25 19:08:10)

Offline

#8 2010-07-25 19:00:11

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: sshmc - control music from anywhere via SSH

I don't see why that's needed:

Sample output from amixer:

Simple mixer control 'PCM',0
  Capabilities: pvolume cvolume penum
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: Playback 0 - 100 Capture 0 - 100
  Front Left: Playback 55 [55%] [-18.00dB] Capture 55 [55%] [-18.00dB]
  Front Right: Playback 55 [55%] [-18.00dB] Capture 55 [55%] [-18.00dB]

Is there a case when the number directly after playback won't match the number wrapped in brackets? If there is, no need to call replace 3 times...

 return int(line.split(' ')[4].strip("[]%"))

Offline

#9 2010-07-25 19:08:33

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Re: sshmc - control music from anywhere via SSH

Thank you big_smile I wasn't thinking properly.

Offline

#10 2010-07-25 21:39:35

JohannesSM64
Member
From: Norway
Registered: 2009-10-11
Posts: 623
Website

Re: sshmc - control music from anywhere via SSH

The commands module is deprecated in Python 2 and removed in Python 3. You should be using subprocess:

subprocess.Popen(['amixer', 'sget', 'PCM'], stdout = subprocess.PIPE).stdout.read()

Last edited by JohannesSM64 (2010-07-25 21:46:29)

Offline

Board footer

Powered by FluxBB