Skip to content

Commit

Permalink
Merge pull request #6 from pooh-bear/channel-blocks
Browse files Browse the repository at this point in the history
feat(channel-blocks): add channel blocks func
  • Loading branch information
pooh-bear authored Mar 18, 2023
2 parents 99d905c + 3b8f838 commit 8b34e5c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# AU Freeview for Channels
> A Playlist & EPG proxy for Channels DVR
AU Freeview for Channels is what is says on the tin - intended for use with [Channels DVR](https://getchannels.com/dvr-server/), this Docker image is a Custom Channels provider, providing Playlist & EPG files that works out of the box with Channels.
Intended for use with [Channels DVR](https://getchannels.com/dvr-server/), this Docker image is a Custom Channels provider, providing Playlist & EPG files that works out of the box with Channels.

Inspired and built on by the efforts & resources of the legendary [Matt Huisman](https://www.matthuisman.nz), this proxies relevant files from `i.mjh.nz` and transmogrifies them to make them fully work with Channels DVR.

*NOTE*: This DOES NOT proxy the actual streaming feeds from the networks. You will need an Australian IP to access most of these channels.
**NOTE**: This DOES NOT proxy the actual streaming feeds from the networks. You will need an Australian IP to access most of these channels.

## Installation
Requires [Docker](http://docker.com).
Expand Down Expand Up @@ -62,20 +62,36 @@ Once you've spun up the service, add it to your Channels DVR as a Custom Channel

Check out your Guide; it should have your new Aussie Freeview channels!

### Channel Numbering
Channel numbers are prefixed, by default, that prefix is 1XXX (eg. for 7two, with an LCN of 72, it's 1072).
### Channel Numbering & Channel Number Blocks
By default, LCNs (Local Channel Numbers) are used for the numbering for the TVG.

You can change the prefix to your choosing by:
(TODO)
However, many Channels DVR users have several channel sources. In this case, the **Channel Number Blocks** setting may come in handy.

#### Channels without official LCNs (Local Channel Numbers)
Channel that don't have a provided LCN are added to the end of the "channel block", eg. the highest LCN is `99` presented as `1099`; the next non-LCN'd channel is `1101`.
When using Channel Number Blocks, you are able to essentially set a prefix for these channels, eg. setting a Channel Block of `1000` will add a prefix for 1XXX (eg. for 7two, with an LCN of 72, it's 1072).

You can enable/define the Channel Block using the `CHANNEL_NUMBER_BLOCK` environment variable, eg. `CHANNEL_NUMBER_BLOCK=2000`.

#### Channels without official LCNs
Channel that don't have a provided LCN are incremented to the end of the highest LCN.

**Not using Channel Number Blocks**: eg. the highest LCN is `99`, the next non-LCN'd channel is `101`.
**Using Channel Number Blocks**: eg. the highest LCN is `99` and is presented as `1099`, the next non-LCN'd channel is `1101`.

A future release will allow more granular control on how to specify particular channel numbers, eg. if you'd like to group the Channel Seven streaming channels under 1X7X.

### Pop-up/Non-linear Channels
Popup & non-linear channels, like channels with an MJH channel prefix of `mjh-7-cas` and `mjh-abc-90-seconds`, are not included in the channel list by default. To re-include them, or to add additional prefixes to exclude:
(TODO)
Popup & non-linear channels, like channels with an MJH channel prefix of `mjh-7-cas` and `mjh-abc-90-seconds`, are not included in the channel list by default.

**To re-include them**: Define the `DISABLE_EXCLUSIONS` environment variable as `TRUE`.
**To re-specify excluded channels**: Define the `EXCLUDE_CHANNELS_PREFIXES` environment variable with the prefixes, separated by a comma, eg. `EXCLUDE_CHANNELS_PREFIXES=mjh-7-cas,mjh-abc-90-seconds,mjh-another-example`.

## Contributing
All contributions are certainly welcome & appreciated! Simply branch & submit a Pull Request.
All contributions are certainly welcome & appreciated! Simply branch & submit a Pull Request.

### Start development environment
```
git clone https://github.com/pooh-bear/au-freeview-for-channels.git
cd au-freeview-for-channels
yarn
yarn dev
```
38 changes: 28 additions & 10 deletions src/controllers/playlist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import fetch from "node-fetch";

const exclude_channels_prefix = ['mjh-7-cas', 'mjh-abc-90-seconds'];
const disableExclusions = process.env.DISABLE_EXCLUSIONS && String(process.env.DISABLE_EXCLUSIONS.toLowerCase) === 'true';
const excludePrefixes = process.env.EXCLUDE_CHANNELS_PREFIXES ? process.env.EXCLUDE_CHANNELS_PREFIXES.split(',') : ['mjh-7-cas', 'mjh-abc-90-seconds'];

const channelBlock = process.env.CHANNEL_NUMBER_BLOCK ? Number(process.env.CHANNEL_NUMBER_BLOCK) : null;

interface M3u8Entry {
url: string;
Expand Down Expand Up @@ -68,7 +71,6 @@ function parseM3u8(m3u8String: string): M3u8Entry[] {
}

function addChannelNumber(data: M3u8Entry[]): void {
let prefix = 1;
const channelMap: Record<string, string> = {};
let count = 1;
let unknownChNumberCount = 1;
Expand Down Expand Up @@ -99,23 +101,39 @@ function addChannelNumber(data: M3u8Entry[]): void {

knownChIdx.forEach(idx => {
let entry = data[idx];
const chNum = prefix + String(entry['tvg-chno']).padStart(calculatedHighestChannelNumber.toString().length, '0');
entry.channel_number = chNum;
entry['tvg-chno'] = String(chNum);

if (channelBlock) {
let blockLength = String(channelBlock).length;
if (blockLength < String(calculatedHighestChannelNumber).length) {
blockLength = String(calculatedHighestChannelNumber).length;
}

entry.channel_number = entry['tvg-chno'] = String(Number(String(entry['tvg-chno']).padStart(blockLength, '0')) + channelBlock);
} else {
entry.channel_number = entry['tvg-chno'];
}
});

unknownChIdx.forEach((aidx, idx) => {
let entry = data[aidx];
const chNum = prefix + String(highestChannelNumber + (idx + 1)).padStart(calculatedHighestChannelNumber.toString().length, '0');
entry.channel_number = chNum;
entry['tvg-chno'] = String(chNum);

if (channelBlock) {
let blockLength = String(channelBlock).length;
if (blockLength < String(calculatedHighestChannelNumber).length) {
blockLength = String(calculatedHighestChannelNumber).length;
}

entry.channel_number = entry['tvg-chno'] = String(Number(String(highestChannelNumber + (idx + 1)).padStart(blockLength, '0')) + channelBlock);
} else {
entry.channel_number = entry['tvg-chno'] = String(highestChannelNumber + idx + 1);

}
});

}

function createM3u8Entry(entry: M3u8Entry, childNodeBase?: string): string {
const excludeIds = exclude_channels_prefix;
if (excludeIds.some(id => String(entry['tvg-id']).startsWith(id))) {
if (!disableExclusions && excludePrefixes.some(id => String(entry['tvg-id']).startsWith(id))) {
return '';
}

Expand Down

0 comments on commit 8b34e5c

Please sign in to comment.