Author Topic: whatcha hackin?  (Read 503 times)

Offline zerocool

  • Sr. Member
  • ****
  • Posts: 375
whatcha hackin?
« on: March 24, 2013, 09:51:32 AM »
Hi fellow hackers. I recently hacked together an
html / apache / php / bash project which was a
lot fun to figure out.

Problem:
I have been using vlc to play
a few hundred videos in a random loop... for months
on end. As far as I can tell, when you tell vlc to both
random and loop it creates one big random playlist
and then loops that playlist. Not really what I wanted
because you'd be surprised how soon the illusion of
randomness disappears and then you're forced to
restart vlc to reshuffle the playlist.

So i finally decided to do something about it and like
so many great hacking projects this one has started
to grow beyond the original parameters and Im sure
its still growing... What I have so far is a very simple
bash script which picks a random number and then
exec a read line of the file list of paths to the videos I
want played and then runs vlc with "full screen" and
"play and exit" cl switches. It then calls a another sub
which check the file size attrib of a "request" file. If the
"request" file size is gt zero someone has logged on to
the request web page and selected a video to be played.
A little php file handles that interface between the web
server and the bash script.

While the bulk of the code is rather less than interesting,
it was a lot of fun as I have never done such a kludge of
different methods Ive never used before (bash, html, php).

Well thats what I been up to and I just wanted to share and
maybe inspire you all share what y'all been hackin too.


 



 

Offline The Chief

  • Hero Member
  • *****
  • Posts: 2343
Re: whatcha hackin?
« Reply #1 on: March 24, 2013, 11:31:17 AM »
Now someone will come along and tell you it's only two lines of perl, or ruby, or python... 

But not me!  Good job!

Retired Senior Chief, Retired Software Engineer, Active GrandPa

Offline zerocool

  • Sr. Member
  • ****
  • Posts: 375
Re: whatcha hackin?
« Reply #2 on: March 24, 2013, 12:23:52 PM »
Its kind of cool because folks can
use their cell phones to request
videos to play.



Offline smileeb

  • Hero Member
  • *****
  • Posts: 2244
    • smileesplace
Re: whatcha hackin?
« Reply #3 on: March 24, 2013, 07:06:19 PM »
 ;D Wait a minute, doesn't some one have a patten on that?  ;D


Offline pags

  • Hero Member
  • *****
  • Posts: 2606
  • Keep it clean.
Re: whatcha hackin?
« Reply #4 on: March 25, 2013, 06:58:05 AM »
Sounds cool.

Would you consider sharing the script(s)?  Have you considered putting it (them?) under some kind of open license?

 :)

Offline zerocool

  • Sr. Member
  • ****
  • Posts: 375
Re: whatcha hackin?
« Reply #5 on: March 25, 2013, 11:37:08 AM »
Sounds cool.

Would you consider sharing the script(s)?  Have you considered putting it (them?) under some kind of open license?

 :)

Sure, but like I said it not very interesting. Also keep in mind I not an expert so the code is likely not
optimized.

here's the html file running on the local apache server:

<html>

<head>

<style type="text/css">
.inputtext { width: 800px; height: 100px; }
</style>

</head>

<body>

<form action="myform.php" method="post">

<img src="ffe-logo.png" alt="ffeb" width="600" height="200">

<p style="font-size:50px">
Music Request
</p>

<p>
<select style="font-size:40px" name="drop1" class="inputtext" id="Select1" size="20" >

<option value="3DoorsDown-BeLikeThat(NoMovieFootage).flv">3DoorsDown-BeLikeThat(NoMovieFootage).flv</option>
<option value="3DoorsDown-WhenI_mGone.flv">3DoorsDown-WhenI_mGone.flv</option>
<option value="50Centfeat.JustinTimberlake-AyoTechnology.flv">50Centfeat.JustinTimberlake-AyoTechnology.flv</option>
<option value="50Cent-InDaClub.flv">50Cent-InDaClub.flv</option>
<option value="Aaliyah-TryAgain.flv">Aaliyah-TryAgain.flv</option>
<option value="AdamLambert-ForYourEntertainment.flv">AdamLambert-ForYourEntertainment.flv</option>
<option value="AdamLambert-IfIHadYou.flv">AdamLambert-IfIHadYou.flv</option>
<option value="AdamLambert-WhatayaWantFromMe.flv">AdamLambert-WhatayaWantFromMe.flv</option>
<option value="Adele-RollingInTheDeep.flv">Adele-RollingInTheDeep.flv</option>

