diff --git a/sites/osn.com/osn.com.config.js b/sites/osn.com/osn.com.config.js new file mode 100644 index 00000000..58b58c17 --- /dev/null +++ b/sites/osn.com/osn.com.config.js @@ -0,0 +1,70 @@ +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const timezone = require('dayjs/plugin/timezone') + +dayjs.extend(utc) +dayjs.extend(timezone) + +const tz = { + AE: 'Asia/Dubai' +} + +module.exports = { + site: 'osn.com', + request: { + method: 'POST', + data({ channel, date }) { + const [selectedCountry, channelCode] = channel.site_id.split('#') + return { + newDate: date.format('MM/DD/YYYY'), + selectedCountry, + channelCode, + isMobile: false, + hoursForMobile: 0 + } + } + }, + url: function () { + return `https://www.osn.com/CMSPages/TVScheduleWebService.asmx/GetTVChannelsProgramTimeTable` + }, + logo: function ({ channel }) { + const [_, channelCode] = channel.site_id.split('#') + + return `https://content.osn.com/logo/channel/cropped/${channelCode}.png` + }, + parser: function ({ content, channel }) { + let programs = [] + const items = parseItems(content) + items.forEach(item => { + const start = parseStart(item, channel) + const duration = parseDuration(item) + const stop = start.add(duration, 'm') + programs.push({ + title: item.Arab_Title, + category: item.GenreArabicName, + start: start.toString(), + stop: stop.toString() + }) + }) + + return programs + } +} + +function parseDuration(item) { + return parseInt(item.TotalDivWidth / 4.8) +} + +function parseStart(item, channel) { + const time = item.StartDateTime + const [selectedCountry] = channel.site_id.split('#') + + return dayjs.tz(time, 'DD MMM YYYY, HH:mm', tz[selectedCountry]) +} + +function parseItems(content) { + if (!content) return [] + const json = JSON.parse(content) + + return json.d ? JSON.parse(json.d) : [] +} diff --git a/sites/osn.com/osn.com.test.js b/sites/osn.com/osn.com.test.js new file mode 100644 index 00000000..dcdf2b78 --- /dev/null +++ b/sites/osn.com/osn.com.test.js @@ -0,0 +1,54 @@ +// npx epg-grabber --config=sites/osn.com/osn.com.config.js --channels=sites/osn.com/osn.com_ae.channels.xml --days=2 --output=guide.xml + +const { parser, url, logo, request } = require('./osn.com.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-10-24', 'YYYY-MM-DD').startOf('d') +const channel = { site_id: 'AE#AAN', xmltv_id: 'AlAanTV.ae' } +const content = JSON.stringify({ + d: '[{"IsPlaying":"0","Durationtime":null,"StartMinute":0,"EndMinute":0,"EmptyDivWidth":1152,"TotalDivWidth":576,"IsTodayDate":false,"IsLastRow":false,"StartDateTime":"24 Oct 2021, 22:00","EndDateTime":"\\/Date(-62135596800000)\\/","Title":"Al Aan TV","Arab_Title":"تلفزيون الآن","GenreEnglishName":null,"GenreArabicName":null,"ChannelNumber":140,"ChannelCode":"AAN","Duration":"\\/Date(-62135596800000)\\/","Showtime":"\\/Date(-62135596800000)\\/","EpisodeId":738257,"ProgramType":null,"EPGUNIQID":"AAN202110271800738257"}]' +}) + +it('can generate valid request data', () => { + const result = request.data({ channel, date }) + expect(result).toMatchObject({ + newDate: '10/24/2021', + selectedCountry: 'AE', + channelCode: 'AAN', + isMobile: false, + hoursForMobile: 0 + }) +}) + +it('can generate valid url', () => { + const result = url() + expect(result).toBe( + 'https://www.osn.com/CMSPages/TVScheduleWebService.asmx/GetTVChannelsProgramTimeTable' + ) +}) + +it('can get logo url', () => { + const result = logo({ channel }) + expect(result).toBe('https://content.osn.com/logo/channel/cropped/AAN.png') +}) + +it('can parse response', () => { + const result = parser({ date, channel, content }) + expect(result).toMatchObject([ + { + start: 'Sun, 24 Oct 2021 18:00:00 GMT', + stop: 'Sun, 24 Oct 2021 20:00:00 GMT', + title: 'تلفزيون الآن', + category: null + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ date, channel, content: JSON.stringify({ d: '[]' }) }) + expect(result).toMatchObject([]) +}) diff --git a/sites/osn.com/osn.com_ae.channels.xml b/sites/osn.com/osn.com_ae.channels.xml new file mode 100644 index 00000000..4bd00fce --- /dev/null +++ b/sites/osn.com/osn.com_ae.channels.xml @@ -0,0 +1,104 @@ + + + + Aghani Aghani TV + Aksyon TV International + Al Aan TV + Al Dafrah TV + Alhurra TV + Al-Majlis TV + Al Mamlaka TV + Al-Qurain TV + Al Safwa + Al Wousta TV + Al Yawm + ANC + ART Aflam 1 + ART Aflam 2 + ART Cinema + ART Hekayat + ART Hekayat 2 + B4U Aflam + B4U Plus + Baby TV Europe + Bahrain TV + BBC Arabic + BBC World News Middle East + Bloomberg TV Europe + CGTN + CGTN Arabic + Cinema 1 + Cinema 2 + Cinema One Global + Cine Mo! + CNBC Arabiya + CNBC Europe + Crime + Investigation UK + Discovery Channel Middle East & Africa + Discovery Science Middle East + Disney Channel Middle East + Disney Junior Middle East + Dubai Racing + Dubai Racing 3 + Ellay.com + E! Middle East + Fann + France 24 Arabic + France 24 English + GMA Life TV + GMA News + GMA Pinoy TV Middle East + History 2 Middle East + History Middle East + Investigation Discovery Europe + KTV 1 + KTV 2 + KTV Arabe + KTV Ethraa + KTV Sport + KTV Sport Plus + Madani TV + Marina TV + MTV 00s + MTV Live + Musalsalat + Musalsalat +2 + Music Now + Myx Middle East + National Geographic Middle East + National Geographic Wild Middle East + NHK World Japan + Nickelodeon Arabia + Nick Jr Arabia + NickToons Arabia + OSN Action + OSN Comedy + OSN Enigma + OSN Family + OSN Kids + OSN Kid Zone + OSN Living + OSN Mezze + OSN Movies + OSN Movies First + OSN Movies First +2 + OSN News + OSN Series + OSN Series First + OSN Woman + OSN Ya Hala + OSN Ya Hala Al Oula + OSN Ya Hala Cinema + Roya TV + RT Arabic + Sharjah Sports + Sharqiya TV + Sky News Arabia + Sky News International + Star Movies Middle East + Star World Middle East + TeleRadyo Global + TFC Middle East + TLC Arabia + + \ No newline at end of file