- Reversed Imgur support.
Removed the Imgur-specific provider handling from [includes/db.php](/Users/tyemeclifford/Documents/GH/mediaplayer/includes/db.php), removed the admin upkeep Imgur counter/copy from [admin/index.php](/Users/tyemeclifford/Documents/GH/mediaplayer/admin/index.php), updated the upload hint in [admin/add.php](/Users/tyemeclifford/Documents/GH/mediaplayer/admin/add.php), cleaned the README mentions, and deleted provider_embed.php.
This commit is contained in:
-105
@@ -512,45 +512,6 @@ function media_youtube_id_from_url(string $url): string {
|
||||
return media_clean_token($id);
|
||||
}
|
||||
|
||||
function media_imgur_path_from_url(string $url): string {
|
||||
$url = normalize_media_url($url);
|
||||
if ($url === '') return '';
|
||||
|
||||
$host = strtolower((string)(parse_url($url, PHP_URL_HOST) ?? ''));
|
||||
$segments = media_path_segments($url);
|
||||
if (!$segments) return '';
|
||||
|
||||
if (media_host_matches($host, 'i.imgur.com')) {
|
||||
$id = pathinfo($segments[0], PATHINFO_FILENAME);
|
||||
$id = media_clean_token($id);
|
||||
return $id !== '' ? $id : '';
|
||||
}
|
||||
|
||||
if (!media_host_matches($host, 'imgur.com')) return '';
|
||||
|
||||
if (in_array($segments[0], ['a', 'gallery'], true) && isset($segments[1])) {
|
||||
$id = media_clean_token($segments[1]);
|
||||
return $id !== '' ? $segments[0] . '/' . $id : '';
|
||||
}
|
||||
|
||||
$id = media_clean_token($segments[0]);
|
||||
return $id !== '' ? $id : '';
|
||||
}
|
||||
|
||||
function media_imgur_page_url(string $url): string {
|
||||
$path = media_imgur_path_from_url($url);
|
||||
return $path !== '' ? 'https://imgur.com/' . $path : '';
|
||||
}
|
||||
|
||||
function media_imgur_embed_url(string $url): string {
|
||||
$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 {
|
||||
$value = trim(html_entity_decode($value, ENT_QUOTES | ENT_HTML5, 'UTF-8'));
|
||||
if ($value === '') return '';
|
||||
@@ -681,26 +642,6 @@ 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);
|
||||
}
|
||||
@@ -724,18 +665,9 @@ function media_external_view_count_from_url(string $url): int {
|
||||
if (media_host_matches($host, 'youtube.com') || media_host_matches($host, 'youtu.be') || media_host_matches($host, 'youtube-nocookie.com')) {
|
||||
return media_youtube_view_count($url);
|
||||
}
|
||||
if (media_host_matches($host, 'imgur.com') || media_host_matches($host, 'i.imgur.com')) {
|
||||
$imgur_page = media_imgur_page_url($url);
|
||||
if ($imgur_page !== '') $url = $imgur_page;
|
||||
}
|
||||
|
||||
$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']);
|
||||
}
|
||||
|
||||
@@ -812,19 +744,6 @@ 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,
|
||||
@@ -951,10 +870,6 @@ function media_provider_oembed_endpoint(string $url, string $host): string {
|
||||
if (media_host_matches($host, 'dailymotion.com') || media_host_matches($host, 'dai.ly')) {
|
||||
return 'https://www.dailymotion.com/services/oembed?url=' . rawurlencode($url);
|
||||
}
|
||||
if (media_host_matches($host, 'imgur.com') || media_host_matches($host, 'i.imgur.com')) {
|
||||
$imgur_page = media_imgur_page_url($url);
|
||||
if ($imgur_page !== '') return 'https://api.imgur.com/oembed.json?url=' . rawurlencode($imgur_page);
|
||||
}
|
||||
if (media_host_matches($host, 'tiktok.com')) {
|
||||
return 'https://www.tiktok.com/oembed?url=' . rawurlencode($url);
|
||||
}
|
||||
@@ -1086,14 +1001,6 @@ function media_external_metadata(string $url): array {
|
||||
if ($url === '') return $metadata;
|
||||
|
||||
$host = strtolower((string)(parse_url($url, PHP_URL_HOST) ?? ''));
|
||||
if (media_host_matches($host, 'imgur.com') || media_host_matches($host, 'i.imgur.com')) {
|
||||
$imgur_page = media_imgur_page_url($url);
|
||||
if ($imgur_page !== '') {
|
||||
$url = $imgur_page;
|
||||
$metadata['url'] = $url;
|
||||
$host = strtolower((string)(parse_url($url, PHP_URL_HOST) ?? ''));
|
||||
}
|
||||
}
|
||||
$provider = media_provider_embed($url);
|
||||
$metadata['provider'] = $provider['provider'] ?? '';
|
||||
|
||||
@@ -1168,13 +1075,6 @@ function media_provider_thumbnail_url(string $url): string {
|
||||
if ($id !== '') return 'https://www.dailymotion.com/thumbnail/video/' . rawurlencode($id);
|
||||
}
|
||||
|
||||
if (media_host_matches($host, 'imgur.com') || media_host_matches($host, 'i.imgur.com')) {
|
||||
$imgur_path = media_imgur_path_from_url($url);
|
||||
if ($imgur_path !== '' && !str_contains($imgur_path, '/')) {
|
||||
return 'https://i.imgur.com/' . rawurlencode($imgur_path) . 'h.jpg';
|
||||
}
|
||||
}
|
||||
|
||||
return media_oembed_thumbnail_url($url, $host);
|
||||
}
|
||||
|
||||
@@ -1310,11 +1210,6 @@ function media_provider_embed(string $url): ?array {
|
||||
if ($id !== '') return ['provider' => 'dailymotion', 'embed' => 'https://www.dailymotion.com/embed/video/' . rawurlencode($id)];
|
||||
}
|
||||
|
||||
if (media_host_matches($host, 'imgur.com') || media_host_matches($host, 'i.imgur.com')) {
|
||||
$embed = media_imgur_embed_url($url);
|
||||
if ($embed !== '') return ['provider' => 'imgur', 'embed' => $embed];
|
||||
}
|
||||
|
||||
if (media_host_matches($host, 'twitch.tv')) {
|
||||
$parent = media_twitch_parent_host();
|
||||
if (preg_match('#/videos/(\d+)#', $path, $m)) {
|
||||
|
||||
Reference in New Issue
Block a user