mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-12 10:00:08 -04:00
Merge pull request #410 from iptv-org/create-api-programs-json
Create /api/programs.json
This commit is contained in:
commit
ac23624122
5 changed files with 106 additions and 20 deletions
|
@ -25,20 +25,14 @@ To load a program guide, all you need to do is copy the link to one or more of t
|
||||||
|
|
||||||
https://iptv-org.github.io/epg/index.html
|
https://iptv-org.github.io/epg/index.html
|
||||||
|
|
||||||
## For Developers
|
## API
|
||||||
|
|
||||||
You can also get a list of all available channels and their codes in JSON format by sending a GET request to:
|
### List of channels
|
||||||
|
|
||||||
```
|
```
|
||||||
https://iptv-org.github.io/epg/api/channels.json
|
https://iptv-org.github.io/epg/api/channels.json
|
||||||
```
|
```
|
||||||
|
|
||||||
If successful, you should get the following response:
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>Expand</summary>
|
|
||||||
<br>
|
|
||||||
|
|
||||||
```
|
```
|
||||||
[
|
[
|
||||||
...
|
...
|
||||||
|
@ -58,7 +52,33 @@ If successful, you should get the following response:
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
### List of programs
|
||||||
|
|
||||||
|
```
|
||||||
|
https://iptv-org.github.io/epg/api/programs.json
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
[
|
||||||
|
...
|
||||||
|
{
|
||||||
|
"channel": "CNNUSA.us",
|
||||||
|
"site": "example.com",
|
||||||
|
"lang": "en",
|
||||||
|
"title": "Erin Burnett OutFront",
|
||||||
|
"desc": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
||||||
|
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.",
|
||||||
|
"categories": [
|
||||||
|
"Series",
|
||||||
|
"News"
|
||||||
|
],
|
||||||
|
"image": "https://example.com/banner.jpg",
|
||||||
|
"start": 1641772800,
|
||||||
|
"stop": 1641776400
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ const API_DIR = process.env.API_DIR || '.gh-pages/api'
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await generateChannelsJson()
|
await generateChannelsJson()
|
||||||
|
await generateProgramsJson()
|
||||||
|
logger.info(`Done`)
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
@ -18,8 +20,41 @@ async function generateChannelsJson() {
|
||||||
const channelsPath = `${API_DIR}/channels.json`
|
const channelsPath = `${API_DIR}/channels.json`
|
||||||
logger.info(`Saving to "${channelsPath}"...`)
|
logger.info(`Saving to "${channelsPath}"...`)
|
||||||
await file.create(channelsPath, JSON.stringify(channels))
|
await file.create(channelsPath, JSON.stringify(channels))
|
||||||
|
}
|
||||||
|
|
||||||
logger.info(`Done`)
|
async function generateProgramsJson() {
|
||||||
|
logger.info('Generating programs.json...')
|
||||||
|
|
||||||
|
const programs = await loadPrograms()
|
||||||
|
|
||||||
|
const programsPath = `${API_DIR}/programs.json`
|
||||||
|
logger.info(`Saving to "${programsPath}"...`)
|
||||||
|
await file.create(programsPath, JSON.stringify(programs))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadPrograms() {
|
||||||
|
logger.info('Loading programs from database...')
|
||||||
|
|
||||||
|
await db.programs.load()
|
||||||
|
|
||||||
|
let items = await db.programs.find({})
|
||||||
|
|
||||||
|
items = items.map(item => {
|
||||||
|
return {
|
||||||
|
channel: item.channel,
|
||||||
|
site: item.site,
|
||||||
|
lang: item.lang,
|
||||||
|
title: item.title,
|
||||||
|
desc: item.description || null,
|
||||||
|
categories: item.category || [],
|
||||||
|
image: item.icon || null,
|
||||||
|
start: item.start,
|
||||||
|
stop: item.stop
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
logger.info('Sort programs...')
|
||||||
|
return _.sortBy(items, ['channel', 'site', 'start'])
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadChannels() {
|
async function loadChannels() {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -50,20 +50,14 @@ To load a program guide, all you need to do is copy the link to one or more of t
|
||||||
|
|
||||||
https://iptv-org.github.io/epg/index.html
|
https://iptv-org.github.io/epg/index.html
|
||||||
|
|
||||||
## For Developers
|
## API
|
||||||
|
|
||||||
You can also get a list of all available channels and their codes in JSON format by sending a GET request to:
|
### List of channels
|
||||||
|
|
||||||
```
|
```
|
||||||
https://iptv-org.github.io/epg/api/channels.json
|
https://iptv-org.github.io/epg/api/channels.json
|
||||||
```
|
```
|
||||||
|
|
||||||
If successful, you should get the following response:
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>Expand</summary>
|
|
||||||
<br>
|
|
||||||
|
|
||||||
```
|
```
|
||||||
[
|
[
|
||||||
...
|
...
|
||||||
|
@ -83,7 +77,33 @@ If successful, you should get the following response:
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
### List of programs
|
||||||
|
|
||||||
|
```
|
||||||
|
https://iptv-org.github.io/epg/api/programs.json
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
[
|
||||||
|
...
|
||||||
|
{
|
||||||
|
"channel": "CNNUSA.us",
|
||||||
|
"site": "example.com",
|
||||||
|
"lang": "en",
|
||||||
|
"title": "Erin Burnett OutFront",
|
||||||
|
"desc": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
||||||
|
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.",
|
||||||
|
"categories": [
|
||||||
|
"Series",
|
||||||
|
"News"
|
||||||
|
],
|
||||||
|
"image": "https://example.com/banner.jpg",
|
||||||
|
"start": 1641772800,
|
||||||
|
"stop": 1641776400
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,10 @@ beforeEach(() => {
|
||||||
'tests/__data__/input/database/channels.db',
|
'tests/__data__/input/database/channels.db',
|
||||||
'tests/__data__/temp/database/channels.db'
|
'tests/__data__/temp/database/channels.db'
|
||||||
)
|
)
|
||||||
|
fs.copyFileSync(
|
||||||
|
'tests/__data__/input/database/programs.db',
|
||||||
|
'tests/__data__/temp/database/programs.db'
|
||||||
|
)
|
||||||
|
|
||||||
execSync(
|
execSync(
|
||||||
'DB_DIR=tests/__data__/temp/database API_DIR=tests/__data__/output/api node scripts/commands/update-api.js',
|
'DB_DIR=tests/__data__/temp/database API_DIR=tests/__data__/output/api node scripts/commands/update-api.js',
|
||||||
|
@ -28,6 +32,13 @@ it('can generate channels.json', () => {
|
||||||
expect(output).toBe(expected)
|
expect(output).toBe(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('can generate programs.json', () => {
|
||||||
|
const output = content('tests/__data__/output/api/programs.json')
|
||||||
|
const expected = content('tests/__data__/expected/api/programs.json')
|
||||||
|
|
||||||
|
expect(output).toBe(expected)
|
||||||
|
})
|
||||||
|
|
||||||
function content(filepath) {
|
function content(filepath) {
|
||||||
const data = fs.readFileSync(path.resolve(filepath), {
|
const data = fs.readFileSync(path.resolve(filepath), {
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue