-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: enhance video management and danmaku features
- Add danmaku download and preview - Add settings page for favorites/name/size filters - Support multi-part video download - Refactor video management logic
- Loading branch information
1 parent
c94f434
commit b5ed867
Showing
29 changed files
with
1,946 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Services\BilibiliService; | ||
use App\Services\DownloadFilterService; | ||
use App\Services\VideoManagerService; | ||
use Illuminate\Console\Command; | ||
use Log; | ||
|
||
class DownloadDanmaku extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:download-danmaku'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = '下载弹幕'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(VideoManagerService $videoManagerService, DownloadFilterService $downloadFilterService) | ||
{ | ||
$favList = $videoManagerService->getFavList(); | ||
foreach ($favList as $fav) { | ||
if($downloadFilterService->shouldExcludeByFav($fav['id'])){ | ||
Log::info('Exclude fav, download danmaku skip', ['id' => $fav['id'], 'title' => $fav['title']]); | ||
continue; | ||
} | ||
|
||
|
||
$videoList = $videoManagerService->getVideoListByFav($fav['id']); | ||
foreach ($videoList as $video) { | ||
if($videoManagerService->videoIsInvalid($video) || $video['invalid']){ | ||
Log::info('Video is invalid, download danmaku skip', ['id' => $video['id'], 'title' => $video['title']]); | ||
continue; | ||
} | ||
|
||
//检查名称是否符合 | ||
if($downloadFilterService->shouldExcludeByName($video['title'])){ | ||
Log::info('Video name not match, download danmaku skip', ['id' => $video['id'], 'title' => $video['title']]); | ||
continue; | ||
} | ||
|
||
|
||
// 检查上次更新时间是否太短 | ||
$lastDownloadTime = $videoManagerService->danmakuDownloadedTime($video['id']); | ||
if($lastDownloadTime && time() - $lastDownloadTime < 3600 * 24 * 7){ | ||
Log::info('Danmaku already downloaded, download danmaku skip', ['id' => $video['id'], 'title' => $video['title']]); | ||
continue; | ||
} | ||
|
||
$videoManagerService->dispatchDownloadDanmakuJob($video['id']); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Services\SettingsService; | ||
use Illuminate\Http\Request; | ||
|
||
class SettingsController extends Controller | ||
{ | ||
|
||
public function __construct(public SettingsService $settings) | ||
{ | ||
|
||
} | ||
|
||
public function getSettings() | ||
{ | ||
$presets = [ | ||
'danmakuCache' => 'on', | ||
'favExclude' => [ | ||
'enabled' => false, | ||
'selected' => [], | ||
], | ||
'MultiPartitionCache' => 'off', | ||
'nameExclude' => [ | ||
'contains' => '', | ||
'regex' => '', | ||
'type' => 'off', | ||
], | ||
'sizeExclude' => [ | ||
'customSize' => 0, | ||
'type' => 'off', | ||
], | ||
]; | ||
|
||
foreach ($presets as $key => $value) { | ||
$got = $this->settings->get($key); | ||
if ($got) { | ||
$presets[$key] = $got; | ||
} | ||
} | ||
|
||
return response()->json($presets); | ||
} | ||
|
||
public function saveSettings(Request $request) | ||
{ | ||
$data = $request->validate([ | ||
'MultiPartitionCache' => 'required|string|in:on,off', | ||
'danmakuCache' => 'required|string|in:on,off', | ||
|
||
'nameExclude' => 'required|array', | ||
'nameExclude.contains' => 'required_if:nameExclude.type,contains|string', | ||
'nameExclude.regex' => 'required_if:nameExclude.type,regex|string', | ||
'nameExclude.type' => 'required|string|in:off,contains,regex', | ||
|
||
'sizeExclude' => 'required|array', | ||
'sizeExclude.customSize' => 'required_if:sizeExclude.type,custom|integer', | ||
'sizeExclude.type' => 'required|string|in:off,1GB,2GB,custom', | ||
|
||
'favExclude' => 'required|array', | ||
'favExclude.enabled' => 'required|boolean', | ||
'favExclude.selected' => 'required_if:favExclude.enabled,true|array', | ||
]); | ||
|
||
foreach ($data as $key => $value) { | ||
$this->settings->put($key, $value); | ||
} | ||
|
||
return response()->json(['message' => 'Settings saved successfully']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class ForceJsonResponse | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next | ||
*/ | ||
public function handle(Request $request, Closure $next): Response | ||
{ | ||
$request->headers->set('Accept', 'application/json'); | ||
$request->headers->set('Content-Type', 'application/json'); | ||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Services\VideoManagerService; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Foundation\Queue\Queueable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class DownloadDanmakuJob implements ShouldQueue | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct(public int $avId) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
$videoManagerService = app(VideoManagerService::class); | ||
$videoManagerService->downloadDanmaku($this->avId); | ||
} | ||
} |
Oops, something went wrong.