Merge pull request #633 from iptv-org/add-kplus.vn

Add guide from kplus.vn
This commit is contained in:
Aleksandr Statciuk 2022-03-15 22:25:52 +03:00 committed by GitHub
commit 89ca292c2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 196 additions and 0 deletions

17
.github/workflows/kplus.vn.yml vendored Normal file
View file

@ -0,0 +1,17 @@
name: kplus.vn
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
workflow_run:
workflows: [_trigger]
types:
- completed
jobs:
load:
uses: ./.github/workflows/_load.yml
with:
site: ${{github.workflow}}
secrets:
APP_ID: ${{ secrets.APP_ID }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}

View file

@ -0,0 +1,79 @@
const axios = require('axios')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(timezone)
dayjs.extend(utc)
const API_ENDPOINT = `https://www.kplus.vn/Schedule/getSchedule`
module.exports = {
site: 'kplus.vn',
ignore: true, // channel list changes with each request
url: API_ENDPOINT,
request: {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data({ date }) {
const params = new URLSearchParams()
params.append('date', date.format('D-M-YYYY'))
params.append('categories', '')
return params
},
method: 'POST'
},
parser: function ({ content, channel }) {
let programs = []
const items = parseItems(content, channel)
items.forEach(item => {
const prev = programs[programs.length - 1]
const start = parseStart(item)
const stop = start.add(1, 'h')
if (prev) prev.stop = start
programs.push({
title: item.Program.Name,
icon: item.Program.Images,
category: item.Program.Genres,
start,
stop
})
})
return programs
},
async channels() {
const params = new URLSearchParams()
params.append('date', dayjs().format('D-M-YYYY'))
params.append('categories', '')
const data = await axios
.post(API_ENDPOINT, params, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(r => r.data)
.catch(console.log)
return data.Channels.map(item => {
return {
lang: 'vi',
site_id: item.Id,
name: item.Name
}
})
}
}
function parseStart(item) {
return dayjs.tz(item.ShowingTime, 'Asia/Ho_Chi_Minh')
}
function parseItems(content, channel) {
const data = JSON.parse(content)
if (!data || !Array.isArray(data.Schedules)) return []
return data.Schedules.filter(i => i.ChannelId == channel.site_id)
}

View file

@ -0,0 +1,66 @@
// npm run channels:parse -- --config=sites/kplus.vn/kplus.vn.config.js --output=sites/kplus.vn/kplus.vn_vn.channels.xml
// npx epg-grabber --config=sites/kplus.vn/kplus.vn.config.js --channels=sites/kplus.vn/kplus.vn_vn.channels.xml --output=guide.xml --days=2
const { parser, url, request } = require('./kplus.vn.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('2022-03-15', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '7019',
xmltv_id: 'KPlus1HD.vn'
}
it('can generate valid url', () => {
expect(url).toBe('https://www.kplus.vn/Schedule/getSchedule')
})
it('can generate valid request headers', () => {
expect(request.headers).toMatchObject({
'Content-Type': 'application/x-www-form-urlencoded'
})
})
it('can generate valid request data', () => {
const data = request.data({ date })
expect(data.get('date')).toBe('15-3-2022')
expect(data.get('categories')).toBe('')
})
it('can parse response', () => {
const content = `{"SchedulesCount":1105,"ChannelsCount":28,"Schedules":[{"Id":12195,"ChannelId":7019,"ProgramId":35111026,"EpgProgramId":"1252496\\r","ShowingTime":"2022-03-15T06:15:00","EpgBroadcastId":"HD_ENT_DOC_LNO_21_2649421_2652183_4383385_OnAir","EpgId":"HD_ENT_DOC_LNO_21_2649421_2652183_4383385_OnAir","IsDeleted":false,"CreatedOn":"2022-03-15T06:22:45","UpdatedOn":"0001-01-01T00:00:00","Channel":{"Id":7019,"Name":"K+1 HD","Image":"https://kplus-website-production-cdn.azureedge.net/content/upload/7/images-mkt/logo-k-1-hd-new.png","LiveUrlSegment":"highlights/broadcast-schedule/K-1-HD","FeatureImage":"https://kplus-website-production-cdn.azureedge.net/content/upload/7/images-mkt/logo-k-1-hd-new.png","EpgId":null,"IsOTTEnabled":false,"StartOver":0,"DisplayOrder":0},"Program":{"Id":35111026,"Name":"WEEKLY FILMS AND STARS, EP740","BodyContent":"","Cast":"","Director":"","Duration":0,"EpgId":"93701","EpgProgramId":null,"Episode":0,"Genres":"Documentary","Images":"https://img.kplus.vn/images?filename=Media/HDVN/2022_02/ENT_DOC_LNO_21_2649421_2652183_2652183.jpg","IsFeatured":false,"IsOTTEnabled":true,"IsRebroadcast":false,"ShortDescription":"","SubTitle":"","Trailers":"","UrlSegment":"highlights/broadcast-schedule/93701/weekly-films-and-stars-ep740","CreatedOn":"2022-03-16T00:15:45","UpdatedOn":"2022-03-16T00:15:45","ParentalRating":null},"RelatedSchedules":null},{"Id":12196,"ChannelId":7019,"ProgramId":35111279,"EpgProgramId":"798685\\r","ShowingTime":"2022-03-15T07:00:00","EpgBroadcastId":"HD_MOV_COM__2632318_4383386_OnAir","EpgId":"HD_MOV_COM__2632318_4383386_OnAir","IsDeleted":false,"CreatedOn":"2022-03-15T07:02:46","UpdatedOn":"0001-01-01T00:00:00","Channel":{"Id":7019,"Name":"K+1 HD","Image":"https://kplus-website-production-cdn.azureedge.net/content/upload/7/images-mkt/logo-k-1-hd-new.png","LiveUrlSegment":"highlights/broadcast-schedule/K-1-HD","FeatureImage":"https://kplus-website-production-cdn.azureedge.net/content/upload/7/images-mkt/logo-k-1-hd-new.png","EpgId":null,"IsOTTEnabled":false,"StartOver":0,"DisplayOrder":0},"Program":{"Id":35111279,"Name":"ST. VINCENT","BodyContent":"","Cast":"Bill Murray, Melissa McCarthy, Naomi Watts","Director":"Theodore Melfi","Duration":0,"EpgId":"93959","EpgProgramId":null,"Episode":0,"Genres":"Comedy","Images":"https://img.kplus.vn/images?filename=Media/HDVN/2020_05/MOV_COM__2632318_2632318.jpg","IsFeatured":false,"IsOTTEnabled":true,"IsRebroadcast":false,"ShortDescription":"","SubTitle":"","Trailers":"","UrlSegment":"highlights/broadcast-schedule/93959/st-vincent","CreatedOn":"2022-03-16T00:15:45","UpdatedOn":"2022-03-16T00:15:45","ParentalRating":null},"RelatedSchedules":null}]}`
const result = parser({ content, channel }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2022-03-14T23:15:00.000Z',
stop: '2022-03-15T00:00:00.000Z',
title: 'WEEKLY FILMS AND STARS, EP740',
icon: 'https://img.kplus.vn/images?filename=Media/HDVN/2022_02/ENT_DOC_LNO_21_2649421_2652183_2652183.jpg',
category: 'Documentary'
},
{
start: '2022-03-15T00:00:00.000Z',
stop: '2022-03-15T01:00:00.000Z',
title: 'ST. VINCENT',
icon: 'https://img.kplus.vn/images?filename=Media/HDVN/2020_05/MOV_COM__2632318_2632318.jpg',
category: 'Comedy'
}
])
})
it('can handle empty guide', () => {
const result = parser({
content: `{"SchedulesCount":0,"ChannelsCount":0,"Schedules":[],"Channels":[],"MinDuration":0}`,
channel
})
expect(result).toMatchObject([])
})

View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<site site="kplus.vn">
<channels>
<channel lang="vi" xmltv_id="AsianFoodNetwork.sg" site_id="4529">AFC</channel>
<channel lang="vi" xmltv_id="AXNEastAsia.us" site_id="7036">AXN HD</channel>
<channel lang="vi" xmltv_id="CartoonNetworkVietnam.us" site_id="7063">CARTOON NETWORK</channel>
<channel lang="vi" xmltv_id="DiscoveryChannelSoutheastAsia.us" site_id="7057">DISCOVERY CHANNEL</channel>
<channel lang="vi" xmltv_id="GiaiTriTV.vn" site_id="4508">VTVCab1-GIAITRITV</channel>
<channel lang="vi" xmltv_id="HBOAsia.us" site_id="7035">HBO HD</channel>
<channel lang="vi" xmltv_id="Hits.id" site_id="161300">HITS SD</channel>
<channel lang="vi" xmltv_id="HTV7.vn" site_id="4550">HTV7</channel>
<channel lang="vi" xmltv_id="HTV9.vn" site_id="4638">HTV9</channel>
<channel lang="vi" xmltv_id="KBSWorld.kr" site_id="7054">KBS WORLD</channel>
<channel lang="vi" xmltv_id="KPlusCineHD.vn" site_id="7008">K+CINE HD</channel>
<channel lang="vi" xmltv_id="KPlusLifeHD.vn" site_id="7010">K+LIFE HD</channel>
<channel lang="vi" xmltv_id="KPlusSport2HD.vn" site_id="7014">K+PC HD</channel>
<channel lang="vi" xmltv_id="KPlusSport1HD.vn" site_id="7012">K+PM HD</channel>
<channel lang="vi" xmltv_id="NationalGeographicAsia.us" site_id="7077">NGC HD</channel>
<channel lang="vi" xmltv_id="NHKWorldJapan.jp" site_id="7070">NHK WORLD JAPAN</channel>
<channel lang="vi" xmltv_id="SCTVPhimtonghop.vn" site_id="7034">SCTV PHIMTONGHOP</channel>
<channel lang="vi" xmltv_id="TodayTV.vn" site_id="7049">VTC7-TODAY TV</channel>
<channel lang="vi" xmltv_id="TV5MondeAsie.fr" site_id="7068">TV5 MONDE</channel>
<channel lang="vi" xmltv_id="VTC1.vn" site_id="7069">VTC1</channel>
<channel lang="vi" xmltv_id="VTV1HD.vn" site_id="7016">VTV1 HD</channel>
<channel lang="vi" xmltv_id="VTV2.vn" site_id="4478">VTV2</channel>
<channel lang="vi" xmltv_id="VTV3HD.vn" site_id="7017">VTV3 HD</channel>
<channel lang="vi" xmltv_id="VTV4.vn" site_id="4481">VTV4</channel>
<channel lang="vi" xmltv_id="VTV6HD.vn" site_id="7018">VTV6 HD</channel>
<channel lang="vi" xmltv_id="VTV7.vn" site_id="7030">VTV7</channel>
<channel lang="vi" xmltv_id="VTV8.vn" site_id="7031">VTV8</channel>
<channel lang="vi" xmltv_id="VTV9.vn" site_id="4486">VTV9</channel>
<channel lang="vi" xmltv_id="YouTV.vn" site_id="7079">YOU TV</channel>
</channels>
</site>