View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 4 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Sat Apr 19, 2008 6:30 am 
Offline
Joined: Fri Mar 24, 2006 10:35 pm
Posts: 89
Location: Detroit, MI
I moved this from the Hints and tips section to the How-To section.

I have made a webpage that will allow you to view all of your songs and assign ratings, create, edit or delete playlists.
I do have a help page for it, and I will add links to mysettopbox post.
I verified the install on a new autoinstall of R5F27.

Image
Code:
cd /myth/video/archive
mkdir /myth/video/archive/m3u
ln -s /myth/music

nano mythmusic_tools.php


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MythTV music assistant</title>
    <link rel="stylesheet" type="text/css" href="/mythweb/skins/default//style.css" />
    <link rel="stylesheet" type="text/css" href="/mythweb/skins/default//status.css" />
    <link rel="stylesheet" type="text/css" href="/mythweb/skins/default//header.css" />
    <link rel="stylesheet" type="text/css" href="/mythweb/skins/default//menus.css" />
    <link rel="stylesheet" type="text/css" href="/mythweb/skins/default//programming.css" />
</head>
<body>
<div id="page_header" class="body">
<?
$webhost  = $_SERVER['SERVER_NAME'];
$webhost_and_port = $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'];
$selected_playlist = $_POST['Playlist'];
$numselections = $_POST['row_count'];
$posted_action = $_POST['submit'];
#                                                     # POSTings are above.  Checking what is POSTed is below.

#                                                                               # SQL section.  Multiple queries
$conn = mysql_connect('localhost', 'mythtv', 'mythtv') or die ('Error connecting to mysql'); mysql_select_db('mythconverg');
$hostname = mysql_result(mysql_query("select hostname from music_playlists limit 1;"),0,0);
$playlists = mysql_query("select playlist_name, playlist_songs from music_playlists order by playlist_id;");
$music_songs = mysql_query("select s.name, a.artist_name, l.album_name, s.rating, s.filename, s.song_id from music_songs s, music_artists a, music_albums l where ((a.artist_name like '%') and (l.album_id = s.album_id) and (a.artist_id = s.artist_id)) limit 10000;");
$numsongs = mysql_numrows($music_songs);

if(strlen($selected_playlist) > 1){                   # Check for empty playlist.  Get songs contained in selected playlist
  $songs_in_playlist = mysql_result(mysql_query("select playlist_songs from music_playlists where playlist_name = '" . $selected_playlist . "';"),0,0);
  $playlist_exploded = explode(",",$songs_in_playlist);
  $numsongs_in_playlist = count($playlist_exploded);
}
$si=0; $songcnt=0; $songlist="";                      # get POSTed song selections.
while ($si < $numsongs){
 $wtg = "r" . $si;
 if($_POST[$wtg] <> ""){
   $songlist = $songlist . $si . ",";
   ++$songcnt;  } ++$si;  }                           #End of while loop to get songs and changes.
$songlist = substr($songlist,0,strlen($songlist)-1);
$songs = explode(",", $songlist);
$numsonglist = count($songs);

if(substr($posted_action,0,7)=="Replace"){          # Replace existing playlist.
$test_it = mysql_query("update music_playlists set playlist_songs=\"" . $songlist . "\" where playlist_name='" . $selected_playlist . "';");
echo "Playlist " . $selected_playlist . " updated with " . $songcnt . " songs. $songlist";
}
if(substr($posted_action,0,6)=="Create"){           # Create NEW playlist.
$test_it = mysql_query("insert into music_playlists (playlist_name,playlist_songs,last_accessed,length,songcount,hostname) values ('" . $_POST['NEWlist'] . "','" . $songlist . "','2008-01-01 12:00:00','23332','2','" . $hostname . "');");
echo "Playlist " . $_POST['NEWlist'] . " created with " . $songcnt . " songs.";
}
if(substr($posted_action,0,6)=="Delete"){           # Delete playlist.
$test_it = mysql_query("delete from music_playlists where playlist_name = '" . $selected_playlist . "';");
echo "Playlist " . $selected_playlist . " deleted.";
$selected_playlist = mysql_result(mysql_query("select playlist_name from music_playlists limit 1;"),0,0);
}
                                                                                # Get PLAYLIST after above changes.
$playlists = mysql_query("select playlist_name, playlist_songs from music_playlists order by playlist_id;");
if(strlen($selected_playlist) > 1){                 # Check for empty playlist.  Get songs contained in selected playlist
  $songs_in_playlist = mysql_result(mysql_query("select playlist_songs from music_playlists where playlist_name = '" . $selected_playlist . "' order by playlist_id;"),0,0);
  $playlist_exploded = explode(",",$songs_in_playlist);
  $numsongs_in_playlist = count($playlist_exploded);
}

