List all files.
[ls2html_00z.git] / ls2html.pl
blob428b0f0f4792a035ba0abcc74737ad503d23ac30
1 #!/usr/bin/perl
3 # Makes an index.html file containing
4 # links to every file in the directory
6 # Modified by Abel `00z' Camarillo <00z@the00z.org> 2008/6/22
8 ##########################################################
9 # User configuration variables #
10 ##########################################################
12 $header = qq/Complete listing.../;
13 # Location of this (HACK.. need to find a way around this)
14 #$location = "/home/arkane/scripts/ls2html.pl";
15 $location = $0;
16 # font size used on headers (titles such as "files available")
17 $headerfontsize = 4;
18 # Files that are analyzed have these extensions
19 #@files = <*.ogg *.OGG *.mp3 *.MP3>;
20 @files = <*>;
21 # default html file written in each directory analyzed
22 $html = "index.html";
23 # Array used for list of subdirectories
24 @directories;
26 ##########################################################
27 # Main #
28 ##########################################################
30 foreach $listing (<*>) {
31 if(-d $listing) {
32 push(@directories, $listing);
33 print("Heading into $listing\n");
34 system("cd $listing && exec $location ");
39 # Open HTML file for writing
40 open(FILE, ">$html") || die "Can't open file: $!\n";
41 select(FILE);
43 # Start HTML file
44 print("<html>\n<head>\n");
45 #print("<title>Files Listed</title>\n");
46 print("<TITLE>" . `pwd` . "</TITLE>\n");
47 print("</head>\n<body>");
48 open_table("100");
49 print("<TR>\n<TD ALIGN=\"center\" BGCOLOR=\"#330099\">\n");
50 print("<FONT SIZE=\"6\" COLOR=\"white\"><B>", $header, "</B></FONT><BR>\n");
51 print("</TD>\n</TR>\n");
52 print("<TR>\n<TD VALIGN=\"top\" BGCOLOR=\"#FFFFFF\">\n");
53 print("<FONT SIZE=\"$headerfontsize\"><B>Subdirectories Available</B></FONT><BR><BR>\n");
54 print("</TD></TR>\n");
55 print("</TBODY>\n");
56 print("</TABLE>\n");
57 open_table("100");
58 print("<TR VALIGN=\"top\" BGCOLOR=\"#FFFFFF\">\n");
59 # setup counter for iteration of tables for subdirectory listing
60 $count = 0;
61 foreach $subdirectory (@directories) {
62 $count++;
63 print("<TD>\n");
64 print("<A HREF=\"$subdirectory\">$subdirectory</A><BR>\n");
65 print("</TD>\n");
66 if($count == 3) {
67 print("</TR>\n<TR>\n");
68 $count = 0;
71 print("</TR>\n");
72 print("</TBODY>\n");
73 print("</TABLE>\n");
74 open_table("100");
75 print("<TR>\n<TD VALIGN=\"top\" BGCOLOR=\"#330099\" WIDTH=\"100%\">\n");
76 print("<BR>\n</TD>\n</TR>\n");
77 print("<TR>\n<TD VALIGN=\"top\" BGCOLOR=\"#FFFFFF\" WIDTH=\"100%\">\n");
78 print("<FONT SIZE=\"$headerfontsize\"><B>Files Available</B></FONT>\n");
79 print("</TD>\n</TR>\n");
80 print("</TBODY>\n");
81 print("</TABLE>\n");
82 open_table("100");
83 print("<TR>\n");
84 # Iterate through files listed, href'ing each
85 $countagain = 0;
86 foreach (@files) {
87 $temp1 = $_;
88 $countagain++;
89 print("<TD VALIGN=\"top\" BGCOLOR=\"#FFFFFF\">\n");
90 # Keeps the index.html being written from showing up
91 if(!/index.html/) {
92 print("<a href=\"$temp1\">$temp1</a>\n");
94 # Work information out of OGG files with ogginfo
95 # displaying it below the file listing
96 if(/.ogg/i) {
97 @ogginfo = `ogginfo \"$temp1\"`;
98 @oggtitle = grep /title=/, @ogginfo;
99 @oggtitle[0] =~ s/title=//ig;
100 @oggartistname = grep(/artist=/, @ogginfo);
101 @oggartistname[0] =~ s/artist=//ig;
102 @oggaveragebitrate = grep(/Average bitrate/, @ogginfo);
103 @oggaveragebitrate[0] =~ s/Average bitrate://ig;
104 @oggplaybacklength = grep(/Playback length/, @ogginfo);
105 @oggplaybacklength[0] =~ s/Playback length//ig;
106 print("<br><font size=\"3\">Title: @oggtitle &nbsp;&nbsp;&nbsp;&nbsp;\n");
107 print("Artist Name: @oggartistname<br>\n");
108 print("Average Bitrate: @oggaveragebitrate &nbsp;&nbsp;&nbsp;&nbsp;\n");
109 print("Playback Length: @oggplaybacklength\n");
111 print("</TD>\n");
112 if( $countagain == 2 ) {
113 print("</TR>\n<TR>\n");
114 $countagain = 0;
117 print("</TR>\n");
118 print("</TBODY>\n");
119 print("</TABLE>");
120 credits();
121 close(FILE);
123 sub credits {
124 print("<BR><BR><BR><FONT SIZE=\"2\"><i>\n");
125 print("Automatically created with ls2html Perl Script<BR>\n");
126 print("Copyright(c) 2002 Norman Lund (dan_lund\@hotmail.com)... and modified"
127 . " by Abel `00z' Camarillo <00z\@the00z.org><BR>\n");
128 print("Script is distributed under the GNU Public License (GPL)\n");
129 print("</FONT></i>\n");
130 print("</body>\n</html>\n");
133 sub open_table {
134 my($mywidth) = @_;
135 print("<TABLE CELLPADDING=\"2\" CELLSPACING=\"2\" BORDER=\"1\" WIDTH=\"$mywidth%\">\n");
136 print("<TBODY>\n");