mirror of
https://github.com/iptv-org/epg
synced 2026-04-06 19:02:53 -04:00
rewrite mail.ru config, recreate UniqBy in native JS
This commit is contained in:
65
sites/tv.mail.ru/__data__/content.json
Normal file
65
sites/tv.mail.ru/__data__/content.json
Normal file
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"status":"OK",
|
||||
"schedule":[
|
||||
{
|
||||
"channel":{
|
||||
"name":"21TV",
|
||||
"pic_url":"https://resizer.mail.ru/p/1234c5ac-c19c-5cf2-9c6a-fc0efca920ac/AAACm2w9aDpGPSWXzsH7PBq2X3I6pbxqmrj-yeuVppAKyyBHXE_dH_7pHQ2rOavyKiC4iHIWTab9SeKo7pKgr71lqVA.png",
|
||||
"pic_url_128":"https://resizer.mail.ru/p/1234c5ac-c19c-5cf2-9c6a-fc0efca920ac/AAACwjJ45j9sTP8fcjPJnJ4xk5e_ILr5iXwjLMhWhzlVnIJkrtT42vEp9walcgpXRKDq9KFoliEPR0xI-LEh96C_izY.png",
|
||||
"pic_url_64":"https://resizer.mail.ru/p/1234c5ac-c19c-5cf2-9c6a-fc0efca920ac/dpr:200/AAACm2w9aDpGPSWXzsH7PBq2X3I6pbxqmrj-yeuVppAKyyBHXE_dH_7pHQ2rOavyKiC4iHIWTab9SeKo7pKgr71lqVA.png"
|
||||
},
|
||||
"event":{
|
||||
"current":[
|
||||
{
|
||||
"channel_id":"2785",
|
||||
"name":"Պրոֆեսիոնալները",
|
||||
"category_id":8,
|
||||
"episode_title":"",
|
||||
"url":"/moskva/channel/2785/173593246/",
|
||||
"id":"173593246",
|
||||
"start":"02:40",
|
||||
"episode_num":0
|
||||
},
|
||||
{
|
||||
"channel_id":"2785",
|
||||
"name":"Նոնստոպ․ Տեսահոլովակներ",
|
||||
"category_id":23,
|
||||
"episode_title":"",
|
||||
"url":"/moskva/channel/2785/173593142/",
|
||||
"id":"173593142",
|
||||
"start":"03:25",
|
||||
"episode_num":0
|
||||
}
|
||||
],
|
||||
"past":[
|
||||
{
|
||||
"channel_id":"2785",
|
||||
"name":"Նոնստոպ․ Տեսահոլովակներ",
|
||||
"category_id":23,
|
||||
"episode_title":"",
|
||||
"url":"/moskva/channel/2785/173593328/",
|
||||
"id":"173593328",
|
||||
"start":"23:35",
|
||||
"episode_num":0
|
||||
},
|
||||
{
|
||||
"channel_id":"2785",
|
||||
"video":{
|
||||
"currency":"RUB",
|
||||
"price_min":"249.00",
|
||||
"price_txt":"249 р."
|
||||
},
|
||||
"name":"Վերջին թագավորությունը",
|
||||
"category_id":2,
|
||||
"episode_title":"",
|
||||
"url":"/moskva/channel/2785/173593318/",
|
||||
"id":"173593318",
|
||||
"start":"01:40",
|
||||
"our_event_id":"890224",
|
||||
"episode_num":0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
23
sites/tv.mail.ru/__data__/no_content.json
Normal file
23
sites/tv.mail.ru/__data__/no_content.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"status":"OK",
|
||||
"current_ts":1637788593,
|
||||
"form":{
|
||||
"values":[
|
||||
|
||||
]
|
||||
},
|
||||
"current_offset":10800,
|
||||
"schedule":[
|
||||
{
|
||||
"channel":null,
|
||||
"event":{
|
||||
"current":[
|
||||
|
||||
],
|
||||
"past":[
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,21 @@
|
||||
const { DateTime } = require('luxon')
|
||||
const axios = require('axios')
|
||||
|
||||
// Remove the big lodash dependency by implementing a simple uniqBy function
|
||||
// Complexity = O(n)
|
||||
const uniqBy = (arr, predicate) => {
|
||||
const cb = typeof predicate === 'function' ? predicate : (o) => o[predicate]
|
||||
|
||||
return [...arr.reduce((map, item) => {
|
||||
const key = (item === null || item === undefined) ?
|
||||
item : cb(item)
|
||||
|
||||
if (!map.has(key)) map.set(key, item)
|
||||
|
||||
return map
|
||||
}, new Map()).values()]
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
site: 'tv.mail.ru',
|
||||
days: 2,
|
||||
@@ -35,8 +50,6 @@ module.exports = {
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const _ = require('lodash')
|
||||
|
||||
const regions = [5506, 1096, 1125, 285]
|
||||
|
||||
let channels = []
|
||||
@@ -64,7 +77,7 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
return _.uniqBy(channels, 'site_id')
|
||||
return uniqBy(channels, 'site_id')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ const { parser, url } = require('./tv.mail.ru.config.js')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
@@ -10,8 +12,7 @@ const channel = {
|
||||
site_id: '2785',
|
||||
xmltv_id: '21TV.am'
|
||||
}
|
||||
const content =
|
||||
'{"status":"OK","schedule":[{"channel":{"name":"21TV","pic_url":"https://resizer.mail.ru/p/1234c5ac-c19c-5cf2-9c6a-fc0efca920ac/AAACm2w9aDpGPSWXzsH7PBq2X3I6pbxqmrj-yeuVppAKyyBHXE_dH_7pHQ2rOavyKiC4iHIWTab9SeKo7pKgr71lqVA.png","pic_url_128":"https://resizer.mail.ru/p/1234c5ac-c19c-5cf2-9c6a-fc0efca920ac/AAACwjJ45j9sTP8fcjPJnJ4xk5e_ILr5iXwjLMhWhzlVnIJkrtT42vEp9walcgpXRKDq9KFoliEPR0xI-LEh96C_izY.png","pic_url_64":"https://resizer.mail.ru/p/1234c5ac-c19c-5cf2-9c6a-fc0efca920ac/dpr:200/AAACm2w9aDpGPSWXzsH7PBq2X3I6pbxqmrj-yeuVppAKyyBHXE_dH_7pHQ2rOavyKiC4iHIWTab9SeKo7pKgr71lqVA.png"},"event":{"current":[{"channel_id":"2785","name":"Պրոֆեսիոնալները","category_id":8,"episode_title":"","url":"/moskva/channel/2785/173593246/","id":"173593246","start":"02:40","episode_num":0},{"channel_id":"2785","name":"Նոնստոպ․ Տեսահոլովակներ","category_id":23,"episode_title":"","url":"/moskva/channel/2785/173593142/","id":"173593142","start":"03:25","episode_num":0}],"past":[{"channel_id":"2785","name":"Նոնստոպ․ Տեսահոլովակներ","category_id":23,"episode_title":"","url":"/moskva/channel/2785/173593328/","id":"173593328","start":"23:35","episode_num":0},{"channel_id":"2785","video":{"currency":"RUB","price_min":"249.00","price_txt":"249 р."},"name":"Վերջին թագավորությունը","category_id":2,"episode_title":"","url":"/moskva/channel/2785/173593318/","id":"173593318","start":"01:40","our_event_id":"890224","episode_num":0}]}}]}'
|
||||
const content = fs.readFileSync(path.join(__dirname, '__data__', 'content.json'), 'utf8')
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
@@ -70,8 +71,7 @@ it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content:
|
||||
'{"status":"OK","current_ts":1637788593,"form":{"values":[]},"current_offset":10800,"schedule":[{"channel":null,"event":{"current":[],"past":[]}}]}'
|
||||
content: fs.readFileSync(path.join(__dirname, '__data__', 'no_content.json'), 'utf8')
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user