# [メタ情報]
# 識別子: 無音ループ動画パッケージphpと埋め込みコード_exe
# システム名: 無音ループ動画パッケージphpと埋め込みコード_exe
# 技術種別: Misc
# 機能名: Misc
# 使用言語: php カスタムhtml
# 状態: 実行用
# [/メタ情報]
要約:高画質・無音オートループ・枠内字幕に特化した dr53 / dr53emd テンプレートの説明。videoct.json から動画・画像・字幕・説明文を取得し、ID 自動プローブで rd.php を優先的に使用して高画質を安定再生する。字幕はネイティブ軌道を隠し、JS により枠内オーバーレイ表示。PiP・フルスクリーン・AirPlay などの状態に応じて自動的にネイティブ表示へ切替える。動画は autoplay muted loop で自動再生し、クリックで一時停止/再開、タブ復帰時の再生再試行も行う。
字幕一覧(TXT)は で展開し、クリックで動画内の該当秒へジャンプ。説明文は TXT/HTML に対応。dr53emd は埋め込み用で、ヘッダやフッタを除外し iframe 的に動作。dynamic3 コードは別画面リンクと埋め込み表示を組み合わせ、既存の再生メディアを自動停止して安全に画面遷移する。
dr53.php
$timeout,
'headers' => ['User-Agent' => 'dr53/1.0'],
]);
if (is_wp_error($res)) return null;
$code = (int) wp_remote_retrieve_response_code($res);
if ($code < 200 || $code >= 300) return null;
$body = wp_remote_retrieve_body($res);
return ($body !== '') ? $body : null;
}
function dr53_fetch_videoct(): ?array {
$json_url = 'https://xxxxxxxx.com/gd_proxy/?f=videoct.json';
$body = dr53_http_get($json_url, 12);
if ($body === null) return null;
$data = json_decode($body, true);
return is_array($data) ? $data : null;
}
function dr53_find_video(array $rows, string $drid): ?array {
foreach ($rows as $r) {
if (isset($r['videoid']) && (string)$r['videoid'] === (string)$drid) return $r;
}
return null;
}
/** URL→wpidex 抽出(rd.php?id=... / 直リンク両対応) */
function dr53_extract_wpidex_from_url(?string $u): string {
if (!$u) return '';
$p = parse_url($u);
if (!empty($p['query'])) {
parse_str($p['query'], $qs);
if (!empty($qs['id'])) {
$id = (string)$qs['id'];
$id = preg_replace('/\.(mp4|m4v|mov|mp3|m4a|wav|jpg|jpeg|png|gif|webp|vtt|srt|txt)$/i', '', $id);
return $id ?: '';
}
}
$path = $p['path'] ?? '';
if ($path === '') return '';
$base = basename($path);
$id = preg_replace('/\.(mp4|m4v|mov|mp3|m4a|wav|jpg|jpeg|png|gif|webp|vtt|srt|txt|php)$/i', '', $base);
return $id ?: '';
}
/* rd.php へのHEADで到達性チェック(200/206/302ならOK) */
function dr53_try_rd(string $id): int {
if ($id === '') return -1;
$rd_abs = rtrim(home_url('/rd.php'), '/');
$url = $rd_abs . '?id=' . rawurlencode($id) . '&mode=dynamic';
$head = wp_remote_head($url, ['timeout'=>8, 'headers'=>['Range'=>'bytes=0-1']]);
if (is_wp_error($head)) return -1;
return (int) wp_remote_retrieve_response_code($head);
}
/* 候補IDを順に試し、最初に2xx/3xxのidを返す */
function dr53_probe_id(array $candidates, array &$diag_log): ?array {
$seen = [];
foreach ($candidates as $cand) {
$cand = trim((string)$cand);
if ($cand === '') continue;
$key = strtolower($cand);
if (isset($seen[$key])) continue;
$seen[$key] = true;
$code = dr53_try_rd($cand);
$diag_log[] = sprintf('probe id="%s" -> %d', $cand, $code);
if ($code >= 200 && $code < 400) return ['id' => $cand, 'code' => $code];
}
return null;
}
/* ========= 本体 ========= */
get_header();
$drid = dr53_get_drid();
$diag = isset($_GET['diag']) ? 1 : 0;
$rid_override = isset($_GET['rid']) ? trim((string)$_GET['rid']) : ''; // rd.php id を強制上書き
$force_direct = (!empty($_GET['force']) && $_GET['force'] === 'direct'); // 直リンク再生(診断用)
echo '';
if ($drid === '') {
echo '
drid が指定されていません。(例:?drid=XXXX)
';
echo '
'; get_footer(); return;
}
$rows = dr53_fetch_videoct();
if (!$rows) {
echo 'JSONデータの取得に失敗しました。(videoct.json)
';
echo ''; get_footer(); return;
}
$v = dr53_find_video($rows, $drid);
if (!$v) {
echo '該当IDが見つかりません:' . esc_html($drid) . '
';
echo ''; get_footer(); return;
}
$image_url = (string)($v['image'] ?? '');
$video_url = (string)($v['video'] ?? ''); // 高画質
$video2_url = (string)($v['video2'] ?? ''); // 低画質(未使用)
$subtitle_url = (string)($v['subtitle'] ?? '');
$subtitle_list_url = (string)($v['subtitle_list'] ?? '');
$explain_line_url = (string)($v['explain_line'] ?? '');
/* ====== rd.phpに渡す id を自動決定(高画質優先) ====== */
$rd_abs = rtrim(home_url('/rd.php'), '/');
$diag_log = [];
if ($rid_override !== '') {
$chosen_id = $rid_override;
$chosen_code = dr53_try_rd($chosen_id);
$diag_log[] = sprintf('override id="%s" code=%d', $chosen_id, $chosen_code);
} else {
$cands = [];
$cands[] = dr53_extract_wpidex_from_url($video_url); // 高画質を最優先
$cands[] = dr53_extract_wpidex_from_url($subtitle_url);
$cands[] = dr53_extract_wpidex_from_url($image_url);
$cands[] = $drid; // 保険
$more = [];
foreach ($cands as $c) { if (!$c) continue; $more[] = strtolower($c); $more[] = strtoupper($c); }
$cands = array_merge($cands, $more);
$picked = dr53_probe_id($cands, $diag_log);
if ($picked) { $chosen_id = $picked['id']; $chosen_code = $picked['code']; }
else { $chosen_id = ''; $chosen_code = -1; }
}
/* 再生ソース決定:通常は rd.php(dynamic)/?force=direct=1 なら直リンク(video) */
$stream_src = '';
if ($force_direct && !empty($video_url)) {
$stream_src = $video_url; // 直リンク
$diag_log[] = 'force_direct=1 → stream_src = direct high-quality URL';
} else {
if ($chosen_id !== '') {
$stream_src = $rd_abs . '?id=' . rawurlencode($chosen_id) . '&mode=dynamic';
$diag_log[] = 'stream_src via rd.php (mode=dynamic)';
} else {
$stream_src = $video_url; // 黒画面回避の保険
$diag_log[] = 'chosen_id empty → fallback to direct high-quality URL';
}
}
/* ====== 診断 ====== */
if ($diag) {
echo '診断(dr53)
';
$diag_txt =
"drid={$drid}\n".
"video_url={$video_url}\n".
"subtitle_url={$subtitle_url}\n".
"image_url={$image_url}\n".
"chosen_id={$chosen_id}\n".
"chosen_code={$chosen_code}\n".
"force_direct=" . ($force_direct ? '1' : '0') . "\n".
"stream_src={$stream_src}\n".
"--- probe log ---\n".implode("\n", $diag_log)."\n";
echo esc_html($diag_txt);
echo " ";
$head = wp_remote_head($stream_src, ['timeout'=>8,'headers'=>['Range'=>'bytes=0-1']]);
$code = is_wp_error($head) ? -1 : (int)wp_remote_retrieve_response_code($head);
$href = esc_url(add_query_arg('diag','1',$stream_src));
echo '';
}
/* ====== スタイル ====== */
?>
';
if (!empty($video_url)) {
echo '';
echo '
';
echo '
';
echo '
';
?>
(この動画の高画質版は準備中です)
';
}
echo '';
echo '';
/* ====== 字幕一覧 ====== */
if (!empty($subtitle_list_url)) {
echo '';
$html = dr53_http_get($subtitle_list_url, 10);
echo $html ? $html : '
字幕一覧の取得に失敗しました。
';
echo '
';
?>
';
if (strpos($txt, '<') !== false && strpos($txt, '>') !== false) {
echo wp_kses_post($txt);
} else {
echo '' . nl2br(esc_html($txt)) . '
';
}
echo '';
}
}
echo ''; // .dr5-container
if (have_posts()) : while (have_posts()) : the_post();
echo '';
the_content();
echo '
';
endwhile; endif;
get_footer();
dr53emd.php
$timeout, 'headers'=>['Cache-Control'=>'no-cache']]);
if (is_wp_error($res)) return null;
if (wp_remote_retrieve_response_code($res) !== 200) return null;
return wp_remote_retrieve_body($res);
}
function dr53emd_find_by_videoid(array $rows, string $vid): ?array {
foreach ($rows as $r) if (is_array($r) && (string)($r['videoid'] ?? '') === $vid) return $r;
return null;
}
/* ========= 本体 ========= */
$drid = dr53emd_get_drid();
$as_fragment = isset($_GET['frag']) || isset($_GET['embed']); // 埋め込みはヘッダ/フッタ無し
if (!$as_fragment) get_header();
if (!$drid) {
echo $as_fragment ? 'drid が未指定です。
'
: '動画ID(drid)が指定されていません。
';
if (!$as_fragment) get_footer(); exit;
}
$json_url = 'https://xxxxxxxx.com/gd_proxy/?f=videoct.json';
$json_text = dr53emd_http_get($json_url);
if (!$json_text) {
echo $as_fragment ? '動画情報の取得に失敗しました。
'
: '動画情報の取得に失敗しました。
';
if (!$as_fragment) get_footer(); exit;
}
$data = json_decode($json_text, true);
if (!is_array($data)) {
echo $as_fragment ? '動画情報が不正です。
'
: '動画情報が不正です。
';
if (!$as_fragment) get_footer(); exit;
}
$info = dr53emd_find_by_videoid($data, $drid);
if (!$info) {
$msg = '指定の動画が見つかりません: '.esc_html($drid).'
';
echo $as_fragment ? $msg : ''.$msg.'';
if (!$as_fragment) get_footer(); exit;
}
$poster = (string)($info['image'] ?? '');
$track = (string)($info['subtitle'] ?? '');
$listurl = (string)($info['subtitle_list'] ?? '');
$explain = (string)($info['explain_line'] ?? '');
$src = !empty($info['video']) ? (string)$info['video']
: ('https://xxxxxxxx.com/rd.php?id=' . rawurlencode($drid));
if (!$as_fragment) echo '';
?>
を内包)
if ($listurl) echo do_shortcode('[dynamic_external_html url="' . esc_url($listurl) . '"]');
// ▼ 説明文(TXT/HTMLどちらでもOK)
if ($explain) {
$body = dr53emd_http_get($explain);
if (is_string($body) && trim($body) !== '') {
$trimmed = trim($body);
if (stripos($trimmed, '<') !== false) {
echo '
' .
wp_kses(
$trimmed,
[
'br' => [],
'p' => [],
'strong' => [],
'em' => [],
'b' => [],
'i' => [],
'span' => ['style'=>[]],
// ★ リンクを許可(説明TXT内の
をそのまま出したい)
'a' => [
'href' => [],
'target' => [],
'rel' => [],
],
]
) .
'';
} else {
echo '
' . nl2br(esc_html($trimmed)) . '
';
}
}
}
?>
';
if (!$as_fragment) get_footer();
dynamic3埋め込みコード
👉別画面表示
[dynamic_external_html url="https://xxxxxxxx.com/dr53emd/?drid=@@VIDEOID@@&frag=1"]