From b3ad303de81bce7981eac44e287fc818443966b6 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Tue, 15 Mar 2022 00:42:57 +0300 Subject: [PATCH] Update index_country_m3u.js --- scripts/generators/index_country_m3u.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/generators/index_country_m3u.js b/scripts/generators/index_country_m3u.js index 7f06ae84f8..448af2bcf9 100644 --- a/scripts/generators/index_country_m3u.js +++ b/scripts/generators/index_country_m3u.js @@ -12,6 +12,10 @@ module.exports = async function (streams = []) { let countries = await api.countries.all() countries = _.keyBy(countries, 'code') + await api.subdivisions.load() + let subdivisions = await api.subdivisions.all() + subdivisions = _.keyBy(subdivisions, 'code') + let items = [] streams.forEach(stream => { if (!stream.broadcast_area.length) { @@ -21,7 +25,8 @@ module.exports = async function (streams = []) { return } - getBroadcastCountries(stream, { countries, regions }).forEach(country => { + const broadcastCountries = getBroadcastCountries(stream, { countries, regions, subdivisions }) + broadcastCountries.forEach(country => { const item = _.cloneDeep(stream) item.group_title = country.name items.push(item) @@ -37,7 +42,7 @@ module.exports = async function (streams = []) { return { filepath: 'index.country.m3u', items } } -function getBroadcastCountries(stream, { countries, regions }) { +function getBroadcastCountries(stream, { countries, regions, subdivisions }) { let codes = stream.broadcast_area.reduce((acc, item) => { const [type, code] = item.split('/') switch (type) { @@ -50,8 +55,9 @@ function getBroadcastCountries(stream, { countries, regions }) { } break case 's': - const [c] = item.split('-') - acc.push(c) + if (subdivisions[code]) { + acc.push(subdivisions[code].country) + } break } return acc