|
|
@ -14,6 +14,7 @@ use Illuminate\Support\Arr; |
|
|
use Illuminate\Support\Facades\App; |
|
|
use Illuminate\Support\Facades\App; |
|
|
use Illuminate\Support\Facades\DB; |
|
|
use Illuminate\Support\Facades\DB; |
|
|
use Illuminate\Support\Facades\Log; |
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
|
|
use Illuminate\Support\Facades\Redis; |
|
|
|
|
|
|
|
|
class BilibiliServiceV2 |
|
|
class BilibiliServiceV2 |
|
|
{ |
|
|
{ |
|
|
@ -33,7 +34,6 @@ class BilibiliServiceV2 |
|
|
private $remoteDir = "/Volumes/Crucial X6/Video/"; |
|
|
private $remoteDir = "/Volumes/Crucial X6/Video/"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected $repository; |
|
|
protected $repository; |
|
|
|
|
|
|
|
|
public function __construct(BilibiliVideoRepository $repository) |
|
|
public function __construct(BilibiliVideoRepository $repository) |
|
|
@ -255,12 +255,10 @@ class BilibiliServiceV2 |
|
|
{ |
|
|
{ |
|
|
$env = App::environment(); |
|
|
$env = App::environment(); |
|
|
$list = BilibiliUpVideos::orderBy("created_at", "desc")->get(); |
|
|
$list = BilibiliUpVideos::orderBy("created_at", "desc")->get(); |
|
|
$list = array_slice($list->all(), 40, 1); |
|
|
|
|
|
// dump($list);exit;
|
|
|
|
|
|
foreach ($list as $item) { |
|
|
foreach ($list as $item) { |
|
|
dump("当前 up名称是: " . $item["up_name"] . "\n"); |
|
|
dump("当前 up名称是: " . $item["up_name"] . "\n"); |
|
|
if ($item["is_downloaded"] == 1) { |
|
|
if ($item["is_downloaded"] == 1) { |
|
|
// continue;
|
|
|
|
|
|
|
|
|
continue; |
|
|
} |
|
|
} |
|
|
if (!$this->checkDiskSpace()) { |
|
|
if (!$this->checkDiskSpace()) { |
|
|
Log::info('磁盘空间不足'); |
|
|
Log::info('磁盘空间不足'); |
|
|
@ -301,28 +299,28 @@ class BilibiliServiceV2 |
|
|
$result = $this->partDownloadBSitePlaylist($videoPartsMap, $this->baseDir . "bilibili/", $item['up_name']); |
|
|
$result = $this->partDownloadBSitePlaylist($videoPartsMap, $this->baseDir . "bilibili/", $item['up_name']); |
|
|
} |
|
|
} |
|
|
if ($result) { |
|
|
if ($result) { |
|
|
if (!$this->repository->softLockUpdate( |
|
|
|
|
|
["id" => $vItem["id"]], |
|
|
|
|
|
$vItem["version"] + 1, |
|
|
|
|
|
["download_status" => 0, |
|
|
|
|
|
"is_downloaded" => 1 |
|
|
|
|
|
])) { |
|
|
|
|
|
Log::warning("soft Lock failed id : " . $vItem["id"]); |
|
|
|
|
|
|
|
|
if (!$this->repository->softLockUpdate( |
|
|
|
|
|
["id" => $vItem["id"]], |
|
|
|
|
|
$vItem["version"] + 1, |
|
|
|
|
|
["download_status" => 0, |
|
|
|
|
|
"is_downloaded" => 1 |
|
|
|
|
|
])) { |
|
|
|
|
|
Log::warning("soft Lock failed id : " . $vItem["id"]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
$result = $this->partDownloadBSitePlaylist($videoPartsMap, $this->remoteDir . "bilibili/", $item["up_name"]); |
|
|
$result = $this->partDownloadBSitePlaylist($videoPartsMap, $this->remoteDir . "bilibili/", $item["up_name"]); |
|
|
if ($result) { |
|
|
if ($result) { |
|
|
if (!$this->repository->softLockUpdate( |
|
|
|
|
|
["id" => $vItem["id"]], |
|
|
|
|
|
$vItem["version"] + 1, |
|
|
|
|
|
["download_status" => 0, |
|
|
|
|
|
"is_downloaded" => 1 |
|
|
|
|
|
])) { |
|
|
|
|
|
Log::warning("soft Lock failed id : " . $vItem["id"]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (!$this->repository->softLockUpdate( |
|
|
|
|
|
["id" => $vItem["id"]], |
|
|
|
|
|
$vItem["version"] + 1, |
|
|
|
|
|
["download_status" => 0, |
|
|
|
|
|
"is_downloaded" => 1 |
|
|
|
|
|
])) { |
|
|
|
|
|
Log::warning("soft Lock failed id : " . $vItem["id"]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
@ -949,6 +947,7 @@ class BilibiliServiceV2 |
|
|
public function partDownloadBSitePlaylist($aidMap, $dir = "/Volumes/intel660p/video/mv/mp4", $subDir) |
|
|
public function partDownloadBSitePlaylist($aidMap, $dir = "/Volumes/intel660p/video/mv/mp4", $subDir) |
|
|
{ |
|
|
{ |
|
|
$env = App::environment(); |
|
|
$env = App::environment(); |
|
|
|
|
|
$cookie = Redis::connection()->get("bilibili_cookie"); |
|
|
$dirExists = is_dir($dir); |
|
|
$dirExists = is_dir($dir); |
|
|
dump($dirExists); |
|
|
dump($dirExists); |
|
|
echo "dir is $dir, and $dirExists"; |
|
|
echo "dir is $dir, and $dirExists"; |
|
|
@ -974,11 +973,45 @@ do |
|
|
annie -f 64 $url$i |
|
|
annie -f 64 $url$i |
|
|
done && echo "ok"'); |
|
|
done && echo "ok"'); |
|
|
} else { |
|
|
} else { |
|
|
$downloadResult = shell_exec('cd "' . $innerDir . '" && url="https://www.bilibili.com/video/av' . $aid . '?p="
|
|
|
|
|
|
for i in $(seq 1 ' . $parts . ') |
|
|
|
|
|
do |
|
|
|
|
|
lux -c "SESSDATA=38d864a2%2C1667569057%2Cc416c*51;" $url$i |
|
|
|
|
|
done && echo "ok"'); |
|
|
|
|
|
|
|
|
$formatInfoShell = "lux -p -j -i -c \"{$cookie}\" av{$aid}"; |
|
|
|
|
|
$formatInfoShellResult = shell_exec($formatInfoShell); |
|
|
|
|
|
$formatInfoList = json_decode($formatInfoShellResult, true); |
|
|
|
|
|
$formatArray = []; |
|
|
|
|
|
foreach ($formatInfoList as $formatInfo) { |
|
|
|
|
|
$keys = array_keys($formatInfo["streams"]); |
|
|
|
|
|
$largeHev1FormatCode = -1; |
|
|
|
|
|
$largeFormatCode = -1; |
|
|
|
|
|
$largeFormatStr = ""; |
|
|
|
|
|
foreach ($keys as $key) { |
|
|
|
|
|
$formats = explode("-", $key); |
|
|
|
|
|
// 127-12, 后面的 12 代表 hev1 编码的
|
|
|
|
|
|
// 这边是想要获取到 hev1 编码的最高清晰度格式
|
|
|
|
|
|
if ($formats[1] == "12" && (int)$formats[0] > $largeHev1FormatCode) { |
|
|
|
|
|
$largeHev1FormatCode = (int)$formats[0]; |
|
|
|
|
|
} |
|
|
|
|
|
if ((int)$formats[0] > $largeFormatCode) { |
|
|
|
|
|
$largeFormatCode = (int)$formats[0]; |
|
|
|
|
|
$largeFormatStr = $key; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if ($largeHev1FormatCode == -1) { |
|
|
|
|
|
$formatArray[] = $largeFormatStr; |
|
|
|
|
|
} else { |
|
|
|
|
|
$formatArray[] = $largeHev1FormatCode . "-12"; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
$downloadShell = "cd $innerDir"; |
|
|
|
|
|
for ($i = 1; $i <= count($formatArray); $i++) { |
|
|
|
|
|
$downloadShell .= " && lux -f " . $formatArray[$i - 1] . " -c \"" . $cookie . "\" https://www.bilibili.com/video/av" . $aid . "?p=" . $i; |
|
|
|
|
|
} |
|
|
|
|
|
$downloadShell .= " && echo \"ok\""; |
|
|
|
|
|
$downloadResult = shell_exec($downloadShell); |
|
|
|
|
|
|
|
|
|
|
|
// $downloadResult = shell_exec('cd "' . $innerDir . '" && url="https://www.bilibili.com/video/av' . $aid . '?p="
|
|
|
|
|
|
//for i in $(seq 1 ' . $parts . ')
|
|
|
|
|
|
//do
|
|
|
|
|
|
//lux -c "'. $cookie.'" $url$i
|
|
|
|
|
|
//done && echo "ok"');
|
|
|
//
|
|
|
//
|
|
|
} |
|
|
} |
|
|
Log::info($downloadResult); |
|
|
Log::info($downloadResult); |
|
|
|