Merge pull request #2766 from iptv-org/add-derana.lk

Add derana.lk
This commit is contained in:
PopeyeTheSai10r
2025-05-25 10:39:16 -07:00
committed by GitHub
5 changed files with 118 additions and 0 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<channels>
<channel site="derana.lk" lang="sn" xmltv_id="TVDerana.lk" site_id="#">TV Derana</channel>
</channels>

View File

@@ -0,0 +1,48 @@
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
const parseDuration = require('parse-duration').default
const timezone = require('dayjs/plugin/timezone')
const _ = require('lodash')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
dayjs.extend(timezone)
module.exports = {
site: 'derana.lk',
url({ date }) {
return `https://derana.lk/api/schedules/${date.format('DD-MM-YYYY')}`
},
parser({ content }) {
const programs = parseItems(content).map(item => {
const start = parseStart(item)
const duration = parseDuration(item.duration)
const stop = start.add(duration, 'ms')
return {
title: item.dramaName,
image: item.imageUrl,
start,
stop
}
})
return _.sortBy(programs, p => p.start)
}
}
function parseStart(item) {
return dayjs.tz(`${item.date} ${item.time}`, 'DD-MM-YYYY H:mm A', 'Asia/Colombo')
}
function parseItems(content) {
try {
const data = JSON.parse(content)
if (!data || !Array.isArray(data.all_schedules)) return []
return data.all_schedules
} catch {
return []
}
}

View File

@@ -0,0 +1,50 @@
const { parser, url } = require('./derana.lk.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-05-18', 'YYYY-MM-DD').startOf('d')
it('can generate valid url', () => {
expect(url({ date })).toBe('https://derana.lk/api/schedules/18-05-2025')
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
let results = parser({ content })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(20)
expect(results[0]).toMatchObject({
title: 'Dahami Derana',
image: 'https://derana.lk/storage/uploads/imgs/program/51/20240717062206.jpg',
start: '2025-05-17T23:05:00.000Z',
stop: '2025-05-18T00:55:00.000Z'
})
expect(results[1]).toMatchObject({
title: 'Derana Aruna',
image: 'https://derana.lk/storage/uploads/imgs/program/15/20240613075807.jpg',
start: '2025-05-18T00:55:00.000Z',
stop: '2025-05-18T02:00:00.000Z'
})
})
it('can handle empty guide', () => {
const results = parser({
content: {
error: 'An error occurred'
}
})
expect(results).toMatchObject([])
})

15
sites/derana.lk/readme.md Normal file
View File

@@ -0,0 +1,15 @@
# derana.lk
https://www.derana.lk/schedule
### Download the guide
```sh
npm run grab --- --site=derana.lk
```
### Test
```sh
npm test --- derana.lk
```