5 files changed
+118
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
{"today_schedule":[{"id":23,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/24\/20240528083526.jpg","dramaName":"Iskole","slug":"iskole","time":"7:30 PM","duration":"30 mins","date":"2025-05-16","showInList":1},{"id":28,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/26\/20240718073139.jpg","dramaName":"Sikuru Awith","slug":"sikuru-awith","time":"6:00 PM","duration":"30 mins","date":"2025-05-16","showInList":1},{"id":34,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/28\/20240528084215.jpg","dramaName":"Nikini Kusum","slug":"nikini-kusum","time":"9:00 PM","duration":"30 mins","date":"2025-05-16","showInList":1},{"id":59,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/16\/20240613043914.jpg","dramaName":"Ma Nowana Mama Season 03","slug":"ma-nowana-mama-season-03","time":"10:30 PM","duration":"85 mins","date":"2025-05-16","showInList":1},{"id":64,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/25\/20240528083822.png","dramaName":"Sitha Nidi Na","slug":"sitha-nidi-na","time":"6:30 PM","duration":"30 mins","date":"2025-05-16","showInList":1},{"id":69,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/27\/20240528084105.png","dramaName":"Prarthana","slug":"prarthana","time":"9:30 PM","duration":"30 mins","date":"2025-05-16","showInList":1},{"id":77,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/22\/20240717062735.jpg","dramaName":"Deweni Inima Season 2","slug":"deweni-inima-season-2","time":"8:30 PM","duration":"30 mins","date":"2025-05-16","showInList":1},{"id":82,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/23\/20240528083409.jpg","dramaName":"Sangeethe","slug":"sangeethe","time":"8:00 PM","duration":"30 mins","date":"2025-05-16","showInList":1},{"id":88,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/15\/20240613075807.jpg","dramaName":"Derana Aruna","slug":"derana-aruna","time":"6:25 AM","duration":"65 mins","date":"2025-05-16","showInList":1},{"id":95,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/11\/20240715091008.jpg","dramaName":"Ada Derana 6.55","slug":"ada-derana-6.55","time":"6:55 PM","duration":"35 mins","date":"2025-05-16","showInList":1},{"id":102,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/21\/20240715084605.jpg","dramaName":"Ada Derana Late Night News Bulletin","slug":"ada-derana-late-night-news-bulletin","time":"10:00 PM","duration":"35 mins","date":"2025-05-16","showInList":1},{"id":109,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/19\/20240715091745.jpg","dramaName":"Ada Derana Midday Prime News Bulletin","slug":"ada-derana-midday-prime-news-bulletin","time":"12:00 PM","duration":"35 mins","date":"2025-05-16","showInList":1},{"id":116,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/20\/20240716062553.jpg","dramaName":"Lokaya Saha Lokayo","slug":"lokaya-saha-lokayo","time":"7:30 AM","duration":"30 mins","date":"2025-05-16","showInList":0},{"id":128,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/51\/20240717062206.jpg","dramaName":"Dahami Derana","slug":"dahami-derana","time":"4:35 AM","duration":"110 mins","date":"2025-05-16","showInList":0},{"id":134,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/52\/20240716111355.jpg","dramaName":"Soortin Martin","slug":"soortin-martin","time":"8:00 AM","duration":"60 mins","date":"2025-05-16","showInList":0},{"id":141,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/45\/20240716063459.jpg","dramaName":"Seda Mawatha","slug":"seda-mawatha","time":"11:30 AM","duration":"30 mins","date":"2025-05-16","showInList":0},{"id":146,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/46\/20240717062004.jpg","dramaName":"Derana Cinema","slug":"derana-cinema","time":"12:35 PM","duration":"205 mins","date":"2025-05-16","showInList":0},{"id":158,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/48\/20240722054430.jpg","dramaName":"Kalari","slug":"kalari","time":"4:25 PM","duration":"30 mins","date":"2025-05-16","showInList":0},{"id":163,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/49\/20240716111624.jpg","dramaName":"Kala Kalliya","slug":"kala-kalliya","time":"4:55 PM","duration":"30 mins","date":"2025-05-16","showInList":0},{"id":168,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/50\/20240722064507.jpg","dramaName":"Alvin & the Chipmunks","slug":"alvin-&-the-chipmunks","time":"5:25 PM","duration":"30 mins","date":"2025-05-16","showInList":0},{"id":179,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/56\/20240717055726.jpg","dramaName":"Lavai Kushai","slug":"lavai-kushai","time":"4:00 PM","duration":"25 mins","date":"2025-05-16","showInList":0},{"id":184,"imageUrl":"https:\/\/derana.lk\/storage\/uploads\/imgs\/program\/57\/20240725061833.jpg","dramaName":"Iskole (Repeat)","slug":"iskole-(repeatLine truncated
|
||||||
@@ -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>
|
||||||
@@ -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 []
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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([])
|
||||||
|
})
|
||||||
@@ -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
|
||||||
|
```
|
||||||
Reference in new issue
Block a user