if(substr($posted_action,0,6)=="Change"){           # Change ratings of songs.  (only changes)
  echo "Changed ratings on " . $numsongs . " songs.<br>"; $isong=0;
  while ($isong <= $numsongs - 1){
     $songrating = $_POST["Rating-" . $isong];
    if(strlen($songrating) > 0){
       $test_it = mysql_query("update music_songs set rating='" . $songrating . "' where song_id='" . ($isong + 1) . "';");
      }
     ++$isong;
   } # end_while
$music_songs = mysql_query("select s.name, a.artist_name, l.album_name, s.rating, s.filename, s.song_id from music_songs s, music_artists a, music_albums l where ((a.artist_name like '%') and (l.album_id = s.album_id) and (a.artist_id = s.artist_id)) limit 10000;");
$numsongs = mysql_numrows($music_songs);
}
if(substr($posted_action,0,6)=="stream"){           # create a M3U file to stream multiple songs.
  $myFile = "m3u/testFile.m3u";
  $fh = fopen($myFile, 'w') or die("can't open file");
  echo "Creating STREAM_list.M3U with songs $songlist.<br>";
  $isong=0;
  while ($isong < $numsongs - 1){
    $wtg = "r" . $isong;
    if($_POST[$wtg] <> ""){
      $stringData = "http://" . $webhost_and_port . "/archive/music/" . mysql_result($music_songs,$isong,'filename') . "\n";
      fwrite($fh, $stringData);
      }
      ++$isong; 
   }  #'end_while
  fclose($fh); $url="\"http://" . $webhost_and_port . "/archive/" . $myFile . "\"";
   echo "Click <a href=" . $url . ">HERE</a>";
}

if(substr($posted_action,0,8)=="Generate"){         # Generate one M3U for each song.
  $isong=0;
  echo "Created M3U files for $numsongs songs.";
  while ($isong < $numsongs - 1){
    $myFile = str_replace("/", "-", mysql_result($music_songs,$isong,'filename'));
      $myFile = substr($myFile, 0, strlen($myFile) - 3) . "m3u";
    $fh = fopen("m3u/" . $myFile, 'w') or die("can't open file");
    $stringData = "http://" . $webhost_and_port . "/archive/music/" . mysql_result($music_songs,$isong,'filename') . "\n";
    fwrite($fh, $stringData);
    ++$isong;
    fclose($fh);
   }  #end_while
}
$i =0 ; $tabindex = 1;                                # above manages POSTs from below's form selections.

if(substr($posted_action,0,4)=="Edit"){             # Determine if checkbox is selected for each song checkbox.   
echo "Edit Playlist <b>" . $selected_playlist . "</b> of " . $numsongs_in_playlist . " songs. Containin songs: <b>$songs_in_playlist</b>";
}
?>

<form name="Myth music tools" action="mythmusic_tools.php" method="post"><input type="hidden" name="row_count" value="<?php  echo $numsongs;  ?>">
<table border="0" cellpadding="0" cellspacing="2" summary="submits" class="body" width="600" >
<tr><td height="50"></td></tr>
<tr>
<td><input type="submit" name="submit" value="Generate m3u links" TABINDEX="<?  echo ++$tabindex; ?>" size="15" /></td>
<td align="center"><input type="reset" value="HELP" onclick=\"window.open('/archive/mythmusic_tools.php','MythMusic_Tools','')></td>
<td><input type="submit" name="submit" value="Edit playlist" size="15"  TABINDEX="<?  echo ++$tabindex; ?>"/>
<input type="submit" name="submit" value="Delete playlist" size="15"  TABINDEX="<?  echo ++$tabindex; ?>"/>
</td></tr>
<tr>
<td><input type="submit" name="submit" value="stream play" TABINDEX="<?  echo ++$tabindex; ?>" size="15" /></td>
<td><input type="submit" name="submit" value="Create new playlist" size="15" TABINDEX="<?  echo ++$tabindex; ?>"></td>
<td><select name="Playlist" TABINDEX="<?  echo ++$tabindex; ?>" >
<?for($si=0;$si < (int)mysql_numrows($playlists);++$si){
   $row = mysql_result($playlists,((int)mysql_numrows($playlists) - $si - 1),0);                        # Display available playlists.
   echo "<option value=\"" . $row . "\">" . $row . "</option>";
}?>
</select></td>
<tr>
<td><input type="submit" name="submit" value="Change ratings only" TABINDEX="<?  echo ++$tabindex; ?>" size="15" /></td>
<td><input type="text" name="NEWlist" size="15" TABINDEX="<?  echo ++$tabindex; ?>"></td>
<td><input type="submit" name="submit" value="Replace playlist" size="15"  TABINDEX="<?  echo ++$tabindex; ?>"/></td>
</tr></table>
<p><?  echo "Number of songs = $numsongs";  ?>

