2014-08-10 23:33:36 +00:00
#! /usr/bin/perl -w
2014-10-01 02:19:53 +00:00
# we want to operate on relative links, so set this to the common prefix
# to the git annex repo
2014-08-10 23:33:36 +00:00
my $ prefix = "/home/media/video/" ;
2014-10-01 02:19:53 +00:00
# this is the directory for the XBMC database
my $ path = '/home/video/.xbmc/userdata/Database/' ;
# no user-serviceable parts below
# list videos database, find the latest one
# modified version of
# http://stackoverflow.com/questions/4651092/getting-the-list-of-files-sorted-by-modification-date-in-perl
opendir my ( $ dirh ) , $ path or die "can't opendir $path: $!" ;
my @ flist = sort { - M $ a <=> - M $ b } # Sort by modification time
map { "$path/$_" } # We need full paths for sorting
grep { /^MyVideos.*\.db$/ }
readdir $ dirh ;
closedir $ dirh ;
my $ dbpath = $ flist [ 0 ] ;
2014-08-10 23:33:36 +00:00
my @ lines = `echo 'SELECT playCount, path.strPath, files.strFileName FROM movie JOIN files ON files.idFile=movie.idFile JOIN path ON path.idPath=files.idPath;' | sqlite3 $dbpath` ;
for ( @ lines ) {
my ( $ count , $ dir , $ file ) = split /\|/ ;
chomp $ file ;
2014-08-10 23:48:06 +00:00
# empty or non-numeric count is zero
if ( $ count !~ /[0-9]/ ) {
$ count = 0 ;
}
2014-08-10 23:33:36 +00:00
if ( $ file =~ s #stack://##) {
for ( split /,/ , $ file ) {
s/$prefix// ;
s/^ // ;
s/ $// ;
my @ cmd = ( qw( git annex metadata --set ) , "playCount=$count" , $ _ ) ;
system ( @ cmd ) ;
}
}
else {
2014-10-01 02:19:53 +00:00
$ dir =~ s/$prefix// ;
2014-08-10 23:33:36 +00:00
my @ cmd = ( qw( git annex metadata --set ) , "playCount=$count" , "$dir$file" ) ;
system ( @ cmd ) ;
}
}