Added new feature to enable videos to be recompressed.
[videoscripts/.git] / make_home_videos.cmd
1 #!/bin/bash
2 # DESCRIPTION:
3 # Wrapper script around make_home_videos.pl script that
4 # facilitates copying over the daily_clips to another
5 # linux server location, properly merging the clips
6 # created with the existing clips and playlists on
7 # the remote server.
8 # USAGE:   make_home_videos.cmd <tapename>
9 # EXAMPLE: make_home_videos.cmd Dec06-Apr07
10
11 SERVER="/naspool/videos/HomeVideos"
12 MAKE_VIDEOS="/naspool/videos/bin/make_home_videos.pl"
13
14 $MAKE_VIDEOS -e -c -m -p -a -n $*
15
16 # Copy the daily clips over to the main file server
17 pushd "$*/daily_clips" > /dev/null
18 lastyear=""
19 for i in `/bin/ls -1 *.avi`;
20 do 
21   filename=`echo "$i" | sed 's/.avi//g'`
22   year=`echo "$filename" | awk --field-separator - '{print $1}'`
23   month=`echo "$filename" | awk --field-separator - '{print $2}'`
24   day=`echo "$filename" | awk --field-separator - '{print $3}'`
25
26   # set lastyear if we haven't done so yet
27   if [[ -z "$lastyear" ]]; 
28   then
29     lastyear="$year"
30   fi
31
32   # if we have changed year directories, remake the playlists for lastyear
33   if [[ "$year" != "$lastyear" ]]; 
34   then
35     pushd "$SERVER/$lastyear" > /dev/null
36     $MAKE_VIDEOS -p -d .
37     popd > /dev/null
38   fi
39
40   # make the destination directory if it is missing
41   if [[ ! -d "$SERVER/$year" ]]; 
42   then 
43     mkdir "$SERVER/$year"
44   fi
45
46   # don't overwrite existing filenames
47   basefilename="$filename"
48   num=0
49   while [[ -f "$SERVER/$year/$filename.avi" ]];
50   do 
51     ((num++))
52     filename="$basefilename.$num"
53   done
54
55   echo "Copying $i to $SERVER/$year/$filename.avi"
56   cp "$i" "$SERVER/$year/$filename.avi"
57   
58   lastyear=$year
59 done
60
61 # remake the playlists for year
62 pushd "$SERVER/$year" > /dev/null
63 $MAKE_VIDEOS -p -d .
64 popd > /dev/null
65
66 popd > /dev/null
67
68 echo "-> Rebooting the system in 10 seconds... Press CTRL-C to abort..."
69 sleep 10
70 echo "-> Rebooting now..."
71 # chmod u+s /sbin/reboot if you can't run the below command without being root
72 /sbin/reboot
73