</select>
</p>

<p style="font-size:50px">
Select song from the dropdown
</p>

<p><input type="submit" class="inputtext" style="font-size:50px" value="Play it!"></p>
</form>

</body>
</html>

here is the php file:

<?php
$filename = '/var/www/html/request.txt';
$mpath = '/home/zerocool/Music/music_edit/';

$select = check_input($_POST['drop1']);
    if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
}
fwrite($handle, $mpath);
fwrite($handle, $select);
fwrite($handle, "\n");
fclose($handle);

?>

<html>
<body>

your request: <?php echo $select; ?>

has been sent.

</body>
</html>

<?php
function check_input($data)
{
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>

here is the bash script:

#!/bin/bash

request()
{
  FILENAME=/var/www/html/request.txt
  FILESIZE=$(stat -c%s "$FILENAME")
  if [ $FILESIZE -gt 0 ]
    then
    exec<$FILENAME
    read line
    echo $line
    vlc --fullscreen --play-and-exit $line
  fi
  rm -rf $FILENAME
  touch $FILENAME
  chmod 777 $FILENAME
  rplay
}

rplay()
{
  fname=/home/zerocool/bash/music.txt

  r=$(( $RANDOM % 334 + 1 ))
  echo $r

  exec<$fname

  x=0
  echo $x

  while [  $x -lt $r ]; do
      echo The counter is $x
      let x=x+1
      read line
      done


  vlc --fullscreen --play-and-exit $line
  request
}

request

then the only other thing is a text file with a list of videos and paths like so:

/home/zerocool/Music/music_edit/3DoorsDown-BeLikeThat(NoMovieFootage).flv
/home/zerocool/Music/music_edit/3DoorsDown-WhenI_mGone.flv
/home/zerocool/Music/music_edit/50Centfeat.JustinTimberlake-AyoTechnology.flv
/home/zerocool/Music/music_edit/50Cent-InDaClub.flv
/home/zerocool/Music/music_edit/Aaliyah-TryAgain.flv
/home/zerocool/Music/music_edit/AdamLambert-ForYourEntertainment.flv
/home/zerocool/Music/music_edit/AdamLambert-IfIHadYou.flv
/home/zerocool/Music/music_edit/AdamLambert-WhatayaWantFromMe.flv
/home/zerocool/Music/music_edit/Adele-RollingInTheDeep.flv

hope someone finds it usefull or at least fun.

 

Offline pags

  • Hero Member
  • *****
  • Posts: 2606
  • Keep it clean.
Re: whatcha hackin?
« Reply #6 on: March 25, 2013, 12:15:43 PM »
Sounds cool.

Would you consider sharing the script(s)?  Have you considered putting it (them?) under some kind of open license?

 :)

Sure, but like I said it not very interesting. Also keep in mind I not an expert so the code is likely not
optimized.

here's the html file running on the local apache server:

Code: [Select]
<html>

<head>

<style type="text/css">
.inputtext { width: 800px; height: 100px; }
</style>

</head>

<body>

<form action="myform.php" method="post">

<img src="ffe-logo.png" alt="ffeb" width="600" height="200">

<p style="font-size:50px">
Music Request
</p>

<p>
<select style="font-size:40px" name="drop1" class="inputtext" id="Select1" size="20" >

