Merge pull request #2792 from shayypy/master

Add ctc.ru
This commit is contained in:
PopeyeTheSai10r authored and GitHub committed 2025-06-24 18:40:21 -07:00
commit 9535c245db
5 files changed
+206

No files matched your search

+1
View File
@@ -0,0 +1 @@
{"isActive":true,"url":"\/programm\/","header":[{"id":261,"widgets":[{"id":814220,"widgets":[],"anchorLink":null,"title":"\u0421\u0435\u0439\u0447\u0430\u0441 \u0438\u0449\u0443\u0442","items":[{"title":"\u0421\u0443\u043f\u0435\u0440\u043d\u0438\u043d\u0434\u0437\u044f. \u0414\u0435\u0442\u0438","link":"https:\/\/ctc.ru\/projects\/show\/supernindzya-deti\/?utm_source=ctc\u0026utm_medium=cross-promo\u0026utm_campaign=supernindzyadeti\u0026utm_content=hint","projectHubId":null},{"title":"\u0420\u043e\u0434\u043a\u043e\u043c","link":"https:\/\/ctc.ru\/projects\/serials\/rodkom\/?utm_source=ctc\u0026utm_medium=cross-promo\u0026utm_campaign=rodkom\u0026utm_content=hint","projectHubId":null},{"title":"\u041c\u043e\u043b\u043e\u0434\u0451\u0436\u043a\u0430","link":"https:\/\/ctc.ru\/projects\/serials\/molodezhka\/?utm_source=ctc\u0026utm_medium=cross-promo\u0026utm_campaign=molodezhka\u0026utm_content=hint","projectHubId":null},{"title":"\u041c\u043e\u043b\u043e\u0434\u0451\u0436\u043a\u0430. \u041d\u043e\u0432\u0430\u044f \u0441\u043c\u0435\u043d\u0430","link":"https:\/\/ctc.ru\/projects\/serials\/molodezhka-novaya-smena\/?utm_source=ctc\u0026utm_medium=cross-promo\u0026utm_campaign=molodezhkanovayasmena\u0026utm_content=hint","projectHubId":null},{"title":"\u0412\u043e\u0440\u043e\u043d\u0438\u043d\u044b","link":"https:\/\/ctc.ru\/projects\/serials\/voroniny\/?utm_source=ctc\u0026utm_medium=cross-promo\u0026utm_campaign=voroniny\u0026utm_content=hint","projectHubId":null},{"title":"\u041a\u0443\u0445\u043d\u044f","link":"https:\/\/ctc.ru\/projects\/serials\/kukhnya\/?utm_source=ctc\u0026utm_medium=cross-promo\u0026utm_campaign=kukhnya\u0026utm_content=hint","projectHubId":null},{"title":"\u0412\u043e\u0441\u044c\u043c\u0438\u0434\u0435\u0441\u044f\u0442\u044b\u0435","link":"https:\/\/ctc.ru\/projects\/serials\/vosmidesyatye\/?utm_source=ctc\u0026utm_medium=cross-promo\u0026utm_campaign=vosmidesyatye\u0026utm_content=hint","projectHubId":null},{"title":"\u0411\u043e\u0433\u0430\u0442\u044b\u0440\u0441\u043a\u0438\u0435 \u0438\u0433\u0440\u044b","link":"https:\/\/ctc.ru\/projects\/show\/bogatyrskie-igry\/?utm_source=ctc\u0026utm_medium=cross-promo\u0026utm_campaign=bogatyrskieigry\u0026utm_content=hint","projectHubId":null},{"title":"\u0412 \u0442\u0435\u043c\u043d\u043e\u0442\u0435","link":"https:\/\/ctc.ru\/projects\/show\/v-temnote\/?utm_source=ctc\u0026utm_medium=cross-promo\u0026utm_campaign=vtemnote\u0026utm_content=hint","projectHubId":null},{"title":"\u041a\u0442\u043e \u0442\u0443\u0442 \u0436\u0443\u043b\u0438\u043a?","link":"https:\/\/ctc.ru\/projects\/show\/kto-tut-zhulik\/?utm_source=ctc\u0026utm_medium=cross-promo\u0026utm_campaign=ktotutzhulik\u0026utm_content=hint","projectHubId":null}],"type":"search-prompt"},{"id":668677,"widgets":[{"id":860061,"widgets":[],"anchorLink":"","title":"\u0418\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440 \u0413\u0430\u0432\u0440\u0438\u043b\u043e\u0432","projectVerticalCoverUrl":[{"url":"https:\/\/mgf-static-ssl.ctc.ru\/images\/ctc-entity-project\/19250\/verticalcover\/web\/67d941e12503f-90x127.jpeg","width":90,"height":127},{"url":"https:\/\/mgf-static-ssl.ctc.ru\/images\/ctc-entity-project\/19250\/verticalcover\/web\/67d941e148699-175x248.jpeg","width":175,"height":248},{"url":"https:\/\/mgf-static-ssl.ctc.ru\/images\/ctc-entity-project\/19250\/verticalcover\/web\/67d941e162311-250x355.jpeg","width":250,"height":355},{"url":"https:\/\/mgf-static-ssl.ctc.ru\/images\/ctc-entity-project\/19250\/verticalcover\/web\/67d941e179a46-350x497.jpeg","width":350,"height":497},{"url":"https:\/\/mgf-static-ssl.ctc.ru\/images\/ctc-entity-project\/19250\/verticalcover\/web\/67d941e1ab6bd-490x696.jpeg","width":490,"height":696}],"projectPageUrl":"/projects/serials/inspektor-gavrilov/","hasTrack":true,"isActiveWidget":true,"projectHubId":1519800,"badge":null,"type":"content-project-vertical-editable"},{"id":860065,"widgets":[],"anchorLink":"","title":"\u0413\u0440\u0430\u043d\u0438\u0446\u0430 \u043c\u0438\u0440\u043e\u0432","projectVerticalCoverUrl":[{"url":"https:\/\/mgf-static-ssl.ctc.ru\/images\/ctc-entity-project\/19797\/verticalcover\/web\/67b448d8acc8e-90x127.jpeg","width":90,"height":127},{"url":"https:\/\/mgf-static-ssl.ctc.ru\/images\/ctc-entity-project\/19797\/verticalcover\/web\/67b448d8c17e7-175x248.jpeg","width":175,"height":248},{"url":"https:\/\/mgf-static-ssl.ctc.ru\/images\/ctc-entity-project\/19797\/verticalcover\/web\/67b448d8d5011-250x355.jpeg","width":250,"height":355},{"url":"https:\/\/mgf-static-ssl.ctc.ru\/images\/ctc-entity-project\/19797\/verticalcover\/web\/67b448d90b83e-350x497.jpeg","width":350,"height":497},{"url":"https:\/\/mgf-static-ssl.ctc.ru\/images\/ctc-entity-project\/19797\/verticalcover\/web\/67b448d938789-490x696.jpeg","width":490,"height":696}],"projectPageUrl":"/projects/serials/granitsa-mirov/","hasTrack":true,"isActiveWidget":true,"projectHubId":1525624,"badge":null,"type":"content-project-vertical-editable"},{"id":860067,"widgets":[]Line truncated
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<channels>
<channel site="ctc.ru" lang="ru" xmltv_id="STS.ru" site_id="ctc">STS</channel>
</channels>
+95
View File
@@ -0,0 +1,95 @@
const dayjs = require('dayjs')
module.exports = {
site: 'ctc.ru',
days: 1,
url: ({ date }) => `https://ctc.ru/api/page/v2/programm/?date=${formatDate(date)}`,
parser({ content }) {
const programs = []
const items = parseItems(content)
for (const item of items) {
programs.push({
title: item.bubbleTitle,
// more like "films", "shows", "cartoons" - not a genre
category: item.bubbleSubTitle,
icons: parseIcons(item),
images: parseImages(item),
start: parseStart(item),
stop: parseStop(item),
// not sure if CTC uses this more like `premiere` but I don't have any
// additional info to use in the `premiere` field so I'm using this
// instead.
new: item.isPremiere ?? false,
url: item.bubbleUrl ? `https://ctc.ru${item.bubbleUrl}` : undefined,
rating: parseRating(item),
})
}
return programs
}
}
function formatDate(date) {
return dayjs(date).format('DD-MM-YYYY')
}
function parseIcons(item) {
const images = item.bubbleImage ?? []
// biggest first
const sorted = images.sort((a, b) => b.height - a.height)
return sorted.map((image) => ({
src: image.url,
width: image.width,
height: image.height,
}))
}
function parseImages(item) {
const images = item.trackImageUrl ?? []
// biggest first
const sorted = images.sort((a, b) => b.height - a.height)
// compile one image of each size since the content should be the same
const sizes = {}
for (const image of sorted) {
const maxRes = Math.max(image.width, image.height)
const item = {
type: 'backdrop',
// https://github.com/ektotv/xmltv/blob/801417b4b7aae38f13caa82d8bbfbed0a254ee5f/src/types.ts#L40-L48
size: maxRes > 400 ? '3' : maxRes > 200 ? '2' : '1',
orient: image.height > image.width ? 'P' : 'L',
value: image.url,
}
if (sizes[item.size]) continue
sizes[item.size] = item
}
// re-sort so the size 3 images are first
return Object
.values(sizes)
.sort((a, b) => Number(b.size) - Number(a.size))
}
function parseStart(item) {
return dayjs(item.startTime)
}
function parseStop(item) {
return dayjs(item.endTime)
}
function parseRating(item) {
if (item.ageLimit == null) return null
return {
// Not sure what the Russian system is actually called (if anything)
system: 'Russia',
value: `${item.ageLimit}+`,
}
}
function parseItems(content) {
const node = JSON.parse(content).content.find(n => n.type === 'tv-program')
if (node) return node.widgets
return []
}
+91
View File
@@ -0,0 +1,91 @@
const { parser, url } = require('./ctc.ru.config.js')
const fs = require('fs')
const path = require('path')
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('2025-06-22')
it('can generate valid url', () => {
expect(url({ date })).toBe('https://ctc.ru/api/page/v2/programm/?date=22-06-2025')
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
let results = parser({ content, date })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
start: '2025-06-22T03:00:00.000Z',
stop: '2025-06-22T03:55:00.000Z',
title: 'Три кота',
category: 'Мультфильмы',
new: false,
url: 'https://ctc.ru/collections/multiki/',
icons: [
{
src: 'https://mgf-static-ssl.ctc.ru/images/ctc-entity-dictionary-category/5/iconurl/web/5f9027fcba9ac-125x125.png',
width: 125,
height: 125,
},
{
src: 'https://mgf-static-ssl.ctc.ru/images/ctc-entity-dictionary-category/5/iconurl/web/5f9027fc99587-60x60.png',
width: 60,
height: 60,
},
],
images: [
{
type: 'backdrop',
size: '3',
orient: 'L',
value: 'https://mgf-static-ssl.ctc.ru/images/ctc-entity-project/1129/horizontalcover/web/66c319f0a31b5-1740x978.jpeg',
},
{
type: 'backdrop',
size: '2',
orient: 'L',
value: 'https://mgf-static-ssl.ctc.ru/images/ctc-entity-project/1129/horizontalcover/web/66c319f20bac2-400x225.jpeg',
},
{
type: 'backdrop',
size: '1',
orient: 'L',
value: 'https://mgf-static-ssl.ctc.ru/images/ctc-entity-project/1129/horizontalcover/web/66c319f244f92-150x84.jpeg',
},
],
rating: {
system: 'Russia',
value: '0+',
},
})
})
it('can handle empty guide', () => {
const results = parser({
content: JSON.stringify({
isActive: true,
url: '/programm/',
header: [],
sidebar: [],
footer: [],
content: [],
seoTags: {},
ogMarkup: {},
userGeo: null,
userData: null,
meta: {},
activeFrom: null,
activeTo: null,
type: 'tv-program-page',
})
})
expect(results).toMatchObject([])
})
+15
View File
@@ -0,0 +1,15 @@
# ctc.ru
https://ctc.ru/programm
### Download the guide
```sh
npm run grab --- --site=ctc.ru
```
### Test
```sh
npm test --- ctc.ru
```