Skip to content

Commit

Permalink
feat: direct YouTube thumbnail proxying (merge pull request #124 from…
Browse files Browse the repository at this point in the history
… dehlirious/img_proxy)

Direct YouTube thumbnail image proxying
  • Loading branch information
Ahwxorg authored Feb 25, 2024
2 parents 5acc51d + 592e8e8 commit 4ed93f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions engines/invidious/video.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public function get_request_url() {

public function parse_results($response) {
$results = array();
$json_response = json_decode($response, true) ?? [];
$json_response = json_decode($response, true);

foreach ($json_response as $response) {
foreach ($json_response ?: [] as $response) {
if ($response["type"] == "video") {
$title = $response["title"];
$url = "https://youtube.com/watch?v=" . $response["videoId"];
Expand Down Expand Up @@ -41,15 +41,16 @@ public function parse_results($response) {
public static function print_results($results, $opts) {
echo "<div class=\"text-result-container\">";

foreach ($results as $result) {
foreach ($results as $key => $result) {
if ($key == "results_source") continue;
$title = $result["title"] ?? '';
$url = $result["url"] ?? '';
$url = check_for_privacy_frontend($url, $opts);
$base_url = get_base_url($url);
$uploader = $result["uploader"] ?? '';
$views = $result["views"] ?? '';
$date = $result["date"] ?? '';
$thumbnail = $result["thumbnail"] ?? '';
$thumbnail = preg_replace('/(?:https?:\/\/)?(?:www\.)?youtube\.com\/watch\?v=([^\s]+)/', 'https://i.ytimg.com/vi/$1/maxresdefault.jpg', $url) ?? '';

echo "<div class=\"text-result-wrapper\">";
echo "<a href=\"$url\">";
Expand Down
2 changes: 1 addition & 1 deletion image_proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$url = $_REQUEST["url"];
$requested_root_domain = get_root_domain($url);

$allowed_domains = array("s2.qwant.com", "s1.qwant.com", "upload.wikimedia.org", get_root_domain($config->invidious_instance_for_video_results));
$allowed_domains = array("i.ytimg.com", "s2.qwant.com", "s1.qwant.com", "upload.wikimedia.org", get_root_domain($config->invidious_instance_for_video_results));

if (in_array($requested_root_domain, $allowed_domains))
{
Expand Down

0 comments on commit 4ed93f6

Please sign in to comment.