2023-10-15 14:08:23 +03:00
// NODE_OPTIONS=--insecure-http-parser npx epg-grabber --config=sites/osn.com/osn.com.config.js --channels=sites/osn.com/osn.com.channels.xml --output=guide.xml --days=2
2023-11-06 23:47:54 +03:00
const { parser , url , request } = require ( './osn.com.config.js' )
2023-10-15 14:08:23 +03:00
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 channelAR = { site _id : 'AAN' , xmltv _id : 'AlAanTV.ae' , lang : 'ar' }
const channelEN = { site _id : 'AAN' , xmltv _id : 'AlAanTV.ae' , lang : 'en' }
2023-11-06 23:43:29 +03:00
const content =
'[{"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"}]'
2023-10-15 14:08:23 +03:00
it ( 'can generate valid request headers' , ( ) => {
2023-11-05 13:55:24 +07:00
const result = request . headers ( { channel : channelAR , date } )
2023-10-15 14:08:23 +03:00
expect ( result ) . toMatchObject ( {
2023-11-05 13:55:24 +07:00
Referer : 'https://www.osn.com/ar-ae/watch/tv-schedule'
2023-10-15 14:08:23 +03:00
} )
} )
it ( 'can generate valid url' , ( ) => {
2023-11-05 13:55:24 +07:00
const result = url ( { channel : channelAR , date } )
expect ( result ) . toBe (
2023-11-05 13:55:24 +07:00
'https://www.osn.com/api/TVScheduleWebService.asmx/GetTVChannelsProgramTimeTable?newDate=10%2F24%2F2021&selectedCountry=AE&channelCode=AAN&isMobile=false&hoursForMobile=0'
2023-10-15 14:08:23 +03:00
)
} )
it ( 'can parse response (ar)' , ( ) => {
const result = parser ( { date , channel : channelAR , 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 parse response (en)' , ( ) => {
const result = parser ( { date , channel : channelEN , content } )
expect ( result ) . toMatchObject ( [
{
start : 'Sun, 24 Oct 2021 18:00:00 GMT' ,
stop : 'Sun, 24 Oct 2021 20:00:00 GMT' ,
title : 'Al Aan TV' ,
category : null
}
] )
} )
it ( 'can handle empty guide' , ( ) => {
2023-11-05 13:55:24 +07:00
const result = parser ( { date , channel : channelAR , content : '[]' } )
2023-10-15 14:08:23 +03:00
expect ( result ) . toMatchObject ( [ ] )
} )