// ==UserScript== // @name Hulu.com Subtitle Downloader // @namespace https://www.hulu.com // @version 1.0.5 // @description Downloads subtitle from Hulu.com as SRT format // @author subdiox // @match https://www.hulu.com/* // @require https://code.jquery.com/jquery-3.7.1.slim.min.js // @require https://update.greasyfork.icu/scripts/502635/1422102/waitForKeyElements-CoeJoder-fork.js // @grant GM_xmlhttpRequest // @copyright 2025, subdiox // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/419624/Hulucom%20Subtitle%20Downloader.user.js // @updateURL https://update.greasyfork.icu/scripts/419624/Hulucom%20Subtitle%20Downloader.meta.js // ==/UserScript== waitForKeyElements('.PlayerSettingsGroup', pageDidLoad); function pageDidLoad(jNode) { jNode.appendChild(createDownloadButton()); } function createDownloadButton() { const button = document.createElement('div'); button.id = 'download-button'; button.className = 'PlayerButton PlayerControlsButton'; button.setAttribute('aria-label', 'Download'); button.setAttribute('role', 'button'); button.setAttribute('tabindex', '0'); button.style.touchAction = 'none'; button.innerHTML = '' + '' + '' + ''; button.addEventListener('click', downloadDidClick); return button; } async function downloadDidClick() { const playbackXhr = new XMLHttpRequest(); const contentId = window.location.href.split('/').pop(); playbackXhr.open('GET', `https://discover.hulu.com/content/v5/deeplink/playback?namespace=entity&schema=1&id=${contentId}`, false); playbackXhr.withCredentials = true; playbackXhr.send(null); const playbackData = JSON.parse(playbackXhr.responseText); const captionId = playbackData.eab_id.split('::')[2]; const entityXhr = new XMLHttpRequest(); entityXhr.open('GET', `https://discover.hulu.com/content/v3/entity?device_context_id=1&language=en&referral_host=www.hulu.com&schema=4&eab_ids=${playbackData.eab_id}`, false); entityXhr.withCredentials = true; entityXhr.send(null); const entityData = JSON.parse(entityXhr.responseText); let filename = ''; const seriesName = entityData.items[0].series_name; const seasonNumber = entityData.items[0].season; const episodeNumber = entityData.items[0].number; const episodeTitle = entityData.items[0].name; if (seriesName) filename += `${seriesName} `; if (seasonNumber) filename += `S ${seasonNumber} `; if (episodeNumber) filename += `E ${episodeNumber} `; if (episodeTitle) { filename = filename ? `${filename}- ${episodeTitle}.srt` : `${episodeTitle}.srt`; } if (!filename) filename = `${captionId}.srt`; const captionsXhr = new XMLHttpRequest(); captionsXhr.open('GET', `https://www.hulu.com/captions.xml?content_id=${captionId}`, false); captionsXhr.withCredentials = true; captionsXhr.send(null); const parser = new DOMParser(); const xmlDoc = parser.parseFromString(captionsXhr.responseText, 'text/xml'); const xmlElement = xmlDoc.getElementsByTagName('en')[0]; let vttUrl = `https://assetshuluimcom-a.akamaihd.net/captions_webvtt/${captionId.substr(-3)}/${captionId}_US_en_en.vtt`; if (xmlElement) { vttUrl = xmlElement.childNodes[0].nodeValue .replace('captions', 'captions_webvtt') .replace('.smi', '.vtt'); } GM_xmlhttpRequest({ method: 'GET', url: vttUrl, onload: (response) => { let cleanedVtt = ''; const vttText = response.responseText .replace(/>/g, '>') .replace(/</g, '<'); for (const line of vttText.split('\n')) { if (!/WEBVTT/.test(line)) { cleanedVtt += line.replace( /(\d{2}:\d{2}:\d{2})\.(\d{3})\s+-->\s*(\d{2}:\d{2}:\d{2})\.(\d{3})/g, '$1,$2 --> $3,$4' ) + '\n'; } } let srtContent = ''; for (const [index, rawBlock] of cleanedVtt.split('\n\n').entries()) { const block = rawBlock.trim(); if (!block) continue; srtContent += `${index + 1}\n${block}\n\n`; } downloadSRT(srtContent, filename); } }); } function downloadSRT(srtText, filename) { const blob = new Blob([srtText], { type: 'text/plain;charset=utf-8' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = filename; document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(url); }