fix thumbnail generation

fix hardcoded paths
a lot of minor fixes
This commit is contained in:
2021-01-21 19:55:42 +00:00
parent aacf387d63
commit 7a62b01027
18 changed files with 62 additions and 121 deletions

View File

@@ -22,25 +22,26 @@ class VideoController extends Controller
* @return Response
*/
public function index(Request $request) {
if($request->has('q')){
$needle = trim($request->input('q'));
return view('index', [
'videos' => Video::filtered()->withAnyTagsFuzzy($needle)
->orderBy('id', 'asc')
->paginate(20)->appends(['q' => $needle]),
$videos = Video::filtered();
if($request->has('q')) {
$needle = trim($request->input('q'));
$videos = $videos->withAnyTagsFuzzy($needle);
return view('index', [
'number_of_results' => $videos->get()->count(),
'videos' => $videos->orderBy('id', 'ASC')->paginate(20)->appends(['q' => $needle]),
'categories' => Category::all(),
'q' => $needle,
'q' => $needle
]);
}
return view('index', [
'videos' => Video::filtered()->orderBy('id', 'ASC')->paginate(20),
'categories' => Category::all(),
return view('index', [
'number_of_results' => $videos->get()->count(),
'videos' => $videos->orderBy('id', 'ASC')->paginate(20),
'categories' => Category::all()
]);
}
public function main(Request $request) {
public function main(Request $request) {
if($request->has('q')){
$needle = trim($request->input('q'));
return view('main', [
@@ -181,9 +182,11 @@ class VideoController extends Controller
#->back();
#->with('error', 'No video with that ID found');
$sfw = $video->tags->contains(function($key, $tag) {
return $tag->normalized === 'sfw';
});
$sfw = $video->isSfw();
if(!$sfw && !file_exists(public_path() . "/thumbs/blurred/" . substr($video->file, 0, -5) . "_blurred.png"))
$video->blurryThumb();
return view('video', [
'video' => $video,

View File

@@ -38,9 +38,9 @@ Route::group(['prefix' => 'api'], function() {
Route::group(['prefix' => 'comments'], function() {
Route::get('/', 'CommentController@index')->middleware('auth');
Route::get('/{id}', 'CommentController@show')->where('id', '[0-9]+')->middleware('auth');
Route::post('{id}/edit', 'CommentController@update')->where('id', '[0-9]+')->middleware('auth');
Route::post('{id}/delete', 'CommentController@destroy')->where('id', '[0-9]+')->middleware('auth');
Route::post('{id}/restore', 'CommentController@restore')->where('id', '[0-9]+')->middleware('auth');
Route::post('{id}/edit', 'CommentController@update')->where('id', '[0-9]+')->middleware('auth')->middleware('theme');
Route::post('{id}/delete', 'CommentController@destroy')->where('id', '[0-9]+')->middleware('auth')->middleware('theme');
Route::post('{id}/restore', 'CommentController@restore')->where('id', '[0-9]+')->middleware('auth')->middleware('theme');
});
// /api/user
@@ -76,10 +76,10 @@ Route::group(['prefix' => 'api'], function() {
}
return $res;
})->where('id', '[0-9]+')->middleware('auth');
Route::post('{id}/delete', 'VideoController@destroy')->where('id', '[0-9]+');
Route::post('{id}/delete', 'VideoController@destroy')->where('id', '[0-9]+')->middleware('theme');
Route::post('{id}/tag', 'VideoController@tag')->where('id', '[0-9]+');
Route::post('{id}/untag', 'VideoController@untag')->where('id', '[0-9]+');
#Route::post('upload', 'VideoController@store')->middleware('auth');
Route::post('upload', 'VideoController@store')->middleware('auth');
});
#Route::post('upload', 'VideoController@store');
@@ -109,7 +109,7 @@ Route::group(["middleware" => "theme"], function() {
Route::get('index', 'VideoController@index')->middleware('auth');
Route::get('main', 'VideoController@main')->middleware('auth');
Route::post('index/{id}', 'VideoController@update')->middleware('auth');
#Route::get('upload', 'VideoController@create')->middleware('auth');
Route::get('upload', 'VideoController@create')->middleware('auth');
Route::get('categories', 'CategoryController@index')->middleware('auth');
Route::get('webm', function() { return view('webm'); })->middleware('auth');
Route::get('about', function() { return view('about'); })->middleware('auth');

View File

@@ -163,8 +163,8 @@ class Video extends Model
public function tesThumb() {
set_time_limit(9899999999999999);
$dat = $this->file;
#$in = public_path() . "/b"; // webm-input
$in = "/home/w0bm/w0bm/public/b";
$in = public_path() . "/b"; // webm-input
#$in = "/home/w0bm/w0bm/public/b";
$out = public_path() . "/thumbs/beta"; //thumb-output
$tmpdir = str_replace("public", "app/Http/Controllers/tmp", public_path());
@@ -192,7 +192,7 @@ public function blurryThumb() {
set_time_limit(9899999999999999);
$dat = $this->file;
#$in = public_path() . "/b"; // webm-input
$in = "/home/w0bm/w0bm/public/b";
$in = public_path() . "/b";
$out = public_path() . "/thumbs/blurred"; //thumb-output
$tmpdir = str_replace("public", "app/Http/Controllers/tmp", public_path());
@@ -220,28 +220,6 @@ public function blurryThumb() {
}
}
public function createThumbnailStatic() {
$dat = $this->file;
$in = public_path() . "/b"; // webm-input
$out = public_path() . "/thumbs/testing"; //thumb-output
$tmpdir = str_replace("public", "app/Http/Controllers/tmp", public_path());
$name = explode(".", $dat);
array_pop($name);
$name = join(".", $name);
if(!file_exists("{$out}/{$name}.png")) {
$length = round(shell_exec("ffprobe -i {$in}/{$dat} -show_format -v quiet | sed -n 's/duration=//p'"));
for ($i = 1; $i < 10; $i++) {
$act = ($i * 10) * ($length / 100);
$ffmpeg = shell_exec("ffmpeg -ss {$act} -i {$in}/{$dat} -vf \"'select=eq(n\,0)'\" -vf scale=128:128 {$tmpdir}/{$name}_{$i}.png 2>&1");
}
$tmp = shell_exec("convert -delay 27 -loop 0 {$tmpdir}/{$name}_*.png {$out}/{$name}.png 2>&1");
if(@filesize("{$out}/{$name}.png") < 2000)
@unlink("{$out}/{$name}.png");
array_map('unlink', glob("{$tmpdir}/{$name}*.png"));
}
}
public static function getRandom($related = null) {
if ($related) {
$id = $related->videos()->filtered()->countScoped()->count() - 1;
@@ -260,8 +238,8 @@ public function blurryThumb() {
}
public function isSfw() {
return $this->tags->contains(function ($key, $tag) {
$tag->normalized === 'sfw';
return !$this->tags->contains(function ($key, $tag) {
return $tag->normalized === 'nsfw';
});
}