first release
This commit is contained in:
8
bootstrap.sh
Executable file
8
bootstrap.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#! /bin/bash
|
||||
|
||||
## @id $Id$
|
||||
|
||||
## 1 2 3 4 5 6 7 8
|
||||
## 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
aclocal && automake && autoconf
|
9
configure.ac
Normal file
9
configure.ac
Normal file
@@ -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
|
8
makefile.am
Normal file
8
makefile.am
Normal file
@@ -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
|
BIN
src/default.jpg
Normal file
BIN
src/default.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
215
src/index.php
Normal file
215
src/index.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
$DIR="/var/data/spielfilme";
|
||||
$POSTER="/var/tmp/spielfilme";
|
||||
$CONVERT=$POSTER;
|
||||
|
||||
function pageUrl() {
|
||||
$pageURL = 'http';
|
||||
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
|
||||
$pageURL .= "://";
|
||||
if ($_SERVER["SERVER_PORT"] != "80") {
|
||||
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
|
||||
} else {
|
||||
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
|
||||
}
|
||||
return $pageURL;
|
||||
}
|
||||
$URL=pageUrl();
|
||||
|
||||
function img($alt, $src, $class="image") {
|
||||
global $URL, $POSTER;
|
||||
if (is_file($POSTER.'/'.$src.'.jpg'))
|
||||
return '<img alt="'.htmlentities($alt).'" src="'.htmlentities($URL.'?img='.$src).'.jpg" class="'.$class.'"/>';
|
||||
}
|
||||
|
||||
if (isset($_GET["img"])) {
|
||||
if (ereg('[^-_.A-Za-z0-9]', $_GET["img"])) {
|
||||
?><html>
|
||||
<body>
|
||||
<p>Illegal Image name: "<code><?php echo htmlentities($_GET["img"]) ?></code>"</p>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
} elseif (is_file($POSTER.'/'.$_GET["img"])) {
|
||||
header('Content-Type: image/jpeg');
|
||||
readfile($POSTER.'/'.$_GET["img"]);
|
||||
exit;
|
||||
} else {
|
||||
?><html>
|
||||
<body>
|
||||
<p>Image not found: "<code><?php echo htmlentities($_GET["img"]) ?></code>"</p>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
}
|
||||
} elseif (isset($_GET["video"])) {
|
||||
if (ereg('[^-_.A-Za-z0-9]', $_GET["video"]) || isset($_GET["mime"]) && ereg('[^-_.A-Za-z0-9]', $_GET["mime"])) {
|
||||
?><html>
|
||||
<body>
|
||||
<p>Illegal Video name: "<code><?php echo htmlentities($_GET["video"]) ?></code>"</p>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
} elseif (is_file($DIR.'/'.$_GET["video"])) {
|
||||
$mime = mime_content_type($DIR.'/'.$_GET["video"]);
|
||||
if (isset($_GET["play"])) {
|
||||
/* if (isset($_GET["convert"])) {
|
||||
switch ($_GET["convert"]) {
|
||||
case "webm":
|
||||
header('Content-type: video/webm');
|
||||
exec('ffmpeg -i "'.$DIR.'/'.$_GET["video"].'" -b 1500k -vcodec libvpx -acodec libvorbis -ab 160000 -f webm -g 30 - 2>/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 {
|
||||
?><!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
|
||||
<p>
|
||||
<video controls>
|
||||
<source src="<?php echo $URL.'&play=1' ?>" type="<?php echo $mime ?>">
|
||||
<?php /* <source src="<?php echo $URL.'&play=1&convert=webm' ?>" type="video/webm">*/
|
||||
if ($d=opendir($CONVERT)) {
|
||||
while (false!==($f=readdir($d))) if ($f!='.' && $f!=".." && is_dir($CONVERT.'/'.$f)) {
|
||||
$p=$CONVERT.'/'.$f.'/'.preg_replace('/\.[^.]*$/', '.'.$f, $_GET['video']);
|
||||
if (is_file($p))
|
||||
echo '<source src="'.$URL.'&play=1&mime='.$f.'" type="video/'.$f.'">';
|
||||
}
|
||||
closedir($d);
|
||||
}
|
||||
/*<source src="<?php echo $URL.'&play=1&convert=mp4' ?>" type="video/mp4"> */ ?>
|
||||
Your browser does not support the video tag.
|
||||
</video><br/>
|
||||
[<a href="<?php echo $URL.'&play=1' ?>">Click to Download or copy link to VLC player</a>]
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
?><html>
|
||||
<body>
|
||||
<p>Video not found: "<code><?php echo htmlentities($_GET["video"]) ?></code>"</p>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
?><html>
|
||||
<head>
|
||||
<style>
|
||||
ul {list-style-type: none;}
|
||||
ul li {display: inline-block; text-weight: bold; border: .5ex groove green; padding: 0; margin: .5ex;}
|
||||
table {}
|
||||
td.poster {}
|
||||
img.poster {height: 210px;}
|
||||
img.preview {height: 70px;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Videofilme</h1>
|
||||
<ul>
|
||||
<?php
|
||||
if ($d=opendir($DIR)) {
|
||||
while (false!==($f=readdir($d))) if (is_file($DIR.'/'.$f)) {
|
||||
$b=ereg_replace('\.[^.]*', '', $f);
|
||||
$t=ereg_replace(' - ', '<br/>', ereg_replace('[0-9]*-[^ ]*$', '', ereg_replace('( - )?(part|[cC][dD]|[Tt][eE][iI][lL])[0-9]+', '', ereg_replace('_', ' ', htmlentities($b)))));
|
||||
if (preg_match('/.*(part|[cC][dD]|[Tt][eE][iI][lL])([0-9]+).*/', $b, $m))
|
||||
$t.='<br/>Teil '.$m[2];
|
||||
$t=ereg_replace('<br/>$', '', ereg_replace('(<br/>)+', '<br/>', $t));
|
||||
echo '<li><table><tr><th colspan="2" class="poster"><a href="'.htmlentities($URL.'?video='.urlencode($f).'&play=1').'">'.$t.'</a></td></tr><tr><td rowspan="3"><a href="'.htmlentities($URL.'?video='.urlencode($f)).'">'.img($b, $b, "poster").'</a></td><td>'.img("$b preview 25%", "$b-25", "preview").'</td></tr><tr><td>'.img("$b preview 50%", "$b-50", "preview").'</td></tr><tr><td>'.img("$b preview 75%", "$b-75", "preview").'</td></tr></table></li>'."\n";
|
||||
}
|
||||
closedir($d);
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
<?php } ?>
|
13
src/makefile.am
Normal file
13
src/makefile.am
Normal file
@@ -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
|
205
src/movieposter.sh
Executable file
205
src/movieposter.sh
Executable file
@@ -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<<EOF
|
||||
USAGE
|
||||
|
||||
1) copy image from a movie file:
|
||||
|
||||
$0 in-movie-path out-image-path
|
||||
|
||||
2) scan sourcedir and cache images for all files
|
||||
|
||||
$0
|
||||
|
||||
3) other options:
|
||||
|
||||
$0 OPTIONS
|
||||
|
||||
OPTIONS
|
||||
|
||||
-h, --help show this help
|
||||
|
||||
EOF
|
||||
exit $#
|
||||
;;
|
||||
(*)
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "**** ERROR! call: $0 --help" 1>&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
|
18
src/towebm.sh
Executable file
18
src/towebm.sh
Executable file
@@ -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
|
BIN
src/unknown-movie-folder.jpg
Normal file
BIN
src/unknown-movie-folder.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Reference in New Issue
Block a user