Files
epg/CONTRIBUTING.md

212 lines
7.4 KiB
Markdown
Raw Normal View History

2022-11-18 08:14:18 +03:00
# Contributing Guide
2023-10-02 22:41:45 +03:00
- [How to?](#how-to)
- [Project Structure](#project-structure)
- [Scripts](#scripts)
2022-11-18 08:14:18 +03:00
2023-10-02 22:41:45 +03:00
## How to?
### How to add a channel to the guide?
Open the [/sites](/sites) folder and select the source that you know has the guide for the channel you want.
2022-11-18 08:14:18 +03:00
Then in the selected folder open the file `*.channels.xml` and add to it:
```xml
2023-10-02 22:41:45 +03:00
<channel site="SITE" lang="LANGUAGE_CODE" xmltv_id="CHANNEL_ID" site_id="SITE_ID">CHANNEL_NAME</channel>
2022-11-18 08:14:18 +03:00
```
2023-10-02 22:41:45 +03:00
| Attribute | Description | Example |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------- |
| SITE | Site domain name. | `example.com` |
| LANGUAGE_CODE | Language of the guide ([ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code). | `en` |
| CHANNEL_ID | Channel ID from [iptv-org/database](https://github.com/iptv-org/database). A complete list of supported channels can also be found at https://iptv-org.github.io/. | `BBCOne.uk` |
| SITE_ID | Unique ID of the channel used in the source. | `bbc1` |
| CHANNEL_NAME | Name of the channel used in the source. | `BBC 1` |
2022-11-18 08:14:18 +03:00
After that just commit all changes and send a pull request.
### How to add a new source to the repository?
2025-01-12 22:06:33 +03:00
To do this, you will need to create a new folder in the [/sites](/sites) directory with at least 4 files:
2022-11-18 08:14:18 +03:00
<details>
<summary>example.com.config.js</summary>
<br>
2025-01-12 22:06:33 +03:00
This file describes what kind of request we need to send to get the guide for a particular channel on a certain date and how to parse the response.
2022-11-18 08:14:18 +03:00
```js
module.exports = {
2023-10-02 22:41:45 +03:00
site: 'example.com',
2025-01-12 22:06:33 +03:00
url({ channel, date }) {
2023-10-02 22:41:45 +03:00
return `https://example.com/api/${channel.site_id}/${date.format('YYYY-MM-DD')}`
},
2025-01-12 22:06:33 +03:00
parser({ content }) {
try {
return JSON.parse(content)
} catch {
return []
}
},
channels() {
return []
2023-10-02 22:41:45 +03:00
}
2022-11-18 08:14:18 +03:00
}
```
More detailed instructions for this file can be found here: https://github.com/freearhey/epg-grabber#site-config
</details>
<details>
<summary>example.com.test.js</summary>
<br>
With this file we can test the previously created config and make sure it works as you expect.
```js
2025-01-12 22:06:33 +03:00
const { parser, url } = require('./example.com.config.js')
2022-11-18 08:14:18 +03:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
2025-01-12 22:06:33 +03:00
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
2022-11-18 08:14:18 +03:00
dayjs.extend(utc)
2025-01-12 22:06:33 +03:00
const date = dayjs.utc('2025-01-12', 'YYYY-MM-DD').startOf('d')
const channel = { site_id: 'bbc1', xmltv_id: 'BBCOne.uk' }
2022-11-18 08:14:18 +03:00
it('can generate valid url', () => {
2025-01-12 22:06:33 +03:00
expect(url({ channel, date })).toBe('https://example.com/api/bbc1/2025-01-12')
2022-11-18 08:14:18 +03:00
})
it('can parse response', () => {
2025-01-12 22:06:33 +03:00
const content =
'[{"title":"Program 1","start":"2025-01-12T00:00:00.000Z","stop":"2025-01-12T00:30:00.000Z"},{"title":"Program 2","start":"2025-01-12T00:30:00.000Z","stop":"2025-01-12T01:00:00.000Z"}]'
2023-10-02 22:41:45 +03:00
const results = parser({ content })
2025-01-12 22:06:33 +03:00
expect(results.length).toBe(2)
expect(results[0]).toMatchObject({
title: 'Program 1',
start: '2025-01-12T00:00:00.000Z',
stop: '2025-01-12T00:30:00.000Z'
})
expect(results[1]).toMatchObject({
title: 'Program 2',
start: '2025-01-12T00:30:00.000Z',
stop: '2025-01-12T01:00:00.000Z'
})
2022-11-18 08:14:18 +03:00
})
it('can handle empty guide', () => {
2025-01-12 22:06:33 +03:00
const result = parser({
date,
channel,
content: ''
})
2022-11-18 08:14:18 +03:00
2025-01-12 22:06:33 +03:00
expect(result).toMatchObject([])
2022-11-18 08:14:18 +03:00
})
```
2025-01-12 22:06:33 +03:00
To run all of these tests use the following command:
2022-11-18 08:14:18 +03:00
```sh
npm test --- example.com
2022-11-18 08:14:18 +03:00
```
Detailed documentation for the tests can be found here: https://jestjs.io/docs/using-matchers
</details>
<details>
<summary>example.com.channels.xml</summary>
<br>
This file contains a list of channels available at the source.
```xml
<?xml version="1.0" encoding="UTF-8" ?>
2023-10-02 22:41:45 +03:00
<channels>
<channel site="example.com" lang="en" xmltv_id="BBCOne.uk" site_id="bbc1">BBC 1</channel>
</channels>
2022-11-18 08:14:18 +03:00
```
</details>
2025-01-12 22:06:33 +03:00
<details>
<summary>readme.md</summary>
<br>
This file contains instructions on how to use this config.
````
# example.com
https://example.com
### Download the guide
2022-11-18 08:14:18 +03:00
```sh
npm run grab --- --site=example.com
2022-11-18 08:14:18 +03:00
```
2025-01-12 22:06:33 +03:00
### Update channel list
```sh
npm run channels:parse --- --config=./sites/example.com/example.com.config.js --output=./sites/example.com/example.com.channels.xml
```
### Test
```sh
npm test --- example.com
```
````
</details>
The fastest way to create all these files is to use the command:
```sh
npm run sites:init --- example.com
```
2022-11-18 08:14:18 +03:00
2025-01-12 22:06:33 +03:00
Once you are done working on the config make sure the tests pass, the guide downloads and just send us a [pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests).
2023-10-02 22:41:45 +03:00
## Project Structure
- `.github/`
- `ISSUE_TEMPLATE/`: issue templates for the repository.
2023-11-17 05:04:23 +03:00
- `workflows`: contains [GitHub actions](https://docs.github.com/en/actions/quickstart) workflows.
2023-10-02 22:41:45 +03:00
- `CODE_OF_CONDUCT.md`: rules you shouldn't break if you don't want to get banned.
- `scripts/`: contains all scripts used in the repository.
- `sites/`: contains configurations, channel lists and tests for all sites.
- `tests/`: contains tests to check the scripts.
- `CONTRIBUTING.md`: file you are currently reading.
- `README.md`: project description displayed on the home page.
- `SITES.md`: list of all supported sites and their current status.
## Scripts
These scripts are created to automate routine processes in the repository and make it a bit easier to maintain.
For scripts to work, you must have [Node.js](https://nodejs.org/en) installed on your computer.
To run scripts use the `npm run <script-name>` command.
2025-01-01 13:04:01 +03:00
- `act:check`: allows to test the [check](https://github.com/iptv-org/iptv/blob/master/.github/workflows/check.yml) workflow locally. Depends on [nektos/act](https://github.com/nektos/act).
2023-11-17 05:04:23 +03:00
- `act:update`: allows to test the [update](https://github.com/iptv-org/iptv/blob/master/.github/workflows/update.yml) workflow locally. Depends on [nektos/act](https://github.com/nektos/act).
2023-10-02 22:41:45 +03:00
- `api:load`: downloads the latest channels data from the [iptv-org/api](https://github.com/iptv-org/api).
2023-11-17 05:04:23 +03:00
- `api:generate`: generates a JSON file with all channels for the [iptv-org/api](https://github.com/iptv-org/api) repository.
2023-10-02 22:41:45 +03:00
- `channels:lint`: сhecks the channel lists for syntax errors.
- `channels:parse`: generates a list of channels based on the site configuration.
- `channels:editor`: utility for quick channels markup.
- `channels:validate`: checks the description of channels for errors.
2024-12-30 09:34:02 +03:00
- `sites:update`: updates the list of sites and their status in [SITES.md](SITES.md).
2023-10-02 22:41:45 +03:00
- `grab`: downloads a program from a specified source.
- `serve`: starts the [web server](https://github.com/vercel/serve).
- `lint`: сhecks the scripts for syntax errors.
- `test`: runs a test of all the scripts described above.