mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Merge pull request #293 from iptv-org/update-tv-mail-ru
Update tv.mail.ru
This commit is contained in:
commit
c4dc1f504c
2 changed files with 92 additions and 22 deletions
|
@ -16,28 +16,29 @@ module.exports = {
|
|||
},
|
||||
logo({ content }) {
|
||||
const json = JSON.parse(content)
|
||||
if (json.status !== 'OK') return null
|
||||
if (!json || !Array.isArray(json.schedule)) return null
|
||||
|
||||
return json.schedule[0].channel.pic_url_64
|
||||
return json.schedule[0] && json.schedule[0].channel
|
||||
? json.schedule[0].channel.pic_url_128
|
||||
: null
|
||||
},
|
||||
parser({ content, date }) {
|
||||
let PM = false
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const title = parseTitle(item)
|
||||
const category = parseCategory(item)
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = parseStart(item, date)
|
||||
if (start.hour() > 11) PM = true
|
||||
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
||||
const stop = start.add(1, 'h')
|
||||
if (programs.length) {
|
||||
programs[programs.length - 1].stop = start
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
|
||||
const stop = start.add(1, 'h')
|
||||
programs.push({
|
||||
title,
|
||||
category,
|
||||
title: item.name,
|
||||
category: parseCategory(item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
|
@ -48,13 +49,9 @@ module.exports = {
|
|||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
const time = `${date.format('MM/DD/YYYY')} ${item.start}`
|
||||
const dateString = `${date.format('YYYY-MM-DD')} ${item.start}`
|
||||
|
||||
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Moscow')
|
||||
}
|
||||
|
||||
function parseTitle(item) {
|
||||
return item.name
|
||||
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Europe/Moscow')
|
||||
}
|
||||
|
||||
function parseCategory(item) {
|
||||
|
@ -62,24 +59,26 @@ function parseCategory(item) {
|
|||
1: 'Фильм',
|
||||
2: 'Сериал',
|
||||
6: 'Документальное',
|
||||
7: 'Телемагазин',
|
||||
8: 'Позновательное',
|
||||
10: 'Другое',
|
||||
14: 'ТВ-шоу',
|
||||
16: 'Досуг,Хобби',
|
||||
17: 'Ток-шоу',
|
||||
18: 'Юмористическое',
|
||||
23: 'Музыка',
|
||||
24: 'Развлекательное',
|
||||
25: 'Игровое',
|
||||
26: 'Новости'
|
||||
}
|
||||
|
||||
return categories[item.category_id] || null
|
||||
return categories[item.category_id]
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const json = JSON.parse(content)
|
||||
if (json.status !== 'OK') return []
|
||||
const event = json.schedule[0].event
|
||||
if (!Array.isArray(json.schedule) || !json.schedule[0]) return []
|
||||
const event = json.schedule[0].event || []
|
||||
|
||||
return [...event.past, ...event.current]
|
||||
}
|
||||
|
|
71
sites/tv.mail.ru/tv.mail.ru.test.js
Normal file
71
sites/tv.mail.ru/tv.mail.ru.test.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
// npx epg-grabber --config=sites/tv.mail.ru/tv.mail.ru.config.js --channels=sites/tv.mail.ru/tv.mail.ru_am.channels.xml --output=.gh-pages/guides/am/tv.mail.ru.epg.xml --days=2
|
||||
|
||||
const { parser, url, logo } = require('./tv.mail.ru.config.js')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2021-11-24', 'YYYY-MM-DD').startOf('d')
|
||||
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}]}}]}`
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://tv.mail.ru/ajax/channel/?region_id=70&channel_id=2785&date=2021-11-24'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid logo url', () => {
|
||||
expect(logo({ content })).toBe(
|
||||
'https://resizer.mail.ru/p/1234c5ac-c19c-5cf2-9c6a-fc0efca920ac/AAACwjJ45j9sTP8fcjPJnJ4xk5e_ILr5iXwjLMhWhzlVnIJkrtT42vEp9walcgpXRKDq9KFoliEPR0xI-LEh96C_izY.png'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const result = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2021-11-24T20:35:00.000Z',
|
||||
stop: '2021-11-24T22:40:00.000Z',
|
||||
title: `Նոնստոպ․ Տեսահոլովակներ`,
|
||||
category: 'Музыка'
|
||||
},
|
||||
{
|
||||
start: '2021-11-24T22:40:00.000Z',
|
||||
stop: '2021-11-24T23:40:00.000Z',
|
||||
title: `Վերջին թագավորությունը`,
|
||||
category: 'Сериал'
|
||||
},
|
||||
{
|
||||
start: '2021-11-24T23:40:00.000Z',
|
||||
stop: '2021-11-25T00:25:00.000Z',
|
||||
title: `Պրոֆեսիոնալները`,
|
||||
category: 'Позновательное'
|
||||
},
|
||||
{
|
||||
start: '2021-11-25T00:25:00.000Z',
|
||||
stop: '2021-11-25T01:25:00.000Z',
|
||||
title: `Նոնստոպ․ Տեսահոլովակներ`,
|
||||
category: 'Музыка'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
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":[]}}]}`
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue