mirror of
https://github.com/iptv-org/epg
synced 2026-05-07 09:57:06 -04:00
Update osn.com guide.
Test ``` npm test -- osn.com > test > run-script-os osn.com > test:win32 > SET "TZ=Pacific/Nauru" && npx jest --runInBand osn.com PASS sites/osn.com/osn.com.test.js (5.194 s) √ can generate valid request headers (6 ms) √ can generate valid url (2 ms) √ can parse response (ar) (112 ms) √ can parse response (en) (9 ms) √ can handle empty guide (1 ms) Test Suites: 1 passed, 1 total Tests: 5 passed, 5 total Snapshots: 0 total Time: 5.499 s Ran all test suites matching /osn.com/i. ``` Grab ``` npm run grab -- --site=osn.com --lang=ar > grab > npx tsx scripts/commands/epg/grab.ts --site=osn.com --lang=ar starting... config: output: guide.xml maxConnections: 1 gzip: false site: osn.com lang: ar loading channels... found 59 channel(s) run #1: [1/118] osn.com (ar) - DWR - Nov 27, 2024 (24 programs) [2/118] osn.com (ar) - DWR - Nov 28, 2024 (24 programs) ... [117/118] osn.com (ar) - OSNYahalaBilArabi.ae - Nov 28, 2024 (29 programs) [118/118] osn.com (ar) - TheFilipinoChannelMiddleEast.us - Nov 28, 2024 (30 programs) saving to "guide.xml"... done in 00h 01m 23s ``` Signed-off-by: Toha <tohenk@yahoo.com>
This commit is contained in:
@@ -5,75 +5,64 @@ const timezone = require('dayjs/plugin/timezone')
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
const packages = { 'OSNTV CONNECT': 3720, 'OSNTV PRIME': 3733, 'ALFA': 1281, 'OSN PINOY PLUS EXTRA': 3519 }
|
||||
const country = 'AE'
|
||||
const tz = 'Asia/Dubai'
|
||||
|
||||
module.exports = {
|
||||
site: 'osn.com',
|
||||
days: 2,
|
||||
url({ channel, date }) {
|
||||
return `https://www.osn.com/api/TVScheduleWebService.asmx/GetTVChannelsProgramTimeTable?newDate=${encodeURIComponent(
|
||||
date.format('MM/DD/YYYY')
|
||||
)}&selectedCountry=AE&channelCode=${channel.site_id}&isMobile=false&hoursForMobile=0`
|
||||
return `https://www.osn.com/api/TVScheduleWebService.asmx/time?dt=${
|
||||
encodeURIComponent(date.format('MM/DD/YYYY'))
|
||||
}&co=${country}&ch=${
|
||||
channel.site_id
|
||||
}&mo=false&hr=0`
|
||||
},
|
||||
request: {
|
||||
headers({ channel }) {
|
||||
return {
|
||||
Referer: `https://www.osn.com/${channel.lang}-ae/watch/tv-schedule`
|
||||
Referer: `https://www.osn.com/${channel.lang}-${country.toLowerCase()}/watch/tv-schedule`
|
||||
}
|
||||
}
|
||||
},
|
||||
parser({ content, channel }) {
|
||||
const 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: parseTitle(item, channel),
|
||||
category: parseCategory(item, channel),
|
||||
start: start.toString(),
|
||||
stop: stop.toString()
|
||||
})
|
||||
})
|
||||
const items = JSON.parse(content) || []
|
||||
if (Array.isArray(items)) {
|
||||
for (const item of items) {
|
||||
const title = channel.lang === 'ar' ? item.Arab_Title : item.Title
|
||||
const start = dayjs.tz(item.StartDateTime, 'DD MMM YYYY, HH:mm', tz)
|
||||
const duration = parseInt(item.TotalDivWidth / 4.8)
|
||||
const stop = start.add(duration, 'm')
|
||||
programs.push({ title, start, stop })
|
||||
}
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ lang = 'ar' }) {
|
||||
const result = {}
|
||||
const axios = require('axios')
|
||||
const result = await axios
|
||||
.get('https://www.osn.com/api/tvchannels.ashx?culture=en-US&packageId=3519&country=AE')
|
||||
.then(response => response.data)
|
||||
.catch(console.error)
|
||||
for (const pkg of Object.values(packages)) {
|
||||
const channels = await axios
|
||||
.get(`https://www.osn.com/api/tvchannels.ashx?culture=en-US&packageId=${pkg}&country=${country}`)
|
||||
.then(response => response.data)
|
||||
.catch(console.error)
|
||||
|
||||
const channels = result.map(channel => {
|
||||
return {
|
||||
lang: lang,
|
||||
site_id: channel.channelCode,
|
||||
name: channel.channeltitle
|
||||
if (Array.isArray(channels)) {
|
||||
for (const ch of channels) {
|
||||
if (result[ch.channelCode] === undefined) {
|
||||
result[ch.channelCode] = {
|
||||
lang,
|
||||
site_id: ch.channelCode,
|
||||
name: ch.channeltitle
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return channels
|
||||
return Object.values(result)
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle(item, channel) {
|
||||
return channel.lang === 'ar' ? item.Arab_Title : item.Title
|
||||
}
|
||||
|
||||
function parseCategory(item, channel) {
|
||||
return channel.lang === 'ar' ? item.GenreArabicName : item.GenreEnglishName
|
||||
}
|
||||
|
||||
function parseDuration(item) {
|
||||
return parseInt(item.TotalDivWidth / 4.8)
|
||||
}
|
||||
|
||||
function parseStart(item) {
|
||||
const time = item.StartDateTime
|
||||
|
||||
return dayjs.tz(time, 'DD MMM YYYY, HH:mm', 'Asia/Dubai')
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
return content ? JSON.parse(content) : []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user