Skip to content

Commit

Permalink
Refactor Stream Hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Nov 1, 2023
1 parent f96505c commit a6223a8
Show file tree
Hide file tree
Showing 8 changed files with 1,089 additions and 561 deletions.
75 changes: 75 additions & 0 deletions Build/build-stream-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// @ts-check
const { task } = require('./lib/trace-runner');

const path = require('path');
const { createRuleset } = require('./lib/create-file');

const { ALL, NORTH_AMERICA, EU, HK, TW, JP, AU, KR } = require('../Source/stream');

/**
* @param {string} fileId
* @param {string} title
* @param {import('../Source/stream').StreamService[]} streamServices
*/
const createRulesetForStreamService = (fileId, title, streamServices) => {
return [
// Domains
...createRuleset(
`Sukka's Ruleset - Stream Services: ${title}`,
[
'License: AGPL 3.0',
'Homepage: https://ruleset.skk.moe',
'GitHub: https://github.com/SukkaW/Surge',
'',
...streamServices.map(i => `- ${i.name}`)
],
new Date(),
streamServices.flatMap(i => i.rules),
'ruleset',
path.resolve(__dirname, `../List/non_ip/${fileId}.conf`),
path.resolve(__dirname, `../Clash/non_ip/${fileId}.txt`)
),
// IP
...createRuleset(
`Sukka's Ruleset - Stream Services' IPs: ${title}`,
[
'License: AGPL 3.0',
'Homepage: https://ruleset.skk.moe',
'GitHub: https://github.com/SukkaW/Surge',
'',
...streamServices.map(i => `- ${i.name}`)
],
new Date(),
streamServices.flatMap(i => (
i.ip
? [
...i.ip.v4.map(ip => `IP-CIDR,${ip},no-resolve`),
...i.ip.v6.map(ip => `IP-CIDR6,${ip},no-resolve`)
]
: []
)),
'ruleset',
path.resolve(__dirname, `../List/ip/${fileId}.conf`),
path.resolve(__dirname, `../Clash/ip/${fileId}.txt`)
)
];
};

const buildStreamService = task(__filename, async () => {
return Promise.all([
...createRulesetForStreamService('stream', 'All', ALL),
...createRulesetForStreamService('stream_us', 'North America', NORTH_AMERICA),
...createRulesetForStreamService('stream_eu', 'Europe', EU),
...createRulesetForStreamService('stream_hk', 'Hong Kong', HK),
...createRulesetForStreamService('stream_tw', 'Taiwan', TW),
...createRulesetForStreamService('stream_jp', 'Japan', JP),
...createRulesetForStreamService('stream_au', 'Oceania', AU),
...createRulesetForStreamService('stream_kr', 'Korean', KR)
]);
});

module.exports.buildStreamService = buildStreamService;

if (require.main === module) {
buildStreamService();
}
7 changes: 5 additions & 2 deletions Build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const { buildSpeedtestDomainSet } = require('./build-speedtest-domainset');
const { buildInternalCDNDomains } = require('./build-internal-cdn-rules');
const { buildInternalChnDomains } = require('./build-internal-chn-domains');
const { buildDomesticRuleset } = require('./build-domestic-ruleset');
const { buildStreamService } = require('./build-stream-service');
const { buildRedirectModule } = require('./build-redirect-module');
const { validate } = require('./validate-domainset');

Expand Down Expand Up @@ -103,8 +104,9 @@ const endWorker = async (worker) => {
const buildInternalChnDomainsPromise = buildInternalChnDomains();
// build:domestic-ruleset
const buildDomesticRulesetPromise = downloadPreviousBuildPromise.then(() => buildDomesticRuleset());
// build:redirect-module

const buildRedirectModulePromise = downloadPreviousBuildPromise.then(() => buildRedirectModule());
const buildStreamServicePromise = downloadPreviousBuildPromise.then(() => buildStreamService());

const stats = await Promise.all([
downloadPreviousBuildPromise,
Expand All @@ -122,7 +124,8 @@ const endWorker = async (worker) => {
buildInternalReverseChnCIDRPromise,
buildInternalChnDomainsPromise,
buildDomesticRulesetPromise,
buildRedirectModulePromise
buildRedirectModulePromise,
buildStreamServicePromise
]);

await Promise.all([
Expand Down
9 changes: 9 additions & 0 deletions Build/lib/create-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ async function compareAndWriteFile(linesA, filePath) {
if (!fs.existsSync(filePath)) {
console.log(`${filePath} does not exists, writing...`);
isEqual = false;
} else if (linesA.length === 0) {
console.log(`Nothing to write to ${filePath}...`);
isEqual = false;
} else {
let index = 0;

for await (const lineB of readFileByLine(filePath)) {
const lineA = linesA[index];
index++;

if (lineA === undefined) {
// The file becomes smaller
isEqual = false;
break;
}

if (lineA[0] === '#' && lineB[0] === '#') {
continue;
}
Expand Down
6 changes: 6 additions & 0 deletions Source/domainset/cdn.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ files.slack.com
cdn.sstatic.net
# PornHub
.phncdn.com
# phprcdn.com # PornHub Premium CDN
# Font.net
.fonts.com
.fonts.net
Expand Down Expand Up @@ -1674,6 +1675,11 @@ headway-widget.net
cdn2.downdetector.com
# DailyMotion
.dmcdn.net
# NowE
images.now-tv.com
.nowestatic.com
# Paramount+
.pplusstatic.com
# Others
.ziffstatic.com
.muscache.com
Expand Down
2 changes: 2 additions & 0 deletions Source/domainset/download.conf
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,5 @@ enterprise.proxmox.com
# Linux Mirrors
mirror.navercorp.com
fedorapeople.org
# WhatPulse
releases.whatpulse.org
27 changes: 0 additions & 27 deletions Source/ip/stream.conf

This file was deleted.

Loading

0 comments on commit a6223a8

Please sign in to comment.