Skip to content

Commit

Permalink
Add video duration capture
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Morris committed Aug 27, 2024
1 parent 6fa99b2 commit f7b1b02
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions aggro-db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ CREATE TABLE `aggro_videos` (
`video_width` int(6) NOT NULL DEFAULT '0',
`video_height` int(6) NOT NULL DEFAULT '0',
`video_aspect_ratio` float NOT NULL DEFAULT '0',
`video_duration` int(10) NOT NULL DEFAULT '0',
`video_type` varchar(255) DEFAULT NULL,
`video_source_id` varchar(255) DEFAULT NULL,
`video_source_username` varchar(255) DEFAULT NULL,
Expand Down
7 changes: 7 additions & 0 deletions app/Helpers/youtube_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ function youtube_parse_meta(object $item)
}
$video['video_aspect_ratio'] = round($video['video_width'] / $video['video_height'], 3);

$videoPage = 'https://www.youtube.com/watch?v=' . $video['video_id'];
$resultPage = fetch_url($videoPage, 'text', 0);
if ($resultPage !== false && is_string($resultPage)) {
if (preg_match('/"lengthSeconds":"(\d+)"/', $resultPage, $matches)) {
$video['video_duration'] = $matches[1];
}
}
return $video;
}
}
2 changes: 1 addition & 1 deletion app/Models/AggroModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function addVideo(array $video)
$utilityModel = new UtilityModels();
helper('aggro');

$sql = "INSERT INTO aggro_videos (video_id, aggro_date_added, aggro_date_updated, video_date_uploaded, flag_archive, flag_bad, video_plays, video_title, video_thumbnail_url, video_width, video_height, video_aspect_ratio, video_source_id, video_source_username, video_source_url, video_type) VALUES ('" . $video['video_id'] . "', '" . $video['aggro_date_added'] . "', '" . $video['aggro_date_updated'] . "', '" . $video['video_date_uploaded'] . "', " . $video['flag_archive'] . ', 0, ' . $video['video_plays'] . ", '" . $video['video_title'] . "', '" . $video['video_thumbnail_url'] . "', " . $video['video_width'] . ', ' . $video['video_height'] . ', ' . $video['video_aspect_ratio'] . ", '" . $video['video_source_id'] . "', '" . $video['video_source_username'] . "', '" . $video['video_source_url'] . "', '" . $video['video_type'] . "')";
$sql = "INSERT INTO aggro_videos (video_id, aggro_date_added, aggro_date_updated, video_date_uploaded, flag_archive, flag_bad, video_plays, video_title, video_thumbnail_url, video_width, video_height, video_aspect_ratio, video_duration, video_source_id, video_source_username, video_source_url, video_type) VALUES ('" . $video['video_id'] . "', '" . $video['aggro_date_added'] . "', '" . $video['aggro_date_updated'] . "', '" . $video['video_date_uploaded'] . "', " . $video['flag_archive'] . ', 0, ' . $video['video_plays'] . ", '" . $video['video_title'] . "', '" . $video['video_thumbnail_url'] . "', " . $video['video_width'] . ', ' . $video['video_height'] . ', ' . $video['video_aspect_ratio'] . ", ". $video['video_duration'] ." , '" . $video['video_source_id'] . "', '" . $video['video_source_username'] . "', '" . $video['video_source_url'] . "', '" . $video['video_type'] . "')";

$this->db->query($sql);

Expand Down

0 comments on commit f7b1b02

Please sign in to comment.