Merge pull request #3183 from tohenk/fix-tv.mail.ru

Update tv.mail.ru Api guide and channels.
This commit is contained in:
Aleksandr Statciuk
2026-07-05 02:59:44 +03:00
committed by GitHub
11 changed files with 1540 additions and 863 deletions
-65
View File
@@ -1,65 +0,0 @@
{
"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
}
]
}
}
]
}
+8
View File
@@ -0,0 +1,8 @@
{
"data": {
"schedule": {
"items": [],
"has_next_page": true
}
}
}
+278
View File
@@ -0,0 +1,278 @@
{
"data": {
"schedule": {
"items": [
{
"id": 3161,
"name": "Мосфильм. Золотая коллекция",
"url": "/moskva/channel/3161/",
"logo_picture": {
"uuid": "68dc738d-986d-5247-b33e-f314113ef9cb",
"key": "AAACoQ27_vcIk20hmphmYeLcyCNxk32Ful-NTVWnqlCGhe6lDYifu2DKVm7CE5ewfsEYS3_UEZFsAm-yCDKmIJa_nPc",
"width": 128,
"height": 128,
"source": {
"id": 1,
"title": "",
"url": ""
},
"params": {
"dpr": [200],
"scale": true
},
"fmt": [
"png"
],
"title": "",
"error": "NO_ERROR",
"baseURL": "https://resizer.mail.ru/p/"
},
"has_live": false,
"events": [
{
"id": 277466571,
"url": "/moskva/event/599772/?event_id=277466571",
"name": "Однажды утром",
"start": "07:05",
"start_ts": 1781755500,
"stop_ts": 1781756100,
"image": "https://tv.mail.ru/tvpic/2/12/8563361.jpg",
"category_id": 20
},
{
"id": 277466579,
"url": "/moskva/event/735402/?event_id=277466579",
"name": "Русалочка",
"start": "07:15",
"start_ts": 1781756100,
"stop_ts": 1781757900,
"image": "https://tv.mail.ru/tvpic/4/04/8917067.jpg",
"category_id": 20
},
{
"id": 277182138,
"url": "/moskva/event/329965/?event_id=277182138",
"name": "Заколдованный мальчик",
"start": "07:30",
"start_ts": 1781757000,
"stop_ts": 1781760300,
"image": "https://tv.mail.ru/tvpic/6/65/651001.jpg",
"category_id": 20
},
{
"id": 277466575,
"url": "/moskva/event/768968/?event_id=277466575",
"name": "Сказка о Золотом Петушке",
"start": "07:45",
"start_ts": 1781757900,
"stop_ts": 1781760300,
"image": "https://tv.mail.ru/tvpic/8/15/083970.jpg",
"category_id": 20
},
{
"id": 277182152,
"url": "/moskva/event/245237/?event_id=277182152",
"name": "Двенадцать месяцев",
"start": "08:25",
"start_ts": 1781760300,
"stop_ts": 1781763900,
"image": "https://tv.mail.ru/tvpic/6/21/138367.jpg",
"category_id": 20
},
{
"id": 277182199,
"url": "/moskva/event/145968/?event_id=277182199",
"name": "Будьте моим мужем",
"start": "09:25",
"start_ts": 1781763900,
"stop_ts": 1781769600,
"image": "https://tv.mail.ru/tvpic/1/97/9152186.jpg",
"category_id": 1
},
{
"id": 277182131,
"url": "/moskva/event/171015/?event_id=277182131",
"name": "Вечный зов (На своей земле)",
"start": "11:00",
"start_ts": 1781769600,
"stop_ts": 1781774400,
"image": "https://tv.mail.ru/tvpic/4/03/8603506.jpg",
"category_id": 2
},
{
"id": 277182105,
"url": "/moskva/event/171015/?event_id=277182105",
"name": "Вечный зов (Испытание)",
"start": "12:15",
"start_ts": 1781774100,
"stop_ts": 1781778900,
"image": "https://tv.mail.ru/tvpic/4/03/8603506.jpg",
"category_id": 2
},
{
"id": 277466569,
"url": "/moskva/event/171015/?event_id=277466569",
"name": "Вечный зов (Испытание)",
"start": "12:20",
"start_ts": 1781774400,
"stop_ts": 1781778900,
"image": "https://tv.mail.ru/tvpic/4/03/8603506.jpg",
"category_id": 2
},
{
"id": 277182186,
"url": "/moskva/event/529366/?event_id=277182186",
"name": "Мужики!..",
"start": "13:35",
"start_ts": 1781778900,
"stop_ts": 1781785500,
"image": "https://tv.mail.ru/tvpic/1/99/8206300.jpg",
"category_id": 1
},
{
"id": 277182180,
"url": "/moskva/event/144472/?event_id=277182180",
"name": "Бриллиантовая рука",
"start": "15:20",
"start_ts": 1781785200,
"stop_ts": 1781791500,
"image": "https://tv.mail.ru/tvpic/2/06/2756727.jpg",
"category_id": 1
},
{
"id": 277466573,
"url": "/moskva/event/144472/?event_id=277466573",
"name": "Бриллиантовая рука",
"start": "15:25",
"start_ts": 1781785500,
"stop_ts": 1781792100,
"image": "https://tv.mail.ru/tvpic/2/06/2756727.jpg",
"category_id": 1
},
{
"id": 277182171,
"url": "/moskva/event/829566/?event_id=277182171",
"name": "Тайны следствия (Заказчик: Часть 1-я)",
"start": "17:05",
"start_ts": 1781791500,
"stop_ts": 1781794800,
"image": "https://tv.mail.ru/tvpic/1/29/6544072.jpg",
"category_id": 2
},
{
"id": 277466572,
"url": "/moskva/event/829566/?event_id=277466572",
"name": "Тайны следствия (Заказчик: Часть 1-я)",
"start": "17:15",
"start_ts": 1781792100,
"stop_ts": 1781798400,
"image": "https://tv.mail.ru/tvpic/1/29/6544072.jpg",
"category_id": 2
},
{
"id": 277182183,
"url": "/moskva/event/829566/?event_id=277182183",
"name": "Тайны следствия (Заказчик: Часть 2-я)",
"start": "18:00",
"start_ts": 1781794800,
"stop_ts": 1781798100,
"image": "https://tv.mail.ru/tvpic/1/29/6544072.jpg",
"category_id": 2
},
{
"id": 277466570,
"url": "/moskva/event/199929/?event_id=277466570",
"name": "Всадник по имени Смерть",
"start": "19:00",
"start_ts": 1781798400,
"stop_ts": 1781805600,
"image": "https://tv.mail.ru/tvpic/1/67/9640263.jpg",
"category_id": 1
},
{
"id": 277182143,
"url": "/moskva/event/124536/?event_id=277182143",
"name": "Белое солнце пустыни",
"start": "20:50",
"start_ts": 1781805000,
"stop_ts": 1781810700,
"image": "https://tv.mail.ru/tvpic/1/23/9959547.jpg",
"category_id": 1
},
{
"id": 277466580,
"url": "/moskva/event/124536/?event_id=277466580",
"name": "Белое солнце пустыни",
"start": "21:00",
"start_ts": 1781805600,
"stop_ts": 1781811000,
"image": "https://tv.mail.ru/tvpic/1/23/9959547.jpg",
"category_id": 1
},
{
"id": 277182094,
"url": "/moskva/event/322390/?event_id=277182094",
"name": "За спичками",
"start": "22:25",
"start_ts": 1781810700,
"stop_ts": 1781817300,
"image": "https://tv.mail.ru/tvpic/1/41/0358818.jpg",
"category_id": 1
},
{
"id": 277466576,
"url": "/moskva/event/322390/?event_id=277466576",
"name": "За спичками",
"start": "22:30",
"start_ts": 1781811000,
"stop_ts": 1781817600,
"image": "https://tv.mail.ru/tvpic/1/41/0358818.jpg",
"category_id": 1
},
{
"id": 277182151,
"url": "/moskva/event/851623/?event_id=277182151",
"name": "Тот самый Мюнхгаузен",
"start": "00:15",
"start_ts": 1781817300,
"stop_ts": 1781825700,
"image": "https://tv.mail.ru/tvpic/2/40/1296158.jpg",
"category_id": 1
},
{
"id": 277466574,
"url": "/moskva/event/851623/?event_id=277466574",
"name": "Тот самый Мюнхгаузен",
"start": "00:20",
"start_ts": 1781817600,
"stop_ts": 1781826300,
"image": "https://tv.mail.ru/tvpic/2/40/1296158.jpg",
"category_id": 1
},
{
"id": 277466578,
"url": "/moskva/event/702859/?event_id=277466578",
"name": "Путешествие мсье Перришона",
"start": "02:45",
"start_ts": 1781826300,
"stop_ts": 1781830800,
"image": "https://tv.mail.ru/tvpic/2/71/6928921.jpg",
"category_id": 1
},
{
"id": 277466577,
"url": "/moskva/event/274206/?event_id=277466577",
"name": "Дни Турбиных",
"start": "04:00",
"start_ts": 1781830800,
"stop_ts": 1781840100,
"image": "https://tv.mail.ru/tvpic/2/08/690341.jpg",
"category_id": 1
}
]
}
],
"has_next_page": true
}
}
}
+238
View File
@@ -0,0 +1,238 @@
{
"data": {
"schedule": {
"items": [
{
"id": 3161,
"name": "Мосфильм. Золотая коллекция",
"url": "/moskva/channel/3161/",
"logo_picture": {
"uuid": "68dc738d-986d-5247-b33e-f314113ef9cb",
"key": "AAACoQ27_vcIk20hmphmYeLcyCNxk32Ful-NTVWnqlCGhe6lDYifu2DKVm7CE5ewfsEYS3_UEZFsAm-yCDKmIJa_nPc",
"width": 128,
"height": 128,
"source": {
"id": 1,
"title": "",
"url": ""
},
"params": {
"dpr": [200],
"scale": true
},
"fmt": [
"png"
],
"title": "",
"error": "NO_ERROR",
"baseURL": "https://resizer.mail.ru/p/"
},
"has_live": false,
"events": [
{
"id": 277465072,
"url": "/moskva/event/1086762/?event_id=277465072",
"name": "Братья Карамазовы (2-я серия)",
"start": "05:10",
"start_ts": 1781662200,
"stop_ts": 1781665500,
"image": "https://tv.mail.ru/tvpic/1/09/6080192.jpg",
"category_id": 2
},
{
"id": 277465083,
"url": "/moskva/event/1086762/?event_id=277465083",
"name": "Братья Карамазовы (3-я серия)",
"start": "06:05",
"start_ts": 1781665500,
"stop_ts": 1781668800,
"image": "https://tv.mail.ru/tvpic/1/09/6080192.jpg",
"category_id": 2
},
{
"id": 277465080,
"url": "/moskva/event/1086762/?event_id=277465080",
"name": "Братья Карамазовы (3-я серия)",
"start": "07:00",
"start_ts": 1781668800,
"stop_ts": 1781673900,
"image": "https://tv.mail.ru/tvpic/1/09/6080192.jpg",
"category_id": 2
},
{
"id": 277465081,
"url": "/moskva/event/329965/?event_id=277465081",
"name": "Заколдованный мальчик",
"start": "08:25",
"start_ts": 1781673900,
"stop_ts": 1781676900,
"image": "https://tv.mail.ru/tvpic/6/65/651001.jpg",
"category_id": 20
},
{
"id": 277182078,
"url": "/moskva/event/307742/?event_id=277182078",
"name": "Еще раз про любовь",
"start": "09:15",
"start_ts": 1781676900,
"stop_ts": 1781683200,
"image": "https://tv.mail.ru/tvpic/2/06/3511811.jpg",
"category_id": 1
},
{
"id": 277182191,
"url": "/moskva/event/171015/?event_id=277182191",
"name": "Вечный зов (В каменном мешке)",
"start": "11:00",
"start_ts": 1781683200,
"stop_ts": 1781687700,
"image": "https://tv.mail.ru/tvpic/4/03/8603506.jpg",
"category_id": 2
},
{
"id": 277182161,
"url": "/moskva/event/171015/?event_id=277182161",
"name": "Вечный зов (Возвращение)",
"start": "12:15",
"start_ts": 1781687700,
"stop_ts": 1781693100,
"image": "https://tv.mail.ru/tvpic/4/03/8603506.jpg",
"category_id": 2
},
{
"id": 277182197,
"url": "/moskva/event/730547/?event_id=277182197",
"name": "Родня",
"start": "13:45",
"start_ts": 1781693100,
"stop_ts": 1781699400,
"image": "https://tv.mail.ru/tvpic/2/74/9560704.jpg",
"category_id": 1
},
{
"id": 277182177,
"url": "/moskva/event/124552/?event_id=277182177",
"name": "Белорусский вокзал",
"start": "15:30",
"start_ts": 1781699400,
"stop_ts": 1781706300,
"image": "https://tv.mail.ru/tvpic/2/98/1925676.jpg",
"category_id": 1
},
{
"id": 277465075,
"url": "/moskva/event/829566/?event_id=277465075",
"name": "Тайны следствия (Практикантка: Часть 1-я)",
"start": "17:25",
"start_ts": 1781706300,
"stop_ts": 1781709300,
"image": "https://tv.mail.ru/tvpic/1/29/6544072.jpg",
"category_id": 2
},
{
"id": 277465074,
"url": "/moskva/event/829566/?event_id=277465074",
"name": "Тайны следствия (Практикантка: Часть 2-я)",
"start": "18:15",
"start_ts": 1781709300,
"stop_ts": 1781712300,
"image": "https://tv.mail.ru/tvpic/1/29/6544072.jpg",
"category_id": 2
},
{
"id": 277465073,
"url": "/moskva/event/165260/?event_id=277465073",
"name": "Верные друзья",
"start": "19:05",
"start_ts": 1781712300,
"stop_ts": 1781719200,
"image": "https://tv.mail.ru/tvpic/2/20/5467305.jpg",
"category_id": 1
},
{
"id": 277182195,
"url": "/moskva/event/247758/?event_id=277182195",
"name": "Девчата",
"start": "20:50",
"start_ts": 1781718600,
"stop_ts": 1781724900,
"image": "https://tv.mail.ru/tvpic/2/79/799077.jpg",
"category_id": 1
},
{
"id": 277465082,
"url": "/moskva/event/247758/?event_id=277465082",
"name": "Девчата",
"start": "21:00",
"start_ts": 1781719200,
"stop_ts": 1781725800,
"image": "https://tv.mail.ru/tvpic/2/79/799077.jpg",
"category_id": 1
},
{
"id": 277182107,
"url": "/moskva/event/247342/?event_id=277182107",
"name": "Девушка без адреса",
"start": "22:35",
"start_ts": 1781724900,
"stop_ts": 1781730900,
"image": "https://tv.mail.ru/tvpic/4/22/9200713.jpg",
"category_id": 1
},
{
"id": 277465079,
"url": "/moskva/event/247342/?event_id=277465079",
"name": "Девушка без адреса",
"start": "22:50",
"start_ts": 1781725800,
"stop_ts": 1781731800,
"image": "https://tv.mail.ru/tvpic/4/22/9200713.jpg",
"category_id": 1
},
{
"id": 277465078,
"url": "/moskva/event/107011/?event_id=277465078",
"name": "Артистка из Грибово",
"start": "00:30",
"start_ts": 1781731800,
"stop_ts": 1781740200,
"image": "https://tv.mail.ru/tvpic/1/61/9929675.jpg",
"category_id": 1
},
{
"id": 277465076,
"url": "/moskva/event/777111/?event_id=277465076",
"name": "Слезы капали",
"start": "02:50",
"start_ts": 1781740200,
"stop_ts": 1781745300,
"image": "https://tv.mail.ru/tvpic/3/72/8639450.jpg",
"category_id": 1
},
{
"id": 277182201,
"url": "/moskva/event/355430/?event_id=277182201",
"name": "Золотой теленок",
"start": "04:05",
"start_ts": 1781744700,
"stop_ts": 1781754900,
"image": "https://tv.mail.ru/tvpic/5/61/686247.jpg",
"category_id": 1
},
{
"id": 277465077,
"url": "/moskva/event/355430/?event_id=277465077",
"name": "Золотой теленок",
"start": "04:15",
"start_ts": 1781745300,
"stop_ts": 1781755500,
"image": "https://tv.mail.ru/tvpic/5/61/686247.jpg",
"category_id": 1
}
]
}
],
"has_next_page": true
}
}
}
-23
View File
@@ -1,23 +0,0 @@
{
"status":"OK",
"current_ts":1637788593,
"form":{
"values":[
]
},
"current_offset":10800,
"schedule":[
{
"channel":null,
"event":{
"current":[
],
"past":[
]
}
}
]
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
# tv.mail.ru
https://tv.mail.ru/
https://tv.mail.ru/moskva/
### Download the guide
File diff suppressed because it is too large Load Diff
+216 -97
View File
@@ -1,126 +1,245 @@
const axios = require('axios')
const cheerio = require('cheerio')
const crypto = require('crypto')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const axios = require('axios')
const uniqBy = require('lodash.uniqby')
const doFetch = require('@ntlab/sfetch')
dayjs.extend(utc)
dayjs.extend(timezone)
const eventIds = []
const caches = {}
const headers = {
'user-agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36',
}
module.exports = {
site: 'tv.mail.ru',
days: 2,
delay: 1000,
url({ channel, date }) {
return `https://tv.mail.ru/ajax/channel/?region_id=70&channel_id=${
channel.site_id
}&date=${date.format('YYYY-MM-DD')}`
request: {
cache: {
ttl: 24 * 60 * 60 * 1000 // 1 day
},
headers
},
parser({ content, date }) {
async url({ date }) {
return await followUrl(getUrl(date))
},
async parser({ content, channel, date }) {
const programs = []
const items = parseItems(content)
items.forEach(item => {
const prev = programs[programs.length - 1]
let start = parseStart(item, date)
if (prev) {
if (start < prev.start) {
start = start.add(1, 'day')
date = date.add(1, 'day')
if (content) {
// common utility
const v = { e: [], d: date, p: 1 }
const ev = (res, url) => {
if (typeof res === 'string' || Buffer.isBuffer(res)) {
res = JSON.parse(res)
}
if (Array.isArray(res?.data?.schedule?.items)) {
res.data.schedule.items
.filter(schedule => schedule.id == channel.site_id)
.forEach(schedule => {
if (Array.isArray(schedule.events)) {
schedule.events
.filter(event => !eventIds.includes(event.id))
.forEach(event => {
// use event id as unique filter
if (!v.e.find(item => item.id === event.id)) {
v.e.push(event)
}
})
}
})
// cache result
if (url) {
caches[url] = res
}
}
prev.stop = start
}
const stop = start.add(1, 'hour')
programs.push({
title: item.name,
category: parseCategory(item),
start,
stop
const mu = (next = true, dt = null) => {
return getUrl(dt ? dt : v.d, next ? ++v.p : v.p)
}
const mq = oUrl => ({
async url(queue) {
return await followUrl(queue.oUrl)
},
oUrl,
params: module.exports.request
})
})
const cr = async (next = true, dt = null) => {
const oUrl = mu(next, dt)
if (caches[oUrl]) {
ev(caches[oUrl])
} else {
await doFetch([mq(oUrl)], (queue, res) => {
ev(res, queue.oUrl)
})
}
}
// add main content
ev(content)
// fetch next page until site is found
await new Promise(resolve => {
const f = async () => {
if (v.e.length) {
resolve()
} else {
await cr()
f()
}
}
f()
})
if (v.e.length) {
date = date.startOf('d')
v.n = [...v.e]
v.e = []
// fetch previous day
await cr(false, date.subtract(1, 'd'))
v.e.push(...v.n)
// process collected events
const queues = []
const events = []
v.e
.forEach(event => {
const start = dayjs.utc(event.start_ts * 1000)
const stop = dayjs.utc(event.stop_ts * 1000)
if (date.isSame(start, 'd') || (date.isSame(stop, 'd') && stop > date)) {
eventIds.push(event.id)
const url = `https://tv.mail.ru${event.url}`
const evt = {
program: {
title: event.name,
image: event.image,
start,
stop
}
}
if (caches[url]) {
evt.detail = caches[url]
} else {
queues.push({
async url(queue) {
return await followUrl(queue.oUrl)
},
oUrl: url,
params: module.exports.request,
evt
})
}
events.push(evt)
}
})
// fetch detailed programs
if (process.env.EPG_DETAILED_GUIDE) {
await doFetch(queues, (queue, res) => {
queue.evt.detail = res
caches[queue.oUrl] = res
})
}
// add programs
programs.push(...events
.map(evt => ({
...evt.program,
...parseProgram(evt.detail)
})
)
)
}
}
return programs
},
async channels() {
const regions = [5506, 1096, 1125, 285]
let channels = []
for (let region of regions) {
const totalPages = await getTotalPageCount(region)
const pages = Array.from(Array(totalPages).keys())
for (let page of pages) {
const data = await axios
.get('https://tv.mail.ru/ajax/channel/list/', {
params: { page },
headers: {
cookie: `s=fver=0|geo=${region};`
}
})
.then(r => r.data)
.catch(console.log)
data.channels.forEach(item => {
channels.push({
const channels = []
const args = { date: dayjs(), page: 0 }
const queues = [getUrl(args.date, ++args.page)]
await doFetch(queues, (url, res) => {
if (res?.data?.schedule?.has_next_page) {
queues.push(getUrl(args.date, ++args.page))
}
if (Array.isArray(res?.data?.schedule?.items)) {
channels.push(...res.data.schedule.items
.map(item => ({
lang: 'ru',
name: item.name,
site_id: item.id
})
})
}
}
return uniqBy(channels, 'site_id')
}
}
async function getTotalPageCount(region) {
const data = await axios
.get('https://tv.mail.ru/ajax/channel/list/', {
params: { page: 0 },
headers: {
cookie: `s=fver=0|geo=${region};`
}))
)
}
})
.then(r => r.data)
.catch(console.log)
return data.total
return channels
}
}
function parseStart(item, date) {
const dateString = `${date.format('YYYY-MM-DD')} ${item.start}`
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Europe/Moscow').utc()
}
function parseCategory(item) {
const categories = {
1: 'Фильм',
2: 'Сериал',
6: 'Документальное',
7: 'Телемагазин',
8: 'Позновательное',
10: 'Другое',
14: 'ТВ-шоу',
16: 'Досуг,Хобби',
17: 'Ток-шоу',
18: 'Юмористическое',
23: 'Музыка',
24: 'Развлекательное',
25: 'Игровое',
26: 'Новости'
function parseProgram(data) {
const res = {}
if (data) {
const props = {
title: '.fa7d86047b [data-qa="Title"]',
sub_title: '.d4a57e7163',
category: '[data-qa="TagLink"] [data-qa="Text"]',
description: ['.f9cbc7a035', 'h2'],
actor: '[data-qa*="TEST_IDS__EVENT_ATTR__actors_link_"]',
director: '[data-qa*="TEST_IDS__EVENT_ATTR__director_link_"]',
date: '[data-qa="TEST_IDS__TEVENT_META__start_year"]',
country: '.ec1bc00977'
}
const $ = cheerio.load(data)
for (const [prop, selector] of Object.entries(props)) {
const item = $(Array.isArray(selector) ? selector[0] : selector)
if (item.length) {
// prune children
if (Array.isArray(selector)) {
item.find(selector[1]).remove()
}
if (item.length > 1) {
res[prop] = item.toArray()
.map(item => $(item).text().trim())
} else {
res[prop] = item.text().trim()
}
}
}
}
return categories[item.category_id]
? {
lang: 'ru',
value: categories[item.category_id]
}
: null
return res
}
function parseItems(content) {
const json = JSON.parse(content)
if (!Array.isArray(json.schedule) || !json.schedule[0]) return []
const event = json.schedule[0].event || []
return [...event.past, ...event.current]
function getUrl(date, page = 1) {
page = page > 1 ? `&page=${page}` : ''
return `https://tv.mail.ru/ajax/service/index/schedule/?region_id=70&channel_type=all&date=${
date.format('YYYY-MM-DD')
}&appearance=grid&period=all${
page
}`
}
async function followUrl(url) {
const f = async (m = 'head') => {
await axios[m](url, { headers })
.then(res => {
if (res.headers && res.headers['x-challenge'] === 'required') {
const challengeUrl = new URL(res.request.res.responseUrl)
if (challengeUrl.searchParams.has('hash429')) {
const key = crypto.hash('md5', challengeUrl.searchParams.get('hash429'))
if (challengeUrl.searchParams.has('key')) {
challengeUrl.searchParams.set('key', key)
} else {
challengeUrl.searchParams.append('key', key)
}
url = challengeUrl.toString()
} else {
throw new Error('Unknown challenge page!')
}
}
})
// @todo: handle captcha on 429
.catch(console.error)
return url
}
return await f()
}
+68 -54
View File
@@ -1,77 +1,91 @@
const { parser, url } = require('./tv.mail.ru.config.js')
const axios = require('axios')
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)
process.env.EPG_DETAILED_GUIDE = 1
const date = dayjs.utc('2021-11-24', 'YYYY-MM-DD').startOf('d')
jest.mock('axios')
const date = dayjs.utc('2026-06-18').startOf('d')
const channel = {
site_id: '2785',
xmltv_id: '21TV.am'
site_id: '3161',
xmltv_id: 'MosfilmGoldCollection.ru@SD'
}
const content = fs.readFileSync(path.join(__dirname, '__data__', 'content.json'), 'utf8')
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'
axios.head.mockImplementation(() => Promise.resolve({}))
axios.get.mockImplementation(url => {
const urls = {
'https://tv.mail.ru/ajax/service/index/schedule/?region_id=70&channel_type=all&date=2026-06-18&appearance=grid&period=all':
'content1.json',
'https://tv.mail.ru/ajax/service/index/schedule/?region_id=70&channel_type=all&date=2026-06-18&appearance=grid&period=all&page=2':
'content2.json',
'https://tv.mail.ru/ajax/service/index/schedule/?region_id=70&channel_type=all&date=2026-06-17&appearance=grid&period=all&page=2':
'content2a.json',
'https://tv.mail.ru/moskva/event/777111/?event_id=277465076':
'program1.html',
'https://tv.mail.ru/moskva/event/702859/?event_id=277466578':
'program2.html'
}
let data = ''
if (urls[url] !== undefined) {
data = fs.readFileSync(path.join(__dirname, '__data__', urls[url])).toString()
}
return Promise.resolve({ data })
})
it('can generate valid url', async () => {
expect(await url({ date })).toBe(
'https://tv.mail.ru/ajax/service/index/schedule/?region_id=70&channel_type=all&date=2026-06-18&appearance=grid&period=all'
)
})
it('can parse response', () => {
const result = parser({ content, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
it('can parse response', async () => {
const content = fs.readFileSync(path.join(__dirname, '__data__', 'content1.json'))
const result = (await parser({ content, channel, 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: {
lang: 'ru',
value: 'Музыка'
}
},
{
start: '2021-11-24T22:40:00.000Z',
stop: '2021-11-24T23:40:00.000Z',
title: 'Վերջին թագավորությունը',
category: {
lang: 'ru',
value: 'Сериал'
}
},
{
start: '2021-11-24T23:40:00.000Z',
stop: '2021-11-25T00:25:00.000Z',
title: 'Պրոֆեսիոնալները',
category: {
lang: 'ru',
value: 'Позновательное'
}
},
{
start: '2021-11-25T00:25:00.000Z',
stop: '2021-11-25T01:25:00.000Z',
title: 'Նոնստոպ․ Տեսահոլովակներ',
category: {
lang: 'ru',
value: 'Музыка'
}
}
])
expect(result.length).toBe(26)
expect(result[0]).toMatchObject({
start: '2026-06-17T23:50:00.000Z',
stop: '2026-06-18T01:15:00.000Z',
title: 'Слезы капали',
description:
'Узнаем, что же случилось с Павлом Ивановичем Васиным, жителем городка Зареченска. Любящий муж и отец, отзывчивый сосед и сослуживец, словом, душа-человек в один прекрасный день превратился в недовольного всем чинушу и формалиста. А все из-за того, что ему в глаз попал осколок волшебного зеркала…',
category: 'драма',
country: 'СССР',
date: '1982',
image: 'https://tv.mail.ru/tvpic/3/72/8639450.jpg'
})
expect(result[25]).toMatchObject({
start: '2026-06-18T23:45:00.000Z',
stop: '2026-06-19T01:00:00.000Z',
title: 'Путешествие мсье Перришона',
description:
'Музыкальная комедия по пьесе французского драматурга Эжена Лабиша. Двое молодых людей - Арман и Даниэль - влюбляются в дочь каретника Перришона. Девушка тоже пока не поняла, кто ей больше нравится. Она решила проверить их в деле: отправилась с ними в горы искать клад. Пусть в полевых условиях поухаживают. Вот тогда и станет ясно, кто из женихов больше достоин руки девушки…',
actor:
['Валентин Гафт', 'Олег Табаков', 'Татьяна Васильева', 'Георгиос Совчис', 'Игорь Скляр', 'Татьяна Догилева', 'Марина Зудина', 'Александр Филиппенко', 'Александр Мохов', 'Екатерина Васильева'],
director: 'Сергей Микаэлян',
country: 'СССР',
date: '1986',
image: 'https://tv.mail.ru/tvpic/2/71/6928921.jpg'
})
})
it('can handle empty guide', () => {
const result = parser({
it('can handle empty guide', async () => {
const result = await parser({
date,
channel,
content: fs.readFileSync(path.join(__dirname, '__data__', 'no_content.json'), 'utf8')
content: ''
})
expect(result).toMatchObject([])
})