Updated for Ubuntu 22.04. Also fixed merge videos cmin check
[videoscripts/.git] / copy_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:   copy_home_videos.cmd <tapename>
9 # EXAMPLE: copy_home_videos.cmd Dec06-Apr07
10
11 SERVER="/mnt/p/video/HomeVideos"
12
13 # Copy the daily clips over to the main file server
14 pushd "$*/daily_clips" > /dev/null
15 lastyear=""
16 for i in `/bin/ls -1 *.avi`;
17 do 
18   filename=`echo "$i" | sed 's/.avi//g'`
19   year=`echo "$filename" | awk --field-separator - '{print $1}'`
20   month=`echo "$filename" | awk --field-separator - '{print $2}'`
21   day=`echo "$filename" | awk --field-separator - '{print $3}'`
22
23   # set lastyear if we haven't done so yet
24   if [[ -z "$lastyear" ]]; 
25   then
26     lastyear="$year"
27   fi
28
29   # if we have changed year directories, remake the playlists for lastyear
30   if [[ "$year" != "$lastyear" ]]; 
31   then
32     pushd "$SERVER/$lastyear" > /dev/null
33     make_home_videos.pl -p -d .
34     popd > /dev/null
35   fi
36
37   # make the destination directory if it is missing
38   if [[ ! -d "$SERVER/$year" ]]; 
39   then 
40     mkdir "$SERVER/$year"
41   fi
42
43   # don't overwrite existing filenames
44   basefilename="$filename"
45   num=0
46   while [[ -f "$SERVER/$year/$filename.avi" ]];
47   do 
48     ((num++))
49     filename="$basefilename.$num"
50   done
51
52   echo "Copying $i to $SERVER/$year/$filename.avi"
53   cp "$i" "$SERVER/$year/$filename.avi"
54   
55   lastyear=$year
56 done
57
58 # remake the playlists for year
59 pushd "$SERVER/$year" > /dev/null
60 make_home_videos.pl -p -d .
61 popd > /dev/null
62
63 popd > /dev/null
64