Project

General

Profile

[Solved] Help with environment variable 'HOME' using MPlayer and python script.

Added by your_mum over 9 years ago

I'm trying to configure lighttpd on a raspberry pi (wheezy) and running MPlayer via python script called from a browser using javascript.

When I run a small test.py script (copied below) from the browser, MPlayer warns that it can not find 'HOME' but when I run the same script logged in as www-data on the command line it is OK.
I have added the output of the script further below and collect the environment varables, whoami and output from MPlayer.

I believe I need to somehow get lighttpd to set "HOME=/var/www", which does not appear in the below output- is this possible and if so how?

(Please let me know if further details, such as conf file, versions etc are required to help answer)

I use the following link on a test.html page: <a href="/cgi-bin/test.py">

test.py:
#!/usr/bin/env python

import subprocess
import select

from os.path import expanduser
home = expanduser("~")

fifoFile = 'file=/run/shm/mpcontrol'

environmentVariables = subprocess.check_output(['printenv'])
whoAmI = subprocess.check_output(['whoami'])

playing_mplayer=subprocess.Popen(['mplayer', '-slave', '-nocache', '-quiet', '-volume', '60', '-key-fifo-size', '2', '-input', fifoFile, '-playlist', 'http://tx.whatson.com/icecast.php?i=magic1054.mp3.m3u' ], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)

mpText=""
counting = 1
while counting < 300:
counting = counting + 1
if 'Starting playback...' in mpText : break
while any(select.select([playing_mplayer.stdout.fileno()], [], [], 0.01)):
mplayerResponse = playing_mplayer.stdout.readline()
if (mplayerResponse is None) or (len(mplayerResponse) == 0) : mplayerResponse = ""
if mplayerResponse != "":
print mplayerResponse
mpText = mpText+mplayerResponse+'<br>'
break

with open('/var/www/error_log','a',0) as g:
g.write('User: '+whoAmI+'<br>\nEnv variables: '+environmentVariables+'<br>\nhome dir is: '+home+'<br>\ntest.py:<br>\n'+str(mpText)+'<br>\n')
g.close()

Outputs are as follows, first set run from a browser, the second set run from command line logged in as www-data:

User: www-data
Env variables: SERVER_SOFTWARE=lighttpd/1.4.31 SERVER_NAME=192.168.1.8 GATEWAY_INTERFACE=CGI/1.1 SERVER_PROTOCOL=HTTP/1.1 SERVER_PORT=80 SERVER_ADDR=0.0.0.0 REQUEST_METHOD=GET REDIRECT_STATUS=200 REQUEST_URI=/cgi-bin/test.py REMOTE_ADDR=192.168.1.5 REMOTE_PORT=60006 CONTENT_LENGTH=0 SCRIPT_FILENAME=/var/www/cgi-bin/test.py SCRIPT_NAME=/cgi-bin/test.py DOCUMENT_ROOT=/var/www/ HTTP_HOST=192.168.1.8 HTTP_CONNECTION=keep-alive HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 HTTP_USER_AGENT=Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36 HTTP_REFERER=http://192.168.1.8/test.html HTTP_ACCEPT_ENCODING=gzip,deflate,sdch HTTP_ACCEPT_LANGUAGE=en-GB,en-US;q=0.8,en;q=0.6
home dir is: /var/www
test.py:
Cannot find HOME directory.
Resolving tx.whatson.com for AF_INET...
Connecting to server tx.whatson.com[91.193.246.140]: 80...
Resolving ICY-E-02.sharp-stream.com for AF_INET...
Connecting to server ICY-E-02.sharp-stream.com[193.27.42.230]: 80...

