kodi2booklet.pl
#!/usr/bin/perl ############################################################################################################################## ### kodi2booklet.pl --- build a pdf booklet of movie descriptions according KODI movie database ... ### (c)2016 by Ing. Peter Grobner ############################################################################################################################## ### Configure ... my @PIPE=(); my $OUTPUT; # eg. 'Filmarchiv' my $KODI_IP; # eg. '192.168.168.88' my $DATABASE; # eg. 'MyVideos93.db' foreach(@ARGV) { @PIPE= if(/^-$/); $OUTPUT=$1 if(/^(.*)\.pdf$/); $KODI_IP=$1 if(/^(\d+\.\d+\.\d+\.\d+)$/); $DATABASE=$1 if(/^(\w+\.db)$/); } print(),exit if(!$KODI_IP or !$DATABASE or !$OUTPUT); my $EXCEPT=join '|',grep /^[^!].*\.(avi|mp4|mkv)$/, (@ARGV,@PIPE); my $IGNORE=join '|',map { s/^!//; $_ } grep /^!(.*)$/,(@ARGV,@PIPE); $EXCEPT=~s/\n//sg; $EXCEPT=~s/([.*+(\{[\]})])/\\$1/sg; $IGNORE=~s/\n//sg; $IGNORE=~s/([.*+(\{[\]})])/\\$1/sg; ############################################################################################################################## # Prerequisites: scp, sqlite3, date, wget, mogrify, wkhtmltopdf, pdf2ps, psbook, psnup, ps2pdf # Parse::CSV, Unicode::Collate ############################################################################################################################## ### get movie database from KODI & convert it to csv ... qx{ scp root\@$KODI_IP:.kodi/userdata/Database/$DATABASE . sqlite3 $DATABASE <new(file=>'movie_view.csv', names=>1); # idMovie,idFile,c00,c01,c02,c03,c04,c05,c06,c07,c08,c09,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20,c21,c22,c23, # idSet,strSet,strFileName,strPath,playCount,lastPlayed,dateAdded,resumeTimeInSeconds,totalTimeInSeconds # see http://kodi.wiki/view/Databases#movieview while(my $r=$parser->fetch) { next if($EXCEPT && $r->{c22}!~m{($EXCEPT)}); next if($IGNORE && $r->{c22}=~m{($IGNORE)}); my $pic= ($r->{c08}=~/http:\/\/(.+?\.jpg)/)? sprintf( qq{},cache($1) ) : qq{ }; my $von= ($r->{c15})? qq{ von $r->{c15}}:''; my $mit= ($r->{c06} and $r->{c06} ne $r->{c15})? qq{ mit $r->{c06}} :''; my $cmp=uc $r->{c00}; ### to avoid pagebreaks, wrap as table ... $dvd{$cmp}=sprintf qq{ %s %s (%d) %s%s%s %s },$pic,$r->{c00},$r->{c07},$r->{c14},$von,$mit,$r->{c01}; } use Unicode::Collate; my $collator = Unicode::Collate::->new(); ### unicode sort ... open OUT, ">:utf8","$OUTPUT.html"; ### build html output ... print OUT qq{ $OUTPUT Stand }.qx{date +%d.%m.%Y}.qq{ }.(join "\n",map $dvd{$_},$collator->sort(keys %dvd)).qq{ }; close OUT; ### and convert html to pdf and as pdf booklet ... Done! qx{wkhtmltopdf "$OUTPUT.html" "$OUTPUT.pdf"}; qx{pdfjam --twoside --offset '5mm 0mm' "$OUTPUT.pdf" -o "$OUTPUT-A4.pdf"}; qx{ pdf2ps "$OUTPUT-A4.pdf" - | psbook | psnup -s0.667 -2 | ps2pdf - "$OUTPUT-A5.pdf"}; ############################################################################################################################## sub cache { my($url,$fn)=(@_,@_); $fn=~s/^.*\///; qx(cd cache; wget "http://$url"; mogrify -geometry 200x "$fn") unless(-r "./cache/$fn"); return "cache/$fn"; } ############################################################################################################################## 1; __DATA__ Make booklet of movies from the kodi-database Usage: kodi2booklet [params] [movie.avi] [movie.mkv] [movie.mp4] ... ! do not list this movie(s) output to this file (eg. "Filmarchiv.dbf") - read list of excepted and ignored movies from STDIN use kodi with this ip (eg. "192.168.168.88") use kodi this kodi database (eg. "MyVideos93.db") -h print this help build a pdf booklet of movie descriptions according KODI movie database ...(5.2kB) Download | Willkommen || Index || News || Drucken || Login | Impressum: Ing. Peter Grobner, A-3340 Waidhofen an der Ybbs, Unter der Leithen 3a Version vom 2019-12-15 19:04:04 von Admin
%s
build a pdf booklet of movie descriptions according KODI movie database ...(5.2kB)
Download