mirror of
https://github.com/iptv-org/epg
synced 2025-12-17 02:47:02 -05:00
continuing, WIP
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { SiteConfig } from 'epg-grabber'
|
import { SiteConfig } from 'epg-grabber'
|
||||||
import { deepMerge } from '../functions/functions'
|
import { deepMerge } from '../functions'
|
||||||
import { pathToFileURL } from 'url'
|
import { pathToFileURL } from 'url'
|
||||||
|
|
||||||
export class ConfigLoader {
|
export class ConfigLoader {
|
||||||
|
|||||||
@@ -11,8 +11,7 @@
|
|||||||
* const uniqueItems = uniqBy(items, item => item.id);
|
* const uniqueItems = uniqBy(items, item => item.id);
|
||||||
* // uniqueItems will be [{ id: 1, name: 'A' }, { id: 2, name: 'B' }]
|
* // uniqueItems will be [{ id: 1, name: 'A' }, { id: 2, name: 'B' }]
|
||||||
*/
|
*/
|
||||||
export const uniqBy = <T, K>(arr: T[], fn: (item: T) => K): T[] =>
|
export const uniqBy = <T, K>(arr: T[], fn: (item: T) => K): T[] => [...new Map(arr.map(x => [fn(x), x])).values()]
|
||||||
Array.from(new Map(arr.map(item => [fn(item), item])).values())
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively merges multiple objects into a single object.
|
* Recursively merges multiple objects into a single object.
|
||||||
|
|||||||
1
scripts/functions/index.ts
Normal file
1
scripts/functions/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './functions'
|
||||||
@@ -3,9 +3,7 @@ const utc = require('dayjs/plugin/utc')
|
|||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
const parseDuration = require('parse-duration').default
|
const parseDuration = require('parse-duration').default
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
|
const { sortBy } = require('../../scripts/functions')
|
||||||
// importing custom function sortBy
|
|
||||||
const sortBy = require('../functions/functions')
|
|
||||||
|
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const dayjs = require('dayjs')
|
|||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
const { uniqBy } = require('../../functions/functions')
|
const { uniqBy } = require('../../scripts/functions')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone)
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
const axios = require('axios')
|
||||||
const cheerio = require('cheerio')
|
const cheerio = require('cheerio')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
const { uniqBy } = require('../../scripts/functions')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone)
|
||||||
@@ -41,9 +43,6 @@ module.exports = {
|
|||||||
return programs
|
return programs
|
||||||
},
|
},
|
||||||
async channels() {
|
async channels() {
|
||||||
const axios = require('axios')
|
|
||||||
const _ = require('lodash')
|
|
||||||
|
|
||||||
const providers = ['-1', '-2', '-3']
|
const providers = ['-1', '-2', '-3']
|
||||||
|
|
||||||
const channels = []
|
const channels = []
|
||||||
@@ -77,7 +76,7 @@ module.exports = {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return _.uniqBy(channels, 'site_id')
|
return uniqBy(channels, 'site_id')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
const axios = require('axios')
|
||||||
const cheerio = require('cheerio')
|
const cheerio = require('cheerio')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
const { uniqBy } = require('../../scripts/functions')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone)
|
||||||
@@ -45,9 +47,6 @@ module.exports = {
|
|||||||
return programs
|
return programs
|
||||||
},
|
},
|
||||||
async channels({ country }) {
|
async channels({ country }) {
|
||||||
const axios = require('axios')
|
|
||||||
const _ = require('lodash')
|
|
||||||
|
|
||||||
const providers = {
|
const providers = {
|
||||||
au: ['o', 'a'],
|
au: ['o', 'a'],
|
||||||
ca: [
|
ca: [
|
||||||
@@ -147,7 +146,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _.uniqBy(channels, 'site_id')
|
return uniqBy(channels, 'site_id')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const cheerio = require('cheerio')
|
|||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
const _ = require('lodash')
|
const { sortBy, uniqBy } = require('../../scripts/functions')
|
||||||
|
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone)
|
||||||
@@ -29,7 +29,7 @@ module.exports = {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
programs = _.orderBy(_.uniqBy(programs, 'start'), 'start')
|
programs = sortBy(uniqBy(programs, p => p.start), 'start')
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
const { DateTime } = require('luxon')
|
const { DateTime } = require('luxon')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
|
const { uniqBy } = require('../../scripts/functions')
|
||||||
// Remove the big lodash dependency by implementing a simple uniqBy function
|
|
||||||
// Complexity = O(n)
|
|
||||||
const uniqBy = (arr, fn) => [...new Map(arr.map(x => [fn(x), x])).values()]
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'tv.mail.ru',
|
site: 'tv.mail.ru',
|
||||||
|
|||||||
Reference in New Issue
Block a user