Cache size set to 0 KBytes
MPlayer svn r34540 (Debian), built with gcc-4.6 (C) 2000-2012 MPlayer Team
Terminal type `unknown' is not defined.

Playing http://icy-e-02.sharp-stream.com:80/magic1054.mp3.
Resolving icy-e-02.sharp-stream.com for AF_INET...
Connecting to server icy-e-02.sharp-stream.com[193.27.42.230]: 80...

Name : Magic 105.4
Genre : Various
Public : no
Bitrate: 112kbit/s
Cache size set to 0 KBytes
Cannot seek backward in linear streams!

ICY Info: StreamTitle='Shania Twain - Man I Feel Like A Woman';StreamUrl='magic.co.uk';
Audio only file format detected. ==========================================================================
Requested audio codec family [mpg123] (afm=mpg123) not available.
Enable it at compilation.
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
libavcodec version 53.35.0 (external)
Mismatching header version 53.32.2
AUDIO: 44100 Hz, 2 ch, floatle, 112.0 kbit/3.97% (ratio: 14000->352800)
Selected audio codec: [ffmp3float] afm: ffmpeg (FFmpeg MPEG layer-3 audio) ==========================================================================
AO: [alsa] 44100Hz 2ch floatle (4 bytes per sample)
Video: no video
Starting playback...


**

User: www-data
Env variables: MAIL=/var/mail/www-data SSH_CLIENT=192.168.1.5 60296 22 USER=www-data SHLVL=1 HOME=/var/www SSH_TTY=/dev/pts/0 LOGNAME=www-data _=printenv TERM=xterm PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games DISPLAY=localhost:10.0 LANG=en_GB.UTF-8 LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36: SHELL=/bin/sh PWD=/home/pi SSH_CONNECTION=192.168.1.5 60296 192.168.1.8 22
home dir is: /var/www
test.py:
Resolving tx.whatson.com for AF_INET...
Connecting to server tx.whatson.com[91.193.246.9]: 80...
Resolving ICY-E-05.sharp-stream.com for AF_INET...
Connecting to server ICY-E-05.sharp-stream.com[91.193.246.144]: 80...

Cache size set to 0 KBytes
MPlayer svn r34540 (Debian), built with gcc-4.6 (C) 2000-2012 MPlayer Team

Playing http://icy-e-05.sharp-stream.com:80/magic1054.mp3.
Resolving icy-e-05.sharp-stream.com for AF_INET...
Connecting to server icy-e-05.sharp-stream.com[91.193.246.144]: 80...

Name : Magic
Genre : Various
Public : no
Bitrate: 112kbit/s
Cache size set to 0 KBytes
Cannot seek backward in linear streams!

ICY Info: StreamTitle='Toni Braxton - Unbreak My Heart';StreamUrl='magic.co.uk';
Audio only file format detected. ==========================================================================
Requested audio codec family [mpg123] (afm=mpg123) not available.
Enable it at compilation.
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
libavcodec version 53.35.0 (external)
Mismatching header version 53.32.2
AUDIO: 44100 Hz, 2 ch, floatle, 112.0 kbit/3.97% (ratio: 14000->352800)

Selected audio codec: [ffmp3float] afm: ffmpeg (FFmpeg MPEG layer-3 audio) ==========================================================================
AO: [alsa] 44100Hz 2ch floatle (4 bytes per sample)
Video: no video
Starting playback...


Replies (5)

RE: Help with environment variable 'HOME' using MPlayer and python script. - Added by your_mum over 9 years ago

I've worked out that one needs to add the following two entries to /etc/lighttpd/lighttpd.conf:

Add the following module to the server.modules section: "mod_setenv"

And the following env var to the 'CGI' module: setenv.add-environment = ("MPLAYER_HOME" => "/var/www/.mplayer")

RE: [Solved] Help with environment variable 'HOME' using MPlayer and python script. - Added by pijimh over 5 years ago

Hello your_mum,

Can you please tell me how to add the environment variable to the CGI module in the conf?

I have added "mod_setenv" to the server.modules, but I don't know the method or the place in the conf to add the setenv.add-environment = ("MPLAYER_HOME" => "/var/www/.mplayer")

Thanks much
Jim

RE: [Solved] Help with environment variable 'HOME' using MPlayer and python script. - Added by gstrauss over 5 years ago

@pijimh: you're posting to something last updated 4 years ago.

... and you still haven't tried anything because you're too scared of breaking something (your words in https://redmine.lighttpd.net/boards/2/topics/8388).

If you are unable to make a change, test it, and revert the change if it does not work, then there is not much that can be done for you, since you're helpless.

If you are able to make a change, test it, and revert the change if it does not work, then you should have no problem getting a working config based on the advice here and repeated to you in https://redmine.lighttpd.net/boards/2/topics/8388

RE: [Solved] Help with environment variable 'HOME' using MPlayer and python script. - Added by pijimh over 5 years ago

gstrauss,

You've given no advice, just condescension. Twice, after plenty of effort, I have asked a question on this forum. And twice I ran into the roadblock called gstrauss. Twice I spent plenty more precious time to find the answer that you refuse to give up, or just don't know. Twice you win your ivory tower game. Pretty rewarding, I'm sure.

I was wondering what the secret to getting a straight answer was. Perhaps I should make a donation to get information? Perhaps there is another "expert" who is more likely to answer questions? I made the false assumption that this forum was a source of information, perhaps saving the readers time. Reading thru posts, it's apparent that I'm not the first person you have chased away from this potential goldmine. You must be an "academic", as pricks like you don't last long in the real world.

I scrubbed the web long enough to sort thru the chaff and find a method, possibly not the best method, certainly not the best use of time, and have things working now.

Thanks, Helpless Jim

RE: [Solved] Help with environment variable 'HOME' using MPlayer and python script. - Added by gstrauss over 5 years ago

The answer was given in my first response in https://redmine.lighttpd.net/boards/2/topics/8388?r=8390#message-8390
If you are too afraid to add a single line to your config and test that it works, then you garner the subsequent responses that you got.

If you read my responses on various issues on this site, you'll find that those who put in some effort are helped much more than those who demand that everything be done for them and that they be spoon-fed. (Your response in the linked post of essentially "I'm too afraid to try anything" is the opposite of making an honest effort.)

    (1-5/5)