Merge pull request #410 from iptv-org/create-api-programs-json

Create /api/programs.json
This commit is contained in:
Aleksandr Statciuk authored and GitHub committed 2022-01-18 22:53:30 +03:00
commit ac23624122
5 files changed
+106 -20

No files matched your search

+29 -9
View File
@@ -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
## 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
```
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
+36 -1
View File
@@ -6,6 +6,8 @@ const API_DIR = process.env.API_DIR || '.gh-pages/api'
async function main() {
await generateChannelsJson()
await generateProgramsJson()
logger.info(`Done`)
}
main()
@@ -18,8 +20,41 @@ async function generateChannelsJson() {
const channelsPath = `${API_DIR}/channels.json`
logger.info(`Saving to "${channelsPath}"...`)
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() {
+1 -1
View File
@@ -1 +1 @@
{"CNNInternationalEurope.us":[{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"CNN Newsroom Sunday"}],"description":[{"lang":"ru","value":"Свежая мировая информационная сводка от CNN. О политике, экономике, общественной жизни, культуре, спорте."}],"categories":[],"image":null,"start":1641772800,"stop":1641776400},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"Fareed Zakaria GPS"}],"description":[{"lang":"ru","value":"Интервью с главными игроками мировой политики."}],"categories":[],"image":null,"start":1641776400,"stop":1641780000},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"African Voices Changemakers. 114-я серия"}],"description":[{"lang":"ru","value":"114-я серия. Африка сегодня - люди, новости, события."}],"categories":[],"image":null,"start":1641780000,"stop":1641781800},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"Marketplace Africa. 549-я серия"}],"description":[{"lang":"ru","value":"549-я серия. Информационная передача об экономических событиях африканского региона. Анализируются проблемы, даются экономические прогнозы."}],"categories":[],"image":null,"start":1641781800,"stop":1641782700},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"Marketplace Africa. 548-я серия"}],"description":[{"lang":"ru","value":"548-я серия. Информационная передача об экономических событиях африканского региона. Анализируются проблемы, даются экономические прогнозы."}],"categories":[],"image":null,"start":1641782700,"stop":1641783600},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"TBD"}],"description":[{"lang":"ru","value":"Информационно-познавательный проект CNN."}],"categories":[],"image":null,"start":1641783600,"stop":1641785400},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"Inside Africa. 586-я серия"}],"description":[{"lang":"ru","value":"586-я серия. Своеобразное \"путешествие\" по Африке - почувствуйте все разнообразие культур различных стран и регионов континента."}],"categories":[],"image":null,"start":1641785400,"stop":1641787200},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"CNN Newsroom with Michael Holmes"}],"description":[{"lang":"ru","value":"Обзор самых важных и актуальных новостей и событий из жизни страны и мира."}],"categories":[],"image":null,"start":1641787200,"stop":1641789900},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"World Sport"}],"description":[{"lang":"ru","value":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов."}],"categories":[],"image":null,"start":1641789900,"stop":1641790800},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"CNN Newsroom with Michael Holmes"}],"description":[{"lang":"ru","value":"Обзор самых важных и актуальных новостей и событий из жизни страны и мира."}],"categories":[],"image":null,"start":1641790800,"stop":1641794400},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"CNN Newsroom with Robyn Curnow"}],"description":[{"lang":"ru","value":"Обзор самых важных и актуальных новостей и событий из жизни страны и мира."}],"categories":[],"image":null,"start":1641794400,"stop":1641797100},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"World Sport"}],"description":[{"lang":"ru","value":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов."}],"categories":[],"image":null,"start":1641797100,"stop":1641798000},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"CNN Newsroom with Rosemary Church"}],"description":[{"lang":"ru","value":"Свежая мировая информационная сводка от CNN. О политике, экономике, общественной жизни, культуре, спорте."}],"categories":[],"image":null,"start":1641798000,"stop":1641805200},{"channel":"CNNInternationalEurope.us","title":[{"lang":"ru","value":"Early Start"}]Line truncated
[{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"CNN Newsroom Sunday","desc":"Свежая мировая информационная сводка от CNN. О политике, экономике, общественной жизни, культуре, спорте.","categories":[],"image":null,"start":1641772800,"stop":1641776400},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"Fareed Zakaria GPS","desc":"Интервью с главными игроками мировой политики.","categories":[],"image":null,"start":1641776400,"stop":1641780000},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"African Voices Changemakers. 114-я серия","desc":"114-я серия. Африка сегодня - люди, новости, события.","categories":[],"image":null,"start":1641780000,"stop":1641781800},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"Marketplace Africa. 549-я серия","desc":"549-я серия. Информационная передача об экономических событиях африканского региона. Анализируются проблемы, даются экономические прогнозы.","categories":[],"image":null,"start":1641781800,"stop":1641782700},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"Marketplace Africa. 548-я серия","desc":"548-я серия. Информационная передача об экономических событиях африканского региона. Анализируются проблемы, даются экономические прогнозы.","categories":[],"image":null,"start":1641782700,"stop":1641783600},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"TBD","desc":"Информационно-познавательный проект CNN.","categories":[],"image":null,"start":1641783600,"stop":1641785400},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"Inside Africa. 586-я серия","desc":"586-я серия. Своеобразное \"путешествие\" по Африке - почувствуйте все разнообразие культур различных стран и регионов континента.","categories":[],"image":null,"start":1641785400,"stop":1641787200},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"CNN Newsroom with Michael Holmes","desc":"Обзор самых важных и актуальных новостей и событий из жизни страны и мира.","categories":[],"image":null,"start":1641787200,"stop":1641789900},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"World Sport","desc":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов.","categories":[],"image":null,"start":1641789900,"stop":1641790800},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"CNN Newsroom with Michael Holmes","desc":"Обзор самых важных и актуальных новостей и событий из жизни страны и мира.","categories":[],"image":null,"start":1641790800,"stop":1641794400},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"CNN Newsroom with Robyn Curnow","desc":"Обзор самых важных и актуальных новостей и событий из жизни страны и мира.","categories":[],"image":null,"start":1641794400,"stop":1641797100},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"World Sport","desc":"Все о главных спортивных событиях мира. Обзоры самых важных спортивных событий, аналитика, мнения экспертов.","categories":[],"image":null,"start":1641797100,"stop":1641798000},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"CNN Newsroom with Rosemary Church","desc":"Свежая мировая информационная сводка от CNN. О политике, экономике, общественной жизни, культуре, спорте.","categories":[],"image":null,"start":1641798000,"stop":1641805200},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"Early Start","desc":"Новости дня с Кристиной Романс и Дейвом Бриггсом.","categories":[],"image":null,"start":1641805200,"stop":1641808800},{"channel":"CNNInternationalEurope.us","site":"magticom.ge","lang":"ru","title":"New Day","desc":"Свежий обзор событий Line truncated
+29 -9
View File
@@ -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
## 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
```
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
+11
View File
@@ -10,6 +10,10 @@ beforeEach(() => {
'tests/__data__/input/database/channels.db',
'tests/__data__/temp/database/channels.db'
)
fs.copyFileSync(
'tests/__data__/input/database/programs.db',
'tests/__data__/temp/database/programs.db'
)
execSync(
'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)
})
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) {
const data = fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'