- Fixed the Imgur embed path.

Imgur now uses a local wrapper page, 
[provider_embed.php](/Users/tyemeclifford/Documents/GH/mediaplayer/provider_embed.php), 
that renders Imgur’s official blockquote + 
https://s.imgur.com/min/embed.js snippet instead of trying to iframe 
Imgur directly. That should avoid the “refuses to connect” issue for 
albums, galleries, images, GIFs, GIFV, and videos.
Also updated:
[includes/db.php](/Users/tyemeclifford/Documents/GH/mediaplayer/includes/db.php): 
Imgur embed URLs now point to the wrapper, and Imgur view-count scraping 
has dedicated fallback patterns.
[admin/index.php](/Users/tyemeclifford/Documents/GH/mediaplayer/admin/index.php): 
Upkeeping → Correct Views now explicitly counts Imgur-backed items in 
the candidate summary.
[README.md](/Users/tyemeclifford/Documents/GH/mediaplayer/README.md): 
documented the Imgur wrapper behavior.
This commit is contained in:
Ty Clifford
2026-06-25 08:36:40 -04:00
parent 173fe3917e
commit 4425716d6f
4 changed files with 116 additions and 3 deletions
+43 -2
View File
@@ -543,8 +543,12 @@ function media_imgur_page_url(string $url): string {
}
function media_imgur_embed_url(string $url): string {
$page = media_imgur_page_url($url);
return $page !== '' ? rtrim($page, '/') . '/embed' : '';
$path = media_imgur_path_from_url($url);
if ($path === '') return '';
return media_append_query(public_url_path('/provider_embed.php'), [
'provider' => 'imgur',
'id' => $path,
]);
}
function media_normalize_datetime(string $value): string {
@@ -677,6 +681,26 @@ function media_view_count_from_html(string $html): int {
return 0;
}
function media_imgur_view_count_from_html(string $html): int {
$count = media_view_count_from_html($html);
if ($count > 0) return $count;
$html = html_entity_decode($html, ENT_QUOTES | ENT_HTML5, 'UTF-8');
$patterns = [
'/\bviews?\b[^0-9]{0,80}([0-9][0-9,.\s]*\s*[KMBkmb]?)/i',
'/([0-9][0-9,.\s]*\s*[KMBkmb]?)\s+\bviews?\b/i',
'/"views_count"\s*:\s*"?(\d+)"?/i',
'/"viewsCount"\s*:\s*"?(\d+)"?/i',
];
foreach ($patterns as $pattern) {
if (!preg_match($pattern, $html, $match)) continue;
$count = media_count_from_text($match[1]);
if ($count > 0) return $count;
}
return 0;
}
function media_youtube_view_count_from_html(string $html): int {
return media_view_count_from_html($html);
}
@@ -708,6 +732,10 @@ function media_external_view_count_from_url(string $url): int {
$fetch = media_http_get($url, 15, 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
if ($fetch['body'] === '' || $fetch['error'] !== '') return 0;
if (media_host_matches($host, 'imgur.com') || media_host_matches($host, 'i.imgur.com')) {
return media_imgur_view_count_from_html($fetch['body']);
}
return media_view_count_from_html($fetch['body']);
}
@@ -784,6 +812,19 @@ function media_external_view_count_candidate_count(): int {
")->fetchColumn();
}
function media_imgur_view_count_candidate_count(): int {
return (int)get_db()->query("
SELECT COUNT(DISTINCT v.id)
FROM videos v
INNER JOIN video_sources vs ON vs.video_id = v.id
WHERE vs.source_type='remote'
AND (
vs.source_url LIKE '%imgur.com%'
OR vs.source_url LIKE '%i.imgur.com%'
)
")->fetchColumn();
}
function media_restore_external_view_counts(int $limit = 25): array {
$result = [
'checked' => 0,