LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-12-2012, 10:32 PM   #1
wgcooley
LQ Newbie
 
Registered: Dec 2012
Posts: 3

Rep: Reputation: Disabled
Script to build web page of movies from directories


Hello! I'm new to linux. I installed DD-WRT onto a router and have it serving movies over http. I'd like to build a web page of all the movie poster art so my kids can easily choose a movie from the home page.

All movies are in /mnt/Videos. Some movies are in the root directory, but there are sub-directories with movies (/mnt/Videos/Barney, /mnt/Videos/Sesame Street, etc). For each movie there is a jpg image of the DVD cover, named exactly the same as the movie (i.e., Toy Story.m4v and Toy Story.jpg)

How do I make a script that reads in all videos (including sub-directores), then builds an index.html of movie art jpg in two columns with as many rows as necessary (n x 2)? When the kids click on the picture, it should link to the movie file.

BTW, the media server works very well and uses hardly any power. I wrote up the install at:
http://www.dd-wrt.com/phpBB2/viewtop...=asc&start=315
 
Old 12-13-2012, 07:58 PM   #2
cbtshare
Member
 
Registered: Jul 2009
Posts: 610

Rep: Reputation: 42
this is a place where you get help ,if you have something that you have done we can assist but we rarely complete everything for you...
 
Old 12-13-2012, 10:15 PM   #3
wgcooley
LQ Newbie
 
Registered: Dec 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Wow. Thanks for the warm welcome on my first post here. I was expecting some guidance like "use this command," not go someplace else.

Here's what I was thinking...

#!/opt/bin/sh
rm index.html
<<don't need help with code to build html header and table>>
i=0
for file in /mnt/Videos/*jpg
do
i=i+1
<<code to assign row/column of movie poseter based on i>>
new variable = need help figuring our how change the ".jpg" in $file to ".m4v"
need help with writing to a file <a href="new variable"</a>
done

I also toyed around with using "find . -name *m4v > names.txt" then looping through the file to create the html code.

I'm asking for your help strategizing the best methods and commands to use, not to write the script for me.
 
Old 12-14-2012, 01:36 PM   #4
montel
Member
 
Registered: Jun 2012
Location: Canada
Distribution: Ubuntu/Debian/CentOS
Posts: 45

Rep: Reputation: 18
No need to get offended by what he said, he was just giving you feedback saying that you would most likely not get a good response unless you post what you have attempted/have so far. This isn't really a place to have people do things for you, its a community of people helping/learning.

That said, I am not entirely sure how you should tackle this, and not a linux guru, but my first thought was something like this:
##EDIT: I like my second one better.

This will list out the poster and movie as it comes across them. But I am pretty sure after writing this, there is some logical flaws with doing it this way.
Code:
#!/bin/bash
rdir="/tmp/grabtest/"*

for file in $rdir
do
#echo $file
        ndir="$file"

        for i in "$ndir/"*
        do
                #echo $i
                if [[ $i == *.jpg ]];then
                        poster=$i
                        echo "poster is $poster"
                fi
                if [[ $i == *.m4v ]];then
                        movie=$i
                        echo "movie is $movie"
                fi
        done
done
Then I was thinking about what you were doing with Find, and thought maybe something like this:

I left in the echos, i was just using them to test.
Code:
#!/bin/bash
rm /tmp/m4list

find /tmp/grabtest/ -name *.m4v > /tmp/m4list

#cat /tmp/m4list
file=/tmp/m4list

while read line;do
        echo $line is found
        p=${line##*/}
        name=${p%.m4v}
        #HTML to link to file could be here
        echo "<a href='$line'>$name</a>" >> /var/www/index.html
        echo $name
        t="${line%/*}/"
        poster="$t$name.jpg"

        if [[ -f $poster ]];then
                echo "poster exists"
                #do whatever HTML you need.
        fi

done < "$file"
These are pretty crude examples, but should give you at least an idea. I am at work right now, so I was trying to speed through it.

Hope it helps,

Last edited by montel; 12-14-2012 at 01:38 PM. Reason: ##edit
 
Old 12-16-2012, 08:26 PM   #5
wgcooley
LQ Newbie
 
Registered: Dec 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
I ended up using find to create a list of all files on the drive. I think looked at the last four characters to see if the string was the movie (ending in m4v). The script works great. Thanks for the help.

!/bin/bash

rm sorted_names
rm movies.html
find | sort -n > sorted_names

FILENAME=sorted_names

while read LINE
do
ext=$(echo $LINE | tail -c -4)

if [[ "$ext" == "m4v" ]]
then
echo "<a href=\"$LINE\" >" >> movies.html
echo "<img src=\"${LINE%????}.jpg\" width=\"360\" height=\"510\" />" >> movies.html
fi

done < $FILENAME
rm sorted_names
 
Old 12-17-2012, 10:31 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Ok ... so the second thing to cover is, please use [code][/code] tags around data and code as it will preserve formatting and make it easier to read.

You are on to some better ideas so let us see if we can get you over the line.
How about something like:
Code:
#!/bin/bash

movie_dir='/mnt/Videos'
html_file='movies.html'

rm "$html_file"

while read -r picture
do
    movie="${picture%.*}.m4v"

    cat >> $html_file <<-EOF
        <a href="$movie" >
        <img src="$picture" width="360" height="510" />
EOF
done< <(find "$movie_dir" -type f -name '*.jpg')
Not tested or complete but you get the idea
 
Old 12-17-2012, 12:47 PM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
The solution posted by grail works iff all JPEGs in the directory tree are associated with a movie file. The more rigorous solution would find all movies, and from that, compose the respective JPEG filename. Actually, I see that is the algorithm used by montel, but merely using a temporary file to store the list of found files. It isn't stated in the original question, but montel's algorithm could also flag any movies that do not have an associated JPEG, and perhaps put a dummy image into the HTML output.
Always a good idea to assume the possibility of errors.

--- rod.
 
Old 12-17-2012, 12:52 PM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,026

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
this seems related (although not html).
http://www.linuxquestions.org/questi...4/#post3508846

have you considered using xbmc ?
 
Old 12-17-2012, 01:04 PM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
hmmm ... so you have marked the problem as solved but given no ideas on what your solution is?

Remember from the first 2 posts, you were advised that we are here to help each other and when someone new searches the site they get the benefit of
learning from you
 
Old 12-19-2012, 10:33 AM   #10
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
The LinuxCommand tutorial exercise is all about automating the building of an html page. It should help you out.
 
Old 12-19-2012, 06:13 PM   #11
propofol
Member
 
Registered: Nov 2007
Location: Seattle
Distribution: Debian Wheezy & Jessie; Ubuntu
Posts: 331

Rep: Reputation: 59
One thing to consider is using PHP on the server to create the page dynamically each time it is requested. PHP would be a better tool than Bash to accomplish what you have in mind. Have a look at: http://www.howtogeek.com/howto/progr...n-a-directory/

Regards,
Stefan
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
executing linux commands from web page and outputing it back to the web page ashes_sheldon Programming 9 02-28-2015 01:07 AM
How To Protect Web Page Directories With Passwords ramecare Linux - Server 1 06-27-2011 07:39 AM
[SOLVED] How to execute bash script from web page mustkill Linux - Server 16 05-20-2010 12:01 PM
remote computers cannot spider my web page directories jacksonscottsly Linux - Networking 4 07-02-2004 06:10 PM
Kicking off a script form a web page Hazzie Programming 2 04-26-2004 02:09 PM


All times are GMT -5. The time now is 10:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration