diff --git a/src/consts.js b/src/consts.js index 8b5cfa8892..f7ad831982 100644 --- a/src/consts.js +++ b/src/consts.js @@ -6,7 +6,6 @@ const PROVIDERS = { migu: require('./provider/migu'), joox: require('./provider/joox'), youtube: require('./provider/youtube'), - ytdownload: require('./provider/yt-download'), youtubedl: require('./provider/youtube-dl'), ytdlp: require('./provider/yt-dlp'), bilibili: require('./provider/bilibili'), diff --git a/src/provider/match.js b/src/provider/match.js index 55b0101cbb..2219a54831 100644 --- a/src/provider/match.js +++ b/src/provider/match.js @@ -21,10 +21,7 @@ const logger = logScope('provider/match'); const isHttpResponseOk = (code) => code >= 200 && code <= 299; /** @type {Map} */ -const headerReferer = new Map([ - ['bilivideo.com', 'https://www.bilibili.com/'], - ['yt-download.org', 'https://www.yt-download.org/'], -]); +const headerReferer = new Map([['bilivideo.com', 'https://www.bilibili.com/']]); /** * @typedef {{ size: number, br: number | null, url: string | null, md5: string | null }} AudioData @@ -215,10 +212,7 @@ async function check(url) { ) || 0; // Check if the Content-Length equals 8192. - if ( - !isHost('yt-download.org') && - headers['content-length'] !== '8192' - ) { + if (headers['content-length'] !== '8192') { // I'm not sure how to describe this. // Seems like not important. return Promise.reject(); diff --git a/src/provider/yt-download.js b/src/provider/yt-download.js deleted file mode 100644 index 1380e2b781..0000000000 --- a/src/provider/yt-download.js +++ /dev/null @@ -1,63 +0,0 @@ -const request = require('../request'); -const { getManagedCacheStorage } = require('../cache'); - -// const proxy = require('url').parse('http://127.0.0.1:1080') -const proxy = undefined; -const key = process.env.YOUTUBE_KEY || null; // YouTube Data API v3 - -const apiSearch = (info) => { - const url = `https://www.googleapis.com/youtube/v3/search?part=snippet&q=${encodeURIComponent( - info.keyword - )}&type=video&key=${key}`; - - return request('GET', url, { accept: 'application/json' }, null, proxy) - .then((response) => response.json()) - .then((jsonBody) => { - const matched = jsonBody.items[0]; - if (matched) return matched.id.videoId; - else return Promise.reject(); - }); -}; - -const search = (info) => { - const url = `https://www.youtube.com/results?search_query=${encodeURIComponent( - info.keyword - )}`; - - return request('GET', url, {}, null, proxy) - .then((response) => response.body()) - .then((body) => { - const initialData = JSON.parse( - body.match(/ytInitialData\s*=\s*([^;]+);/)[1] - ); - const matched = - initialData.contents.twoColumnSearchResultsRenderer - .primaryContents.sectionListRenderer.contents[0] - .itemSectionRenderer.contents[0]; - if (matched) return matched.videoRenderer.videoId; - else return Promise.reject(); - }); -}; - -const track = (id) => { - const url = `https://www.yt-download.org/api/button/mp3/${id}`; - const regex = /]*href=["']([^"']*)["']/; - - return request('GET', url, {}, null, proxy) - .then((response) => response.body()) - .then((body) => { - var matched = body.match(regex); - return matched ? matched[1] : Promise.reject(); - }); -}; - -const cs = getManagedCacheStorage('provider/yt-download'); -const check = (info) => - cs - .cache(info, () => { - if (key) return apiSearch(info); - return search(info); - }) - .then(track); - -module.exports = { check, track }; diff --git a/src/server.js b/src/server.js index 66386ebb33..2ece39bccb 100644 --- a/src/server.js +++ b/src/server.js @@ -131,9 +131,6 @@ const proxy = { req.headers['referer'] = 'https://www.bilibili.com/'; req.headers['user-agent'] = 'okhttp/3.4.1'; } - if (isHost(req.url, 'yt-download.org')) { - req.headers['referer'] = 'https://www.yt-download.org/'; - } const url = parse(req.url); const options = request.configure(req.method, url, req.headers); ctx.proxyReq = request