<option value="3DoorsDown-BeLikeThat(NoMovieFootage).flv">3DoorsDown-BeLikeThat(NoMovieFootage).flv</option>
<option value="3DoorsDown-WhenI_mGone.flv">3DoorsDown-WhenI_mGone.flv</option>
<option value="50Centfeat.JustinTimberlake-AyoTechnology.flv">50Centfeat.JustinTimberlake-AyoTechnology.flv</option>
<option value="50Cent-InDaClub.flv">50Cent-InDaClub.flv</option>
<option value="Aaliyah-TryAgain.flv">Aaliyah-TryAgain.flv</option>
<option value="AdamLambert-ForYourEntertainment.flv">AdamLambert-ForYourEntertainment.flv</option>
<option value="AdamLambert-IfIHadYou.flv">AdamLambert-IfIHadYou.flv</option>
<option value="AdamLambert-WhatayaWantFromMe.flv">AdamLambert-WhatayaWantFromMe.flv</option>
<option value="Adele-RollingInTheDeep.flv">Adele-RollingInTheDeep.flv</option>

</select>
</p>

<p style="font-size:50px">
Select song from the dropdown
</p>

<p><input type="submit" class="inputtext" style="font-size:50px" value="Play it!"></p>
</form>

</body>
</html>

here is the php file:

Code: [Select]
<?php
$filename 
'/var/www/html/request.txt';
$mpath '/home/zerocool/Music/music_edit/';

$select check_input($_POST['drop1']);
    if (!
$handle fopen($filename'a')) {
         echo 
"Cannot open file ($filename)";
         exit;
}
fwrite($handle$mpath);
fwrite($handle$select);
fwrite($handle"\n");
fclose($handle);

?>


<html>
<body>

your request: <?php echo $select?><br />
has been sent.

</body>
</html>

<?php
function check_input($data)
{
    
$data stripslashes($data);
    
$data htmlspecialchars($data);
    return 
$data;
}
?>

here is the bash script:

Code: [Select]
#!/bin/bash

request()
{
  FILENAME=/var/www/html/request.txt
  FILESIZE=$(stat -c%s "$FILENAME")
  if [ $FILESIZE -gt 0 ]
    then
    exec<$FILENAME
    read line
    echo $line
    vlc --fullscreen --play-and-exit $line
  fi
  rm -rf $FILENAME
  touch $FILENAME
  chmod 777 $FILENAME
  rplay
}

rplay()
{
  fname=/home/zerocool/bash/music.txt

  r=$(( $RANDOM % 334 + 1 ))
  echo $r

  exec<$fname

  x=0
  echo $x

  while [  $x -lt $r ]; do
      echo The counter is $x
      let x=x+1
      read line
      done


  vlc --fullscreen --play-and-exit $line
  request
}

request

then the only other thing is a text file with a list of videos and paths like so:

/home/zerocool/Music/music_edit/3DoorsDown-BeLikeThat(NoMovieFootage).flv
/home/zerocool/Music/music_edit/3DoorsDown-WhenI_mGone.flv
/home/zerocool/Music/music_edit/50Centfeat.JustinTimberlake-AyoTechnology.flv
/home/zerocool/Music/music_edit/50Cent-InDaClub.flv
/home/zerocool/Music/music_edit/Aaliyah-TryAgain.flv
/home/zerocool/Music/music_edit/AdamLambert-ForYourEntertainment.flv
/home/zerocool/Music/music_edit/AdamLambert-IfIHadYou.flv
/home/zerocool/Music/music_edit/AdamLambert-WhatayaWantFromMe.flv
/home/zerocool/Music/music_edit/Adele-RollingInTheDeep.flv

hope someone finds it usefull or at least fun.

 

Thanks
(edited your copy to use CODE tags)

Offline zerocool

  • Sr. Member
  • ****
  • Posts: 375
Re: whatcha hackin?
« Reply #7 on: March 25, 2013, 12:24:09 PM »
yeah hope you like it. Keep me informed if you make it better!

 8)


Offline zerocool

  • Sr. Member
  • ****
  • Posts: 375
Re: whatcha hackin?
« Reply #8 on: March 25, 2013, 03:47:22 PM »
Code: [Select]
<?php
function check_input($data)
{
    
$data stripslashes($data);
    
$data htmlspecialchars($data);
    return 
$data;
}
?>

here's a question for the real experts out there in pclos land:

the above php code was an attempt to do some input validation
but that code is not working. i think there must be a php module
in synaptic i need to load but dont know what it is.

anyone know?