<div class="content">
<table border="1" cellpadding="2" cellspacing="2" summary="DB populated table"><tr>
<?                                                    # Below is the big table of songs.
$i=0; $edit_output = "";
while ($i < $numsongs){
$bname = "r" . $i;


if(substr($posted_action,0,4)=="Edit"){             # Determine if checkbox is selected for each song checkbox.   
 $showcheck = "";   
 for($si=0;$si < count($playlist_exploded) ;++$si){
  if((int)$playlist_exploded[$si] == (int)$i) {
     $showcheck = "checked=\"yes\"";
  }
 }
}
echo "<td><input type=\"checkbox\" " . $showcheck . " name=\"" . $bname . "\" value=\"" . $i . "\" TABINDEX=" . ++$tabindex . " /></button></td>";
echo "<td><select name=\"Rating-" .$i . "\" TABINDEX=" . ++$tabindex . " \>";       #onChange=\"location.reload()\"
echo "<option value=\"" . mysql_result($music_songs, $i,3) . "\">" . mysql_result($music_songs,$i,3) . "</option>";
$rs=0;
while($rs<9){   
    echo "<option value=\"" . $rs . "\" >" . $rs . "</option>";
++$rs;
}
echo "\" /></select></td>";

$m3uFILE = str_replace("/", "-", mysql_result($music_songs,$i,'filename'));
$m3uFILE = substr($m3uFILE, 0, strlen($m3uFILE) - 3) . "m3u";
echo "<td><a href=\"http://" . $webhost_and_port . "/archive/m3u/" . $m3uFILE . "\" >" . mysql_result($music_songs,$i,0) . "</a></td>";     
echo "<td>" . mysql_result($music_songs,$i,1) . "</td>";
echo "<td>" . mysql_result($music_songs,$i,2) . "</td></tr>";

++$i;
}
mysql_close($conn);

?>
</form>
<? 
#echo "<tr><td></td><td>Edit output:</td><td>" . $edit_output . "</td></tr>";
?>
</table>
</div>
</div>
</body>
</html>


Code:
chmod -f -R 777 mythmusic_tools.php
chown  -f -R mythtv:mythtv mythmusic_tools.php
chmod -f -R 777 m3u
chown mythtv:mythtv -R m3u


I know the 777 may seem extreme. The script does write files to ./m3u folder. The .php script needs permissions to write files. The owner is needed to write to database.

point browser to http://{mythserver:port}/archive/mythmusic_tools.php

I added a button to the mythmusic page in mythweb.
Image

Code:
nano /usr/share/mythtv/mythweb/modules/music/tmpl/default/music.php

Press ctrl-w and search for Player About line 192
Code:
printf("<input type=\"button\" value=\"MUSIC_tools\" onclick=\"window.open('/archive/mythmusic_help.php','MythMusic_Tools','')\">\n");


Code:
nano mythmusic_help.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>
<body>
<br>
cd /myth/video/archive<br>
mkdir /myth/video/archive/m3u<br>

chmod -f -R 777 m3u<br>
chown mythtv:mythtv -R m3u<br>

nano mythmusic_tools.php<br>

<br>
chmod -f -R 777 mythmusic_tools.php<br>
chown  -f -R mythtv:mythtv mythmusic_tools.php<br>

I know the 777 may seem extreme.  The script does write files to ./m3u folder.  The .php script needs permissions to write files.  The owner is needed to write to database.<br>

point browser to http://{mythserver:port}/archive/mythmusic_tools.php<br>
<br>
I added a button to the mythmusic page in mythweb.<br>
nano /usr/share/mythtv/mythweb/modules/music/tmpl/default/music.php<br>
Press ctrl-w and search for Player   About line 192<br>
printf(\"<input type=\"button\" value=\"MUSIC_tools\" onclick=\"window.open('/archive/mythmusic_tools.php','MythMusic_Tools','width=800,height=600')\">\n");<br>
<br>
</body>
</html>


Try the following:
Select a few songs and click stream, and then HERE.
Click generate m3u and then the song names will play the song.
Change the song ratings and then click the Change ratings button.
Create a playlist, edit and replace. Delete works by playlist name.
The changes will appear on the myth box too.

Give me some feedback. Thanks.


Last edited by myth19kirt on Tue Apr 22, 2008 6:23 am, edited 1 time in total.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 20, 2008 6:53 pm 
Offline
Site Admin
Joined: Fri Sep 19, 2003 6:37 pm
Posts: 2659
Location: Whittier, Ca
Cool! Might I suggest you test this on 0.21. I further suggest you make a patch and submit to MythTV proper. Let me know (PM) if you like to work with a release candidate w/ 0.21.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 22, 2008 6:20 am 
Offline
Joined: Fri Mar 24, 2006 10:35 pm
Posts: 89
Location: Detroit, MI
Glad to hear that you like it. I did get some verbal feedback and will be making a few changes this weekend.
    A filter, and sort for song name, artist, or album.
    Immediate update of changed ratings.
    Use on front-end sharing mythconverg music_playlists.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 16, 2008 7:32 pm 
Offline
Joined: Wed Apr 12, 2006 11:28 am
Posts: 82
Location: Beverly Hills, Michigan
Hi Kirt, if you see me at work I am on 5.5 now and can test it.

Paul

_________________
Backend/Frontend
ASUS M4A78-EM w/8400GS 4G RAM pcHDTV 3000 + PVR500 (1045), 1TB, 250 & 320. Iguana IR USB (running R6)
Frontend_1
Asus M2NPV-VM - 1GB RAM - 40 GB Hard Disk - StreamZap
Frontend_2
Dragon 1.0 w/ 2G RAM - 40 GB Hard Disk StreamZap


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu