Merge pull request #1143 from iptv-org/add-myafn.dodmedia.osd.mil

Add guide from myafn.dodmedia.osd.mil
This commit is contained in:
Aleksandr Statciuk 2022-10-03 20:59:31 +03:00 committed by GitHub
commit 3b6deb8438
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 162 additions and 0 deletions

View file

@ -0,0 +1,17 @@
name: myafn.dodmedia.osd.mil
on:
schedule:
- cron: '0 3 * * *'
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,75 @@
const axios = require('axios')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
module.exports = {
site: 'myafn.dodmedia.osd.mil',
request: {
cache: {
ttl: 60 * 60 * 1000 // 1 hour
}
},
url: function ({ date }) {
return `https://v3.myafn.dodmedia.osd.mil/api/json/32/${date.format(
'YYYY-MM-DD'
)}@0000/${date.format('YYYY-MM-DD')}@2359/schedule.json`
},
parser: function ({ content, date, channel }) {
let programs = []
const items = parseItems(content, channel)
items.forEach(item => {
const start = parseStart(item, date)
const stop = start.add(item.o, 'm')
programs.push({
title: item.h,
sub_title: item.i,
description: item.l,
rating: parseRating(item),
category: parseCategory(item),
start,
stop
})
})
return programs
},
async channels() {
const data = await axios
.get(`https://v3.myafn.dodmedia.osd.mil/api/json/32/channels.json`)
.then(r => r.data)
.catch(console.log)
return data.map(item => ({
site_id: item.Channel,
name: item.Title
}))
}
}
function parseStart(item, date) {
return dayjs.utc(item.e, 'YYYY,M,D,H,m,s,0').add(1, 'month')
}
function parseCategory(item) {
return item.m ? item.m.split(',') : []
}
function parseRating(item) {
return item.j
? {
system: 'MPA',
value: item.j
}
: null
}
function parseItems(content, channel) {
const items = JSON.parse(content)
if (!Array.isArray(items)) return []
return items.filter(i => i.b == channel.site_id)
}

View file

@ -0,0 +1,57 @@
// npx epg-grabber --config=sites/myafn.dodmedia.osd.mil/myafn.dodmedia.osd.mil.config.js --channels=sites/myafn.dodmedia.osd.mil/myafn.dodmedia.osd.mil_us.channels.xml --output=guide.xml --days=2
// npm run channels:parse -- --config=./sites/myafn.dodmedia.osd.mil/myafn.dodmedia.osd.mil.config.js --output=./sites/myafn.dodmedia.osd.mil/myafn.dodmedia.osd.mil_us.channels.xml
const { parser, url } = require('./myafn.dodmedia.osd.mil.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-10-03', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '2',
xmltv_id: 'AFNPrimeAtlantic.us'
}
it('can generate valid url', () => {
expect(url({ date })).toBe(
'https://v3.myafn.dodmedia.osd.mil/api/json/32/2022-10-03@0000/2022-10-03@2359/schedule.json'
)
})
it('can parse response', () => {
const content = `[{"a":566,"b":2,"c":"2022,9,3,3,0,0,0","d":"2022,9,3,4,0,0,0","e":"2022,9,3,3,0,0,0","f":"2022,9,3,4,0,0,0","g":60,"h":"This Week with George Stephanopoulos (ABC)","i":"Episode Title","j":"TV-14","k":false,"l":"Former Clinton White House staffer and current co-anchor of ABC's weekday morning news show \\"\\"Good Morning America,\\"\\" George Stephanopoulos and co-anchors Martha Raddatz and Jonathan Karl offer a look at current events with a focus on the politics of the day. Each week's show includes interviews with top newsmakers (including some of the nation's top political leaders) as well as a roundtable discussion, usually featuring journalists from ABC and other news organizations, of the week's happenings. Since 2008, the program has broadcast from a studio at the Newseum in Washington, D.C.","m":"News,Politics,Public affairs,Talk","n":694284445,"o":60,"p":20,"q":true,"r":694285705,"s":null}]`
const result = parser({ content, date, channel }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2022-10-03T03:00:00.000Z',
stop: '2022-10-03T04:00:00.000Z',
title: 'This Week with George Stephanopoulos (ABC)',
sub_title: 'Episode Title',
description:
'Former Clinton White House staffer and current co-anchor of ABC\'s weekday morning news show ""Good Morning America,"" George Stephanopoulos and co-anchors Martha Raddatz and Jonathan Karl offer a look at current events with a focus on the politics of the day. Each week\'s show includes interviews with top newsmakers (including some of the nation\'s top political leaders) as well as a roundtable discussion, usually featuring journalists from ABC and other news organizations, of the week\'s happenings. Since 2008, the program has broadcast from a studio at the Newseum in Washington, D.C.',
category: ['News', 'Politics', 'Public affairs', 'Talk'],
rating: {
system: 'MPA',
value: 'TV-14'
}
}
])
})
it('can handle empty guide', () => {
const result = parser({
content: `{
"Message": "An error has occurred."
}`,
date,
channel
})
expect(result).toMatchObject([])
})

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<site site="myafn.dodmedia.osd.mil">
<channels>
<channel lang="en" xmltv_id="AFNPrimeAtlantic.us" site_id="2">AFN|prime Atlantic</channel>
<channel lang="en" xmltv_id="AFNNews.us" site_id="5">AFN|news</channel>
<channel lang="en" xmltv_id="AFNSports.us" site_id="1">AFN|sports</channel>
<channel lang="en" xmltv_id="AFNPrimePacific.us" site_id="4">AFN|prime Pacific</channel>
<channel lang="en" xmltv_id="AFNSpectrum.us" site_id="3">AFN|spectrum</channel>
<channel lang="en" xmltv_id="AFNSports2.us" site_id="6">AFN|sports2</channel>
<channel lang="en" xmltv_id="AFNFamily.us" site_id="9">AFN|family,AFN|pulse</channel>
<channel lang="en" xmltv_id="AFNMovie.us" site_id="10">AFN|movie</channel>
</channels>
</site>