diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..e69de29 diff --git a/COPYING b/COPYING new file mode 120000 index 0000000..2fcb217 --- /dev/null +++ b/COPYING @@ -0,0 +1 @@ +/usr/share/automake-1.13/COPYING \ No newline at end of file diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/INSTALL b/INSTALL new file mode 120000 index 0000000..8b641e3 --- /dev/null +++ b/INSTALL @@ -0,0 +1 @@ +/usr/share/automake-1.13/INSTALL \ No newline at end of file diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..00f0488 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +## @id $Id$ + +## 1 2 3 4 5 6 7 8 +## 45678901234567890123456789012345678901234567890123456789012345678901234567890 + +aclocal && automake && autoconf \ No newline at end of file diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..89a6fa6 --- /dev/null +++ b/configure.ac @@ -0,0 +1,9 @@ +## @id $Id$ + +## 1 2 3 4 5 6 7 8 +## 45678901234567890123456789012345678901234567890123456789012345678901234567890 + +AC_INIT([videoweb], [1.0]) +AM_INIT_AUTOMAKE +AC_CONFIG_FILES([makefile src/makefile]) +AC_OUTPUT diff --git a/makefile.am b/makefile.am new file mode 100644 index 0000000..1098db8 --- /dev/null +++ b/makefile.am @@ -0,0 +1,8 @@ +## @id $Id$ + +## 1 2 3 4 5 6 7 8 +## 45678901234567890123456789012345678901234567890123456789012345678901234567890 + +SUBDIRS = src + +MAINTAINERCLEANFILES = aclocal.m4 configure install-sh makefile.in missing diff --git a/src/default.jpg b/src/default.jpg new file mode 100644 index 0000000..734d39c Binary files /dev/null and b/src/default.jpg differ diff --git a/src/index.php b/src/index.php new file mode 100644 index 0000000..3705083 --- /dev/null +++ b/src/index.php @@ -0,0 +1,215 @@ +'; +} + + if (isset($_GET["img"])) { + if (ereg('[^-_.A-Za-z0-9]', $_GET["img"])) { +?> + +

Illegal Image name: ""

+ + + + +

Image not found: ""

+ + + + +

Illegal Video name: ""

+ + +/dev/null'); + break; + case "mp4": + header('Content-type: video/mp4'); + exec('ffmpeg -i "'.$DIR.'/'.$_GET["video"].'" -qscale 4 -vcodec libx264 -f mp4 - 2>/dev/null'); + break; + } + } else { */ +// Clears the cache and prevent unwanted output +ob_clean(); +@ini_set('error_reporting', E_ALL & ~ E_NOTICE); +@apache_setenv('no-gzip', 1); +@ini_set('zlib.output_compression', 'Off'); + +if (isset($_GET["mime"])) + $file = $CONVERT.'/'.$_GET["mime"].'/'.preg_replace('/\.[^.]*$/', '.'.$_GET["mime"], $_GET["video"]); +else + $file = $DIR.'/'.$_GET["video"]; // The media file's location +$size = filesize($file); // The size of the file +$mime = mime_content_type($file); + +// Send the content type header +header('Content-type: ' . $mime); + +// Check if it's a HTTP range request +if(isset($_SERVER['HTTP_RANGE'])){ + // Parse the range header to get the byte offset + $ranges = array_map( + 'intval', // Parse the parts into integer + explode( + '-', // The range separator + substr($_SERVER['HTTP_RANGE'], 6) // Skip the `bytes=` part of the header + ) + ); + + // If the last range param is empty, it means the EOF (End of File) + if(!$ranges[1]){ + $ranges[1] = $size - 1; + } + + // Send the appropriate headers + header('HTTP/1.1 206 Partial Content'); + header('Accept-Ranges: bytes'); + header('Content-Length: ' . ($ranges[1] - $ranges[0])); // The size of the range + + // Send the ranges we offered + header( + sprintf( + 'Content-Range: bytes %d-%d/%d', // The header format + $ranges[0], // The start range + $ranges[1], // The end range + $size // Total size of the file + ) + ); + + // It's time to output the file + $f = fopen($file, 'rb'); // Open the file in binary mode + $chunkSize = 8192; // The size of each chunk to output + + // Seek to the requested start range + fseek($f, $ranges[0]); + + // Start outputting the data + while(true){ + // Check if we have outputted all the data requested + if(ftell($f) >= $ranges[1]){ + break; + } + + // Output the data + echo fread($f, $chunkSize); + + // Flush the buffer immediately + @ob_flush(); + flush(); + } +} +else { + // It's not a range request, output the file anyway + header('Content-Length: ' . $size); + + // Read the file + @readfile($file); + + // and flush the buffer + @ob_flush(); + flush(); +} +// } + } else { +?> + + + +

+
+[Click to Download or copy link to VLC player] +

+ + + + + +

Video not found: ""

+ + + + + + + +

Videofilme

+ + + + diff --git a/src/makefile.am b/src/makefile.am new file mode 100644 index 0000000..b574456 --- /dev/null +++ b/src/makefile.am @@ -0,0 +1,13 @@ +## @id $Id$ + +## 1 2 3 4 5 6 7 8 +## 45678901234567890123456789012345678901234567890123456789012345678901234567890 + +configdir=${sysconfdir}/${PACKAGE} +config_DATA = default.jpg unknown-movie-folder.jpg + +webdatadir= +html_DATA = index.php +bin_SCRIPTS = movieposter.sh towebm.sh + +MAINTAINERCLEANFILES = makefile.in diff --git a/src/movieposter.sh b/src/movieposter.sh new file mode 100755 index 0000000..14749f3 --- /dev/null +++ b/src/movieposter.sh @@ -0,0 +1,205 @@ +#! /bin/bash -e + +echo "$(date) -- $0 $*" >> /tmp/movieposter.log + +# Change this for your environment +SRC_PATH=/var/data/spielfilme +DEFAULT=/etc/movieposter/default.jpg +#DEFAULT=/etc/mediatomb/scripts/unknown-movie-folder.jpg +TARGET_PATH=/var/tmp/spielfilme +DEBUG=1 # set DEBUG to 1 for debugging + +# Normally you don't need to change this +SED_FILTER=' + s,.*/,,; # remove path + s/\.[^.]*$//; # remove extension + s/-[^_]*$//; # remove after last dash if no _ follows + s/_[12][90][0-9][0-9]$//; # remove year at end + s/^[12][90][0-9][0-9]_//; # remove year at begin + s/_*[A-Z][A-Z][A-Z][A-Z]*_*/_/g; # remove word in capitals only + s/__*/_/g; # remove duplicated underscore + s/_$//; # remove trailing whitespaces + /[a-z]/p; # file must contain lowecase letter' +SLEEP=0 +IFS=" +" + +function trace { + if [ $DEBUG -eq 1 ]; then + echo "$*" 1>&2 + fi +} + +# get poster-link from movie database +function findposterurl { + # first try OpenMovieDatabase API + url="http://www.omdbapi.com/?t=$*" + trace " $url" + img=$(wget -q -O- "$url" \ + | sed -n 's/.*Poster":"\([^"]*\)",.*/\1/p'); + if [ -n "$img" -a "$img" != "N/A" ]; then # poster image found + echo "$img" + return + fi + # then try categories movie and tv in The Movie Database + # not using the API, because the API requires a key + for t in movie tv; do + url="http://www.themoviedb.org/search/$t?query=${*// /+}" + trace " $url" + img=$(wget -q -O- "$url" \ + | html2 2> /dev/null \ + | sed -n '0,/\/@class=poster/d; s/.*\/img\/@src=//p' \ + | head -1) + if [ -n "$img" -a "$img" != "N/A" ]; then # poster image found + echo "$img" + return + fi + # make sure there are not too many unsuccessful queries in short time + sleep $SLEEP # don't want http://www.themoviedb.org to exclude me + done +} + +# try to find poster-link from movie databases in two ways: +# unchanged or by removing the last number +function poster { + n="$*" + # try movie name as passed in the arguments + img=$(findposterurl "$n") + if [ -z "$img" ]; then + # try without number at the end or without I at the end + n2=$(echo "$n" | sed 's/ *[0-9]* *$//; s/ I *$//g') + if [ "$n2" == "$n" ]; then return; fi # no number at the end + img=$(findposterurl "$n2") + fi + if [ -n "$img" ]; then + echo "$img"; + fi +} + +function getimage { + f=$(echo "$1" | sed -n "$SED_FILTER") + if [ -z "$f" ]; then + trace "**** ingored: $1" + return + fi + n=${f//_/ }; # moviename is filename with spaces instead of underscore + t="${1%.*}.jpg" # target file name + if test -n "$TARGET_PATH"; then + test -d "$TARGET_PATH" || mkdir -p "$TARGET_PATH"; + t="${TARGET_PATH}/${t##*/}" + fi + echo "$t" + if [ -s "$t" ]; then + trace "**** exists: $t" + return + fi # already downloaded + # try to find movie using full filename + trace "**** $f -> $n" + img=$(poster "$n") + if [ -z "$img" ]; then # no poster found, try with manipulated name + # split filename at "_-_" and sort by length, search for the parts + for n2 in $(echo $n | sed 's/ - /\n/g' \ + | awk '{ print length($0) " " $0; }' | sort -r -n \ + | cut -d ' ' -f 2-); do + if [ "$n" = "$n2" ]; then continue; fi # same - ignore + trace ",,,, $n -> $n2" + img=$(poster "$n2") + if [ -n "$img" ]; then break; fi # found + for n3 in $(echo $n2 | sed 's/-/\n/g' \ + | awk '{ print length($0) " " $0; }' | sort -r -n \ + | cut -d ' ' -f 2-); do # split at -, sort by length + if [ "$n2" = "$n3" ]; then continue; fi # same - ignore + echo ".... $n2 -> $n3" + img=$(poster "$n3") + if [ -n "$img" ]; then break; fi # found + done + done + fi + if [ -n "$img" ]; then + trace "---- Download: $img"; + wget -q -O"$t" $img; + if ! [ -s "$t" ]; then + trace "==== ERROR"; rm "$t"; + fi; + fi; + if ! [ -s "$t" ]; then + trace "++++ Transcoding: $1" + if ! ( ffmpegthumbnailer -i"$1" -o"$t" -f -s400 > /dev/null 2> /dev/null && [ -s "$t" ] ); then + trace "++++ Copy Default: $DEFAULT" + cp "$DEFAULT" "$t" + fi + fi + if [ -s "$t" ]; then + trace "++++ INSTALLED!" + fi +} + +function thumbnails() { + if ! test -f "$1"; then + return + fi + t="${1%.*}" # target file name + if test -n "$TARGET_PATH"; then + test -d "$TARGET_PATH" || mkdir -p "$TARGET_PATH"; + t="${TARGET_PATH}/${t##*/}" + fi + for p in "25%" "50%" "75%"; do + t2="${t}-${p%\%}.jpg" + if test -s "$t2"; then + continue; + fi + trace "++++ Thumbnail: ${t2}" + if ! ( ffmpegthumbnailer -i"$1" -o"${t2}" -s400 -t"${p}" > /dev/null 2> /dev/null && [ -s "$t2" ] ); then + rm "$t2" + fi + done +} + +#### MAIN ############################################################# +while (( "$#" )); do + arg=$1 + shift + case "$arg" in + (-h|--help) + cat<&2 + exit 1 + fi + cp $(getimage "$arg") "$1" + exit 0 + ;; + esac +done + +trace "******** $0 ********" +# scan all the movie files and also the directories +# assuming the file name contains the movie title in some predefined way +# find all files and subdirectories take newline as separator +SLEEP=10 +for f in $(find $SRC_PATH/ \( -name '*.jpg' -prune \) -o -type f -print); do + getimage "$f" > /dev/null + thumbnails "$f" +done diff --git a/src/towebm.sh b/src/towebm.sh new file mode 100755 index 0000000..2626cea --- /dev/null +++ b/src/towebm.sh @@ -0,0 +1,18 @@ +#! /bin/bash + +SRC="/var/data/spielfilme" +DST="/var/tmp/spielfilme/webm" + +for f in $(find "$SRC" \( -name '*.jpg' -prune \) -o -type f -print); do + t="${f/$SRC/$DST}" + t="${t%.*}.webm" + if test -s "${t}"; then + continue; + fi + test -d "${t%/*}" || mkdir -p "${t%/*}" + #ffmpeg -i "$f" -b 1500k -vcodec libvpx -acodec libvorbis -ab 160000 -f webm -g 30 "$t" + avconv -i "$f" "$t" + if ( ! test -s "${t}" ) && ( test -e "$t" ); then + rm "$t" + fi +done diff --git a/src/unknown-movie-folder.jpg b/src/unknown-movie-folder.jpg new file mode 100644 index 0000000..d88c8b9 Binary files /dev/null and b/src/unknown-movie-folder.jpg differ