Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
OGG/MP3 webifyer
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
arkane
l33t
l33t


Joined: 30 Apr 2002
Posts: 918
Location: Phoenix, AZ

PostPosted: Sun Nov 03, 2002 6:22 am    Post subject: OGG/MP3 webifyer Reply with quote

I just wrote a small script to use locally to give me complete details on my OGG files within a web interface. This script is started at the root of a directory tree containing other directories with OGG or MP3 files in them. It iterates down through each directory, creating an index.html within each directory (including the root you start it in), putting the names of the files into the index.html in a nice, neat fashion. I needed something like this locally on this net for my wife and I and the ones available seemed to want to do too much and not enough of what I wanted. I have my http://localhost/music directory as the start of the tree, and I run this script there. (on the commandline, not as a web cgi)
Give it a shot if you'd like. I'm opening it up as GPL for anyone who wants it. (not that it's very advanced, just wanted to share... )
There is a line in the script that is a variable called "$location" that needs to be changed to the full path including filename of the actual script. I can't for the life of me remember how to get the full directory and filename of the current perl script running, so this takes it's place.
It's not optimized, it's not the best there is. You will probably want to change things around, but it is very changable :)
This is like version 0.02 or something.. 0.01 didn't do anything with tables, it was all straight forward. This lays everything out in tables.
Enjoy.

Code:

#!/usr/bin/perl
#
# Makes an index.html file containing
# links to every file in the directory

# Location of this (HACK.. need to find a way around this)
$location = $0;
# font size used on headers (titles such as "files available")
$headerfontsize = 4;
# Files that are analyzed have these extensions
@files = <*.ogg *.OGG *.mp3 *.MP3>;
# default html file written in each directory analyzed
$html = "index.html";
# Array used for list of subdirectories
@directories;

foreach $listing (<*>) {
  if(-d $listing) {
    push(@directories, $listing);
    print("Heading into $listing\n");
    system("cd $listing && exec $location ");
  }
}


# Open HTML file for writing
open(FILE, ">$html") || die "Can't open file: $!\n";
select(FILE);

# Start HTML file
print("<html>\n<head>\n");
#print("<title>Files Listed</title>\n");
print("<TITLE>" . `pwd` . "</TITLE>\n");
print("</head>\n<body>");
open_table("100");
print("<TR>\n<TD ALIGN=\"center\" BGCOLOR=\"#330099\">\n");
print("<FONT SIZE=\"6\" COLOR=\"white\"><B>Audio Listing</B></FONT><BR>\n");
print("</TD>\n</TR>\n");
print("<TR>\n<TD VALIGN=\"top\" BGCOLOR=\"#FFFFFF\">\n");
print("<FONT SIZE=\"$headerfontsize\"><B>Subdirectories Available</B></FONT><BR><BR>\n");
print("</TD></TR>\n");
print("</TBODY>\n");
print("</TABLE>\n");                                                                                       
open_table("100");
print("<TR  VALIGN=\"top\" BGCOLOR=\"#FFFFFF\">\n");
# setup counter for iteration of tables for subdirectory listing
$count = 0;
foreach $subdirectory (@directories) {
  $count++;
  print("<TD>\n");
  print("<A HREF=\"$subdirectory\">$subdirectory</A><BR>\n");
  print("</TD>\n");
  if($count == 3) {
    print("</TR>\n<TR>\n");
    $count = 0;
  }
}
print("</TR>\n");
print("</TBODY>\n");
print("</TABLE>\n");
open_table("100");
print("<TR>\n<TD VALIGN=\"top\" BGCOLOR=\"#330099\" WIDTH=\"100%\">\n");
print("<BR>\n</TD>\n</TR>\n");
print("<TR>\n<TD VALIGN=\"top\" BGCOLOR=\"#FFFFFF\" WIDTH=\"100%\">\n");
print("<FONT SIZE=\"$headerfontsize\"><B>Files Available</B></FONT>\n");
print("</TD>\n</TR>\n");
print("</TBODY>\n");
print("</TABLE>\n");                                                                                       
open_table("100");
print("<TR>\n");
# Iterate through files listed, href'ing each
$countagain = 0;
foreach (@files) {
  $temp1 = $_;
  $countagain++;
  print("<TD VALIGN=\"top\" BGCOLOR=\"#FFFFFF\">\n");
  # Keeps the index.html being written from showing up
  if(!/index.html/) {                       
    print("<a href=\"$temp1\">$temp1</a>\n");
  }
  # Work information out of OGG files with ogginfo
  # displaying it below the file listing                   
  if(/.ogg/i) {
    @ogginfo = `ogginfo \"$temp1\"`;
    @oggtitle = grep /title=/, @ogginfo;
    @oggtitle[0] =~ s/title=//ig;
    @oggartistname = grep(/artist=/, @ogginfo);
    @oggartistname[0] =~ s/artist=//ig;
    @oggaveragebitrate = grep(/Average bitrate/, @ogginfo);
    @oggaveragebitrate[0] =~ s/Average bitrate://ig;
    @oggplaybacklength = grep(/Playback length/, @ogginfo);
    @oggplaybacklength[0] =~ s/Playback length//ig;
    print("<br><font size=\"3\">Title: @oggtitle &nbsp;&nbsp;&nbsp;&nbsp;\n");
    print("Artist Name: @oggartistname<br>\n");
    print("Average Bitrate: @oggaveragebitrate &nbsp;&nbsp;&nbsp;&nbsp;\n");
    print("Playback Length: @oggplaybacklength\n");
  }
  print("</TD>\n");
  if( $countagain == 2 ) {
    print("</TR>\n<TR>\n");
    $countagain = 0;
  }
}
print("</TR>\n");
print("</TBODY>\n");
print("</TABLE>");
credits();
close(FILE);

sub credits {
  print("<BR><BR><BR><FONT SIZE=\"2\"><i>\n");
  print("Automatically created with ls2html Perl Script<BR>\n");                 
  print("Copyright(c) 2002 Norman Lund (dan_lund\@hotmail.com)<BR>\n");
  print("Script is distributed under the GNU Public License (GPL)\n");           
  print("</FONT></i>\n");
  print("</body>\n</html>\n");
}

sub open_table {
  my($mywidth) = @_;
  print("<TABLE CELLPADDING=\"2\" CELLSPACING=\"2\" BORDER=\"1\" WIDTH=\"$mywidth%\">\n");
  print("<TBODY>\n");
}


EDIT: Changed the $location variable to use $0 isntead of a hardcoded path to the program.
Tested it on my system, and works great. I have my script in a subdirectory of my home directory, and always call it directly. (would work if in your path too, I would imagine)


Last edited by arkane on Sun Nov 03, 2002 3:52 pm; edited 2 times in total
Back to top
View user's profile Send private message
Craigo
Apprentice
Apprentice


Joined: 09 Aug 2002
Posts: 249
Location: /dev/life

PostPosted: Sun Nov 03, 2002 12:03 pm    Post subject: Reply with quote

I really like this script, I'm hacking it up to my own settings. Though I haven't actually learn perl at all but I give this one as my first go!

Cheers.

-/Craigo/-
Back to top
View user's profile Send private message
lazarusrat
Guru
Guru


Joined: 17 Jul 2002
Posts: 305
Location: Lafayette, IN

PostPosted: Sun Nov 03, 2002 3:32 pm    Post subject: Reply with quote

The program name in perl is given by $0 (that's a zero).
Note you've got to call the script with its full path to get the path, otherwise you just get whatever you called it with. So if you typed:
Code:
./script.pl

$0 would contain "./script.pl"
Back to top
View user's profile Send private message
arkane
l33t
l33t


Joined: 30 Apr 2002
Posts: 918
Location: Phoenix, AZ

PostPosted: Sun Nov 03, 2002 3:55 pm    Post subject: Reply with quote

Great, thanks alot, lazarusrat. I'm not a professional at Perl hacking, and I missed that part :)

I updated the $location variable to be "$location = $0" and it works like a charm. Thanks again.
(update above, also)

Glad it can be of some use to you, Craigo.
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 17808

PostPosted: Sun Nov 03, 2002 9:22 pm    Post subject: Reply with quote

Good things come to those who procrastinate.
_________________

Believing I had supernatural powers I slammed into a brick wall.
I said hey, is this my problem? Is this my fault?
Back to top
View user's profile Send private message
arkane
l33t
l33t


Joined: 30 Apr 2002
Posts: 918
Location: Phoenix, AZ

PostPosted: Thu Nov 14, 2002 10:57 pm    Post subject: Reply with quote

I know it's a small script and all, but I added a sourceforge.net page for it, hoping to extend it to more. (clientside virtues of course)

http://www.sourceforge.net/projects/ls2html

some of you might have seen the freshmeat announcement.
Back to top
View user's profile Send private message
nikolei
n00b
n00b


Joined: 15 Dec 2003
Posts: 37

PostPosted: Mon Dec 15, 2003 12:17 pm    Post subject: mp3riot Reply with quote

Hi,

I have my own script called mp3riot (formerly known as f2html.pl). I does a lot of stuff and is very flexible. You can download it under http://www.linuxsecure.de/index.php?action=55.

So check it out.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum