mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
A tool to fix resolutions on m3u8 file
This commit is contained in:
parent
2fd0a2fcf6
commit
ed50ec2440
1 changed files with 72 additions and 0 deletions
72
install/fixM3U8Resolution.php
Normal file
72
install/fixM3U8Resolution.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
//streamer config
|
||||
require_once __DIR__ . '/../videos/configuration.php';
|
||||
ob_end_flush();
|
||||
if (!isCommandLineInterface()) {
|
||||
return die('Command Line only');
|
||||
}
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
$global['rowCount'] = 99999;
|
||||
$total = Video::getTotalVideos("", false, true, true, false, false);
|
||||
$videos = Video::getAllVideosLight("", false, true, false);
|
||||
$count = 0;
|
||||
|
||||
$cdnObj = AVideoPlugin::getDataObjectIfEnabled('CDN');
|
||||
|
||||
|
||||
$resolutions = [
|
||||
240 => 426,
|
||||
360 => 640,
|
||||
480 => 854,
|
||||
540 => 960,
|
||||
720 => 1280,
|
||||
1080 => 1920,
|
||||
1440 => 2560,
|
||||
2160 => 3840
|
||||
];
|
||||
|
||||
foreach ($videos as $video) {
|
||||
$count++;
|
||||
//echo "FIX: {$count}/{$total} ({$video['type']}) [{$video['id']}] {$video['title']}".PHP_EOL;
|
||||
if ($video['type'] !== 'video') {
|
||||
continue;
|
||||
}
|
||||
$sources = getVideosURLOnly($video['filename'], false);
|
||||
if (empty($sources['m3u8'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content = file_get_contents($sources['m3u8']['url']);
|
||||
if (preg_match_all('/RESOLUTION=-2x([0-9]+)/i', $content, $matches)) {
|
||||
//var_dump($content);
|
||||
foreach ($matches[1] as $key => $value) {
|
||||
$height = intval($value);
|
||||
if (!empty($resolutions[$height])) {
|
||||
$content = str_replace($matches[0][$key], "RESOLUTION={$resolutions[$height]}x{$height}", $content);
|
||||
}
|
||||
}
|
||||
file_put_contents($sources['m3u8']['path'], $content);
|
||||
//var_dump($sources['m3u8'], $content);
|
||||
echo "FIX : {$count}/{$total} ({$sources['m3u8']['url']}) [{$video['id']}] {$video['title']}" . PHP_EOL;
|
||||
|
||||
if (!empty($cdnObj) && !empty($cdnObj->enable_storagej)) {
|
||||
try {
|
||||
CDNStorage::putUsingAPI([$resp['path']]);
|
||||
} catch (\Throwable $th) {
|
||||
_error_log("HLSAudioManager CDNStorage::put API error use FTP " . $th->getMessage());
|
||||
CDNStorage::putUsingFTP([$resp['path']], 1);
|
||||
}
|
||||
CDNStorage::createDummyFiles($video['id']);
|
||||
}
|
||||
}else{
|
||||
echo "SKIP: {$count}/{$total} ({$sources['m3u8']['url']}) [{$video['id']}] {$video['title']}" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($cdnObj) && !empty($cdnObj->enable_storagej)) {
|
||||
CDN::purgeCache();
|
||||
}
|
||||
|
||||
die();
|
Loading…
Add table
Add a link
Reference in a new issue