| 16 | |
| 17 | export class CountriesTable implements Table { |
| 18 | async create() { |
| 19 | const parser = new LogParser() |
| 20 | const logsStorage = new Storage(LOGS_DIR) |
| 21 | const generatorsLog = await logsStorage.load('generators.log') |
| 22 | const parsed = parser.parse(generatorsLog) |
| 23 | const logCountries = parsed.filter((logItem: LogItem) => logItem.type === 'country') |
| 24 | const logSubdivisions = parsed.filter((logItem: LogItem) => logItem.type === 'subdivision') |
| 25 | const logCities = parsed.filter((logItem: LogItem) => logItem.type === 'city') |
| 26 | |
| 27 | let items = new Collection() |
| 28 | data.countries.forEach((country: sdk.Models.Country) => { |
| 29 | const countryCode = country.code |
| 30 | const countriesLogItem = logCountries.find( |
| 31 | (logItem: LogItem) => logItem.filepath === `countries/${countryCode.toLowerCase()}.m3u` |
| 32 | ) |
| 33 | |
| 34 | const countryItem: ListItem = { |
| 35 | index: country.name, |
| 36 | count: 0, |
| 37 | link: `https://iptv-org.github.io/iptv/countries/${countryCode.toLowerCase()}.m3u`, |
| 38 | name: `${country.flag} ${country.name}`, |
| 39 | children: new Collection() |
| 40 | } |
| 41 | |
| 42 | if (countriesLogItem) { |
| 43 | countryItem.count = countriesLogItem.count |
| 44 | } |
| 45 | |
| 46 | const countrySubdivisions = data.subdivisions.filter( |
| 47 | (subdivision: sdk.Models.Subdivision) => subdivision.country === countryCode |
| 48 | ) |
| 49 | const countryCities = data.cities.filter( |
| 50 | (city: sdk.Models.City) => city.country === countryCode |
| 51 | ) |
| 52 | if (countrySubdivisions.isNotEmpty()) { |
| 53 | data.subdivisions.forEach((subdivision: sdk.Models.Subdivision) => { |
| 54 | if (subdivision.country !== countryCode) return |
| 55 | |
| 56 | const subdivisionCode = subdivision.code |
| 57 | const subdivisionCities = countryCities.filter( |
| 58 | (city: sdk.Models.City) => |
| 59 | (city.subdivision && city.subdivision === subdivisionCode) || |
| 60 | city.country === subdivision.country |
| 61 | ) |
| 62 | const subdivisionsLogItem = logSubdivisions.find( |
| 63 | (logItem: LogItem) => |
| 64 | logItem.filepath === `subdivisions/${subdivisionCode.toLowerCase()}.m3u` |
| 65 | ) |
| 66 | |
| 67 | const subdivisionItem: ListItem = { |
| 68 | index: subdivision.name, |
| 69 | name: subdivision.name, |
| 70 | count: 0, |
| 71 | link: `https://iptv-org.github.io/iptv/subdivisions/${subdivisionCode.toLowerCase()}.m3u`, |
| 72 | children: new Collection<ListItem>() |
| 73 | } |
| 74 | |
| 75 | if (subdivisionsLogItem) { |