fix youtube dates. i deserve a fucking cup of tea

This commit is contained in:
2026-09-06 15:10:34 -04:00
parent 462c5e1729
commit 1863dfa57b
+35 -1
View File
@@ -526,6 +526,8 @@ class yt{
} }
$json = json_decode($json[1], true); $json = json_decode($json[1], true);
/*$first_page = true;
$json = json_decode(file_get_contents("scraper/yt.html"), true);*/
} }
$items = [ $items = [
@@ -692,7 +694,7 @@ class yt{
$video["publishedTimeText"] $video["publishedTimeText"]
["simpleText"] ["simpleText"]
) ? ) ?
strtotime( $this->parse_date(
trim( trim(
str_replace( str_replace(
"Streamed", "", "Streamed", "",
@@ -1352,6 +1354,38 @@ class yt{
return str_replace(["\r", "\n"], " ", trim($title, " \n\r\t\v\x00\0\x0B\xc2\xa0")); return str_replace(["\r", "\n"], " ", trim($title, " \n\r\t\v\x00\0\x0B\xc2\xa0"));
} }
private function parse_date($date){
if(
preg_match(
'/^([0-9]+)(s|m|h|d|w|mo|y) ago$/',
$date,
$control_chars
)
){
switch($control_chars[2]){
case "s": $selection = "seconds"; break;
case "m": $selection = "minutes"; break;
case "h": $selection = "hours"; break;
case "d": $selection = "days"; break;
case "w": $selection = "weeks"; break;
case "mo": $selection = "months"; break;
case "y": $selection = "years"; break;
default: return null;
}
$date = "{$control_chars[1]} {$selection} ago";
}
$out = strtotime($date);
if($out === false){ $out = null; }
return $out;
}
private function assemble_runs($runs){ private function assemble_runs($runs){
if(!isset($runs["runs"])){ return ""; } if(!isset($runs["runs"])){ return ""; }