diff --git a/sites/dsmart.com.tr/dsmart.com.tr.channels.xml b/sites/dsmart.com.tr/dsmart.com.tr.channels.xml index 81420dd5..e0cc7b8d 100644 --- a/sites/dsmart.com.tr/dsmart.com.tr.channels.xml +++ b/sites/dsmart.com.tr/dsmart.com.tr.channels.xml @@ -1,109 +1,207 @@ - A News - Baby TV Europe - BBC World News Europe - CNN International Europe - FashionTV HD Europe - NBA TV - Trace Urban - 24 Kitchen Türkiye - 24 TV - 360 - A Haber - A Spor - ATV Türkiye - BBC Earth Türkiye - BBN Türk - Beyaz TV - Bloomberg HT - Boomerang Türkiye - Cartoon Network Türkiye - CNN Türk - Çocuk Smart - Da Vinci - Discovery Channel Türkiye - Discovery Science Türkiye - Disney Channel Türkiye - Diyanet TV - DiziSmart Max - DiziSmart Premium - DMAX Türkiye - DocuBox HD - Euro D - Eurosport 1 - Eurosport 2 - Fast & FunBox HD - FB TV - FightBox HD - FilmBox Türkiye - Flash TV - Fox Crime Türkiye - Fox Türkiye - FX Türkiye - Haber Global - Habertürk - Halk TV - Insight HD - Kanal 7 - Kanal D - Lider TV - Love Nature - MovieSmart Classic - MovieSmart Premium - MovieSmart Premium 2 - MovieSmart Türk - National Geographic Türkiye - National Geographic Wild Türkiye - NTV - Number 1 Türk - Number 1 TV - Power TV - Show TV - Sinema 1001 - Sinema 1002 - Sinema 2 - Sinema Aile - Sinema Aile 2 - Sinema Aksiyon - Sinema Aksiyon 2 - Sinema Komedi - Sinema Komedi 2 - Sinema TV - Spor Smart - Spor Smart 2 - S Sport - S Sport 2 - Star TV - Stingray Naturescape - TAY TV - Tele 1 - Teve 2 - TGRT Haber - TLC Türkiye - TMB - TRT 1 - TRT 2 - TRT 3 - TRT 4K - TRT Avaz - TRT Belgesel - TRT Çocuk - TRT Haber - TRT Kurdî - TRT Müzik - TRT Spor - TRT Spor Yildiz - TRT Türk - TV 100 - TV 4 - TV 8 - TV 8.5 - TV Net - UçanKus TV - Ülke TV - Vav TV - Viasat History HD + a News + Baby TV + BBC World News + CNN International + Fashion TV + NBA TV + Trace Urban + 24Kitchen + 24 + 360 + a Haber + a Spor + ATV + BBC Earth + BBN Türk + Beyaz TV + Bloomberg HT + Boomerang + Cartoon Network + CNN Türk SD + Çocuk Smart + Da Vinci Learning + Discovery + Discovery Science + Disney Channel + Diyanet Tv + Dizi Smart Max + Dizi Smart Premium + DMAX + DocuBox + Euro D + Eurosport + Eurosport 2 + Fast & Fun + FB TV + FightBox + FilmBox + Flash Haber + FOXCRIME + FOX + FX + Haber Global + Haber Türk + Halk TV + Insight TV + Kanal 7 + Kanal D + Lider Tv + Love Nature + MovieSmart Classic + MovieSmart Premium + MovieSmart Premium 2 + MovieSmart Türk + National Geographic + National Geographic WILD + NTV + NR1 Türk + NR1 + Power TV + Show TV + Sinema TV 1001 + Sinema TV 1002 + Sinema TV 2 + Sinema TV Aile + Sinema TV Aile 2 + Sinema TV Aksiyon + Sinema TV Aksiyon 2 + Sinema TV Comedy + Sinema TV Comedy 2 + Sinema TV + Spor Smart + SPOR SMART 2 + S Sport + S Sport 2 + Star + Nature Escape + TAY TV + Tele 1 + teve2 + TGRT Haber + TLC + TMB + TRT 1 + trt 2 + TRT 3 Spor + TRT 4K + TRT Avaz + TRT Belgesel + TRT Çocuk + TRT Haber + TRT Kurdi + TRT Müzik + TRT Spor + Trt Spor Yıldız + TRT Türk + Tv 100 + TV4 + TV8 + TV 8,5 + TV Net + Uçankuş TV + Ülke TV + Vav Tv + Viasat History + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sites/dsmart.com.tr/dsmart.com.tr.config.js b/sites/dsmart.com.tr/dsmart.com.tr.config.js index 8c237e0b..353aa561 100644 --- a/sites/dsmart.com.tr/dsmart.com.tr.config.js +++ b/sites/dsmart.com.tr/dsmart.com.tr.config.js @@ -1,3 +1,4 @@ +const axios = require('axios') const dayjs = require('dayjs') const utc = require('dayjs/plugin/utc') const customParseFormat = require('dayjs/plugin/customParseFormat') @@ -5,18 +6,15 @@ const customParseFormat = require('dayjs/plugin/customParseFormat') dayjs.extend(utc) dayjs.extend(customParseFormat) +const API_ENDPOINT = 'https://www.dsmart.com.tr/api/v1/public/epg/schedules' + module.exports = { site: 'dsmart.com.tr', days: 2, - request: { - cache: { - ttl: 60 * 1000 // 60 seconds response cache - } - }, url({ date, channel }) { - return `https://www.dsmart.com.tr/api/v1/public/epg/schedules?page=1&limit=500&day=${date.format( - 'YYYY-MM-DD' - )}` + const [page] = channel.site_id.split('#') + + return `${API_ENDPOINT}?page=${page}&limit=1&day=${date.format('YYYY-MM-DD')}` }, parser: function ({ content, channel }) { let offset = -1 @@ -35,7 +33,7 @@ module.exports = { programs.push({ title: item.program_name, - category: item.genre, + category: parseCategory(item), description: item.description.trim(), start, stop @@ -43,9 +41,48 @@ module.exports = { }) return programs + }, + async channels() { + const perPage = 1 + const totalChannels = 210 + const pages = Math.ceil(totalChannels / perPage) + + const channels = [] + for (let i in Array(pages).fill(0)) { + const page = parseInt(i) + 1 + const url = `${API_ENDPOINT}?page=${page}&limit=${perPage}&day=${dayjs().format( + 'YYYY-MM-DD' + )}` + let offset = i * perPage + await axios + .get(url) + .then(r => r.data) + .then(data => { + offset++ + if (data && data.data && Array.isArray(data.data.channels)) { + data.data.channels.forEach((item, j) => { + const index = offset + j + channels.push({ + lang: 'tr', + name: item.channel_name, + site_id: index + '#' + item._id + }) + }) + } + }) + .catch(err => { + console.log(err.message) + }) + } + + return channels } } +function parseCategory(item) { + return item.genre !== '0' ? item.genre : null +} + function parseStart(item, date) { const time = dayjs.utc(item.start_date) @@ -59,9 +96,10 @@ function parseDuration(item) { } function parseItems(content, channel) { + const [, channelId] = channel.site_id.split('#') const data = JSON.parse(content) if (!data || !data.data || !Array.isArray(data.data.channels)) return null - const channelData = data.data.channels.find(i => i._id == channel.site_id) + const channelData = data.data.channels.find(i => i._id == channelId) return channelData && Array.isArray(channelData.schedule) ? channelData.schedule : [] } diff --git a/sites/dsmart.com.tr/dsmart.com.tr.test.js b/sites/dsmart.com.tr/dsmart.com.tr.test.js index 04e1e0c7..34e1b067 100644 --- a/sites/dsmart.com.tr/dsmart.com.tr.test.js +++ b/sites/dsmart.com.tr/dsmart.com.tr.test.js @@ -1,3 +1,4 @@ +// npm run channels:parse -- --config=./sites/dsmart.com.tr/dsmart.com.tr.config.js --output=./sites/dsmart.com.tr/dsmart.com.tr.channels.xml // npx epg-grabber --config=sites/dsmart.com.tr/dsmart.com.tr.config.js --channels=sites/dsmart.com.tr/dsmart.com.tr.channels.xml --output=guide.xml --timeout=30000 --days=2 const { parser, url } = require('./dsmart.com.tr.config.js') @@ -11,13 +12,13 @@ dayjs.extend(utc) const date = dayjs.utc('2023-01-16', 'YYYY-MM-DD').startOf('d') const channel = { - site_id: '5fe07d7acfef0b1593275751', + site_id: '3#5fe07d7acfef0b1593275751', xmltv_id: 'SinemaTV.tr' } it('can generate valid url', () => { expect(url({ date, channel })).toBe( - 'https://www.dsmart.com.tr/api/v1/public/epg/schedules?page=1&limit=500&day=2023-01-16' + 'https://www.dsmart.com.tr/api/v1/public/epg/schedules?page=3&limit=1&day=2023-01-16' ) })