HydrogenAudio

Hosted Forums => foobar2000 => General - (fb2k) => Topic started by: Strat on 2004-04-04 10:15:24

Title: Copy Command String question
Post by: Strat on 2004-04-04 10:15:24
Hi guys. I did a search for this but couldn't find anything.

Just wondering is it possible to add a header and footer section to a copy string ?

I have some code setup to copy all my albums to html but I would like it to generate the whole page, in other words I would like a header at the top of the copy command that is only inserted once at the top. So it will put a <html> <head></head> etc etc etc at the top of the copy command only.

Does that make sense? Is it possible?

For anyone interested my copy command string is

Code: [Select]
// HTML Copy String

$if($strcmp($num(%TRACKNUMBER%,2),01),
'    </ul>'
'</div>' $crlf()
'<div id="Album">' $crlf()
'    <ul>' $crlf()
'        <li id="title">'
)

// 1. Line
$if($strcmp($num(%TRACKNUMBER%,2),01),
$if(%artist%,%artist%,'unknown artist') ' - '
$if(%album%,%album%,'unknown album')
'</li>' $crlf()
,)
'        <li>'$num(%TRACKNUMBER%,2). %TITLE%' - ' %_length%'</li>'



This then gets pasted in between the following:::

Code: [Select]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 

<html>

    <head>
 <title>Test Page</title>
 <style type="text/css" media="all">@import url("style.css");</style>
 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
 <meta http-equiv="expires" content="-1">
 <meta http-equiv= "pragma" content="no-cache">
 <meta name="robots" content="all">
    </head>
    
    <body>

    INSERT COPY CODE HERE !!!!!

    </body>
    
</html>


So instead of pasting it in between the html above i would like it to generate that aswell. Hope that makes sense.

Ohh btw it ends up generating the following page

Link to Music Page (http://members.ii.net/~u4996a/music.html)

Hope that makes sense.

Thanks in advanced.
Title: Copy Command String question
Post by: kjoonlee on 2004-04-04 10:34:57
Yes, you can do that alright.  Check if %_playlist_number% is equal to either 1 or %_playlist_total%.

Code: [Select]
$if($strcmp(%_playlist_number%,1),
Place header here
$crlf(),)
Place item string here
$if($strcmp(%_playlist_number%,%_playlist_total%),$crlf()
Place footer here
,)


edit: I've just realized this string doesn't work with partial selections. You'll either have to select all files in your playlist, or send your selection to a new playlist before you can issue the copy command.
Title: Copy Command String question
Post by: kjoonlee on 2004-04-04 11:26:50
If you use commas or parentheses in your string, then you'll have to enclose the affected bits with single quotes or you'll get syntax errors.
Title: Copy Command String question
Post by: Strat on 2004-04-05 09:31:00
ahh brilliant. Thanks for that. Yeah I always do a complete selection of the playlist so that code should work fine.

Will go fix it up now.

Thanks heaps. Will post my completed code here for others once I am done

Cheers.
Title: Copy Command String question
Post by: Strat on 2004-04-05 09:57:19
My complete code

Code: [Select]
//HEADER
$if($strcmp(%_playlist_number%,1),

'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> '$crlf()

'<html>'$crlf()

'    <head>'$crlf()
'  <title>Foobar 0.8 - Music List</title>'$crlf()
'  <style TYPE="text/css">'$crlf()
'  <!-- '$crlf()
'  body'$crlf()
'  {'$crlf()
'      margin: 10px 0px 0px 0px;'$crlf()
'      padding: 0;'$crlf()
'      font-family: verdana, arial, sans-serif;'$crlf()
'      font-size: small;'$crlf()
'      color: #ccc;'$crlf()
'      background-color: #000000;'$crlf()
'      text-align: left;'$crlf()
'  }'$crlf()
'  #Album'$crlf()
'  {'$crlf()
'      margin: auto;'$crlf()
'      padding: 0px;'$crlf()
'      border-bottom: 0px;'$crlf()
'      border-top: 2px solid #ccc;'$crlf()
'      border-left: 2px solid #ccc;'$crlf()
'      border-right: 2px solid #ccc;'$crlf()
'      background: #666;'$crlf()
'      width: 615px;'$crlf()
'  }'$crlf()
'  #title'$crlf()
'  {'$crlf()
'      font-weight: bold;'$crlf()
'      border-bottom: 2px solid #ccc;'$crlf()
'      margin: 0px;'$crlf()
'      background: #4C5255;'$crlf()
'  }'$crlf()
'  #Album ul '$crlf()
'  {'$crlf()
'      border: 0;'$crlf()
'      margin: 0;'$crlf()
'      padding: 0;'$crlf()
'      text-align: left;'$crlf()
'      clear: left;'$crlf()
'  }'$crlf()
'  #Album ul li '$crlf()
'  {'$crlf()
'      display: block;'$crlf()
'      text-align: left;'$crlf()
'      padding: 0;'$crlf()
'      padding-left: 10px;'$crlf()
'  }'$crlf()
'  -->'$crlf()
'  </style>'$crlf()
'  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'$crlf()
'  <meta http-equiv="expires" content="-1">'$crlf()
'  <meta http-equiv= "pragma" content="no-cache">'$crlf()
'  <meta name="robots" content="all">'$crlf()
'    </head>'$crlf()$crlf()
    
'<body>'$crlf()
'<div id="Album">' $crlf()
'    <ul>' $crlf()


//BODY
$crlf(),)
$if($strcmp($num(%TRACKNUMBER%,2),01),
'    </ul>'
'</div>' $crlf()
'<div id="Album">' $crlf()
'    <ul>' $crlf()
'        <li id="title">'
)

$if($strcmp($num(%TRACKNUMBER%,2),01),
$if(%artist%,%artist%,'unknown artist') ' - '
$if(%album%,%album%,'unknown album')
'</li>' $crlf()
,)
'        <li>'$num(%TRACKNUMBER%,2). %TITLE%' - ' %_length%'</li>'


//FOOTER
$if($strcmp(%_playlist_number%,%_playlist_total%),$crlf()
'    </ul>'$crlf()
'</div>'$crlf()
'</body>'$crlf()
'</html>'$crlf()
,)


The output is similar to the following

http://members.ii.net/~u4996a/music.html (http://members.ii.net/~u4996a/music.html)

Keep in mind that it only really deals with full albums and they must be tagged properly (track # etc). Doesn't handle compilations very well.

Thanks for the help.
Title: Copy Command String question
Post by: pix on 2004-04-18 05:00:46
Sorry for the newbishness, but where in Foobar2k do I enter this code?
Title: Copy Command String question
Post by: kjoonlee on 2004-04-18 05:08:10
1. Enter preferrences, Display, Title formatting.
2. Click on "Copy command" in the right pane.
3. Enter any code you want into the space below.
4. Select all files in playlist, and issue the copy command. (Default command: Control-C)

Code will be copied into your Windows clipboard.

5. Open a text editor.
6. Paste from clipboard.
7. Save as text or HTML.
Title: Copy Command String question
Post by: kjoonlee on 2004-04-18 05:12:59
Look here if you need UTF-8.

http://www.hydrogenaudio.org/show.php/showtopic/13807 (http://www.hydrogenaudio.org/show.php/showtopic/13807)
Title: Copy Command String question
Post by: LordSlash5 on 2004-04-18 05:48:20
http://www.cs.fredonia.edu/~wiss9895/foobar2000/ (http://www.cs.fredonia.edu/~wiss9895/foobar2000/)

Some of my lists are simply too big to be displayed all at once. I also tried javascript and expanding/collapsing "folders" of mp3s. This didn't work well because my list of files sometimes was bigger than 2MB. It would take a long time to load. With this script, it may turn out to be 2MB or bigger, BUT the server handles all the load and sends the client browser only what it needs.

This requires you have PHP installed on the server you are putting the playlist on. Save it has a .php file instead of .html.

It's pretty dirty code but you get the idea 
Quote
// Foobar2000
// PHP Generator v1 by Slash demodevil5@yahoo.com
//

$if($strcmp(%_playlist_number%,1),
'<?php'$crlf()
'// Request Varibles'$crlf()
'$field   = $_REQUEST["field"];'$crlf()
'$value   = $_REQUEST["value"];'$crlf()

'$value   = urldecode("$value");'$crlf()

'$value  = stripslashes("$value");'$crlf()

'// Variables'$crlf()
'$i = 0;'$crlf()
'$artist = array();'$crlf()
'$album   = array();'$crlf()
'$date = array();'$crlf()
'$number = array();'$crlf()
'$title   = array();'$crlf()
'$length   = array();'$crlf()

$crlf(),)

// Tracks
'$artist[$i]="'%artist%'";'
'$album[$i]="'%album%'";'
'$date[$i]="'%date%'";'
'$number[$i]="'%tracknumber%'";'
'$title[$i]="'%title%'";'
'$length[$i]="'%_length%'";'
'$i++;'

// Footer
$if($strcmp(%_playlist_number%,%_playlist_total%),$crlf()

'echo "<HTML><HEAD><TITLE>Music Collection Listing</TITLE>'$crlf()
'<link rel=\"stylesheet\" type=\"text/css\" href=\"bunny.css\">'$crlf()
'</HEAD><BODY><CENTER>";'$crlf()

'echo "<TABLE WIDTH=\"90%\"><TR><TD><CENTER><FONT SIZE=\"4\">Music Collection Listing</FONT><BR>Generated by '%_foobar2000_version%'<BR><B>'%_playlist_total%'</B> Files Total</CENTER></TD></TR></TABLE><BR>";'$crlf()

'if($field) {'$crlf()

'   if($field == "artist") {'$crlf()

'  echo "<TABLE WIDTH=\"90%\">";'$crlf()
'  echo "<TR><TD COLSPAN=\"2\"><B>$value</B> Albums</TD></TR>";'$crlf()

'  $previous_album = "";'$crlf()

'  for($j = 0; $j < $i; $j++) {'$crlf()
'  if($album[$j] != $previous_album) {'$crlf()
'    if($artist[$j] == $value) {'$crlf()
'     $passvalue = urlencode("$album[$j]");'$crlf()
'     echo "<TR><TD WIDTH=\"5%\">$date[$j]</TD><TD><A HREF=\"$PHP_SELF?field=album&value=$passvalue\">$album[$j]</A></TD></TR>";'$crlf()
'     $previous_album = $album[$j];'$crlf()
'    }'$crlf()
'  }'$crlf()
'  }'$crlf()

'   }'$crlf()
   
'   else if($field == "album") {'$crlf()
'  echo "<TABLE WIDTH=\"90%\">";'$crlf()
'  echo "<TR><TD COLSPAN=\"3\"><B>$value</B> Tracks</TD></TR>";'$crlf()

'  $previous_title = "";'$crlf()

'  for($j = 0; $j < $i; $j++) {'$crlf()
'  if($title[$j] != $previous_title) {'$crlf()
'    if($album[$j] == $value) {'$crlf()
'     echo "<TR><TD WIDTH=\"5%\">$number[$j]</TD><TD>$title[$j]</TD><TD WIDTH=\"10%\">$length[$j]</TD></TR>";'$crlf()
'     $previous_title = $title[$j];'$crlf()
'    }'$crlf()
'  }'$crlf()
'  }'$crlf()


'   }'$crlf()

'   else {'$crlf()
'  echo "Not Found. Press Back and try again";'$crlf()
'   }'$crlf()

'}'$crlf()

'else {'$crlf()
'   echo "<TABLE WIDTH=\"90%\">";'$crlf()
'   echo "<TR><TD COLSPAN=\"4\"><B>Artists</B></TD></TR>";'$crlf()

'   $x = 0;'$crlf()
'   $previous_name = "";'$crlf()

'   for($j = 0; $j < $i; $j++) {'$crlf()
'  if($artist[$j] != $previous_name) {'$crlf()
'  if($x == 0)'$crlf()
'    echo "<TR>";'$crlf()

'  $passvalue = urlencode("$artist[$j]");'$crlf()
'  echo "<TD><A HREF=\"$PHP_SELF?field=artist&value=$passvalue\">$artist[$j]</TD>";'$crlf()
'  $previous_name = $artist[$j];'$crlf()
'  $x++;'$crlf()
 
'  if($x == 4) {'$crlf()
'    echo "</TR>";'$crlf()
'    $x = 0;'$crlf()
'  }'$crlf()
'  }'$crlf()
'   }'$crlf()
'}'$crlf()

'echo "</TABLE></CENTER></BODY></HTML>";'$crlf()

'?>'$crlf()

,)
Title: Copy Command String question
Post by: pix on 2004-04-18 06:51:06
Is there just a way to make a quick and simple .txt file?
Title: Copy Command String question
Post by: kjoonlee on 2004-04-18 07:06:41
Quote
Is there just a way to make a quick and simple .txt file?

Yes. Use quick and simple code! The default values will work.
Title: Copy Command String question
Post by: pix on 2004-04-18 07:10:16
What are the default values, I replaced them.
Title: Copy Command String question
Post by: kjoonlee on 2004-04-18 07:29:21
[$num(%_playlist_number%,$len(%_playlist_total%)). ][%artist% - ]$if(%title%,['['%album%[ #[%disc%/]$num(%tracknumber%,2)]'] ']%title%,%_filename_ext%)[ '['%_length%']']
Title: Copy Command String question
Post by: ExUser on 2004-04-18 08:26:48
If you're going to throw a DOCTYPE on your file, why not make it valid XHTML 1.1? That way you're cutting-edge, and thus much more cool.
Title: Copy Command String question
Post by: Strat on 2004-04-18 08:35:37
Just be grateful i didn't use Tables, Frames and Popups
Title: Copy Command String question
Post by: Diablo on 2004-04-18 14:16:55
Quote
http://www.cs.fredonia.edu/~wiss9895/foobar2000/ (http://www.cs.fredonia.edu/~wiss9895/foobar2000/)

It handles albums with various artists badly
Title: Copy Command String question
Post by: toroco on 2004-04-18 17:16:54
I got this error on my complete file list (but not with a single album), maybe any tags are borked...

Code: [Select]
Parse error: parse error, unexpected '\"' in [...] on line [...]


I checked my php file and got this line:

Code: [Select]
$artist[$i]="Air";$album[$i]="Le Soleil est Pres de Moi 12"";$date[$i]="1996";$number[$i]="3";$title[$i]="Le Soleil est Pres de Moi (Automator Remix)";$length[$i]="6:18";$i++;


You forgot to point to the the "bunny" style sheet on http://www.cs.fredonia.edu/~wiss9895/foobar2000/bunny.css (http://www.cs.fredonia.edu/~wiss9895/foobar2000/bunny.css)

If the copy command code is unchanged the style sheet has to be in the same directory as the php file.
Title: Copy Command String question
Post by: LordSlash5 on 2004-04-19 01:58:33
Quote
$album[$i]="Le Soleil est Pres de Moi 12""


There are 2 quotes there, that's why its breaking. I guess you would have to change the album tag and remove the double quote at the end. I probably should have escaped " characters.. but thats a lot of work.
Title: Copy Command String question
Post by: negatron on 2004-04-20 13:36:51
So, just started to use foobar200 because I have to remake my mp3 pages. I'm having a small problems with this whole "Copy Command" thing, and I hope you guys can help me.

I've tried to make a list that will show the information like this: directory/album - track_number - artist - track_title. And that works about right. But the hard part is that I'd like to add the number of track and the total playtime of the list to the bottom of the list. So there would be a line saying "Tracks: xxx, total playtime: hh:mm:ss". But just can't make it happen.
So if someone could help me with this, I'd be really happy :D

PS. sorry about my English, it's not my native tongue. Hope you still understand it :)
Title: Copy Command String question
Post by: LordSlash5 on 2004-04-21 00:47:39
Check the 2nd reply. You need to add a check to see if it is the last file on the playlist- In other words, if playlist_number = playlist_total. Like this:

$if($strcmp(%_playlist_number%,%_playlist_total%),

Total Tracks, playtime, etc

,)
Title: Copy Command String question
Post by: negatron on 2004-04-21 09:30:50
So, got it partly working now. Only problem is that I can't find an option which would show the total playtime of the playlist. Is that even possible? I can see the total playtime if I choose all the tracks and choose properties, but I can't find how to put that into the output file.
Title: Copy Command String question
Post by: R2D2 on 2004-06-18 22:43:34
LordSlash5: I love that code...thanks.

But I need it to look a bit different.

I am a concert trader..so if you have any free time, could you rewrite this a bit?

I don't know how it works, but it uses some sort of database, right? Is it possible to add many playlists to the database?

If this works, or if it works in some kind of way, is it possible to list first the playlist name, and if you click that playlist name, it shows all different albums in that playlist, and if you click one album, it shows a list of all tracks on that album?
If you could do this, you would be the best!!
Title: Copy Command String question
Post by: John Doe on 2004-06-20 13:17:23
@ Strat:

//offtopic:

Saw the Test CD by accident in your list - is it a CD for testing your amp system setup? If so - where'd you get it? Would like to check my setup as well!!
Title: Copy Command String question
Post by: kamijo on 2004-09-25 21:49:23
[marked for deletion]