Skip to content

Commit b056932

Browse files
authored
refactor: uses TypeScript, better API usage (#38)
1 parent 81ae3ac commit b056932

20 files changed

+4458
-1750
lines changed

.github/workflows/ci.yaml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,41 @@
11
name: Continuous Integration
2+
23
on:
34
pull_request:
45
branches:
56
- main
7+
68
jobs:
7-
build:
8-
name: Build
9+
build-docker:
10+
name: Build Docker
911
runs-on: ubuntu-latest
1012
steps:
1113
- name: Checkout repository
12-
uses: actions/checkout@v2
14+
uses: actions/checkout@v4
15+
1316
- name: Build service
1417
run: docker build .
18+
19+
build-lint-test:
20+
name: Build, Lint, and Test
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version-file: package.json
30+
31+
- name: Install dependencies
32+
run: npm ci
33+
34+
- name: Build
35+
run: npm run build
36+
37+
- name: Lint
38+
run: npm run lint
39+
40+
- name: Test
41+
run: npm run test:run
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"packages": {
3+
".": {
4+
"release-type": "simple",
5+
"package-name": "zap2xml"
6+
}
7+
}
8+
}

.github/workflows/release.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ jobs:
1414
uses: actions/checkout@v4
1515

1616
- name: Setup release please
17-
uses: google-github-actions/release-please-action@v2
17+
uses: googleapis/release-please-action@v4
1818
id: release
1919
with:
20-
token: ${{ secrets.GITHUB_TOKEN }}
21-
release-type: simple
22-
changelog-path: CHANGELOG.md
23-
package-name: zap2xml
20+
config-file: .github/workflows/release-please-config.json
2421

2522
- name: Login into GitHub Container Registry
2623
if: ${{ steps.release.outputs.release_created }}

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
.zap2xmlrc
1+
build/
2+
node_modules/
23

3-
config/
4-
xmltv/
4+
compose.yaml
5+
6+
xmltv.xml

.zap2xmlrc-example

Lines changed: 0 additions & 57 deletions
This file was deleted.

Dockerfile

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
FROM alpine:3.13.5
1+
FROM node:22.17.1-alpine3.22
22

3-
ENV SLEEPTIME=43200
3+
WORKDIR /app
44

5-
RUN apk add --no-cache \
6-
perl \
7-
perl-http-cookies \
8-
perl-lwp-useragent-determined \
9-
perl-json \
10-
perl-json-xs \
11-
perl-lwp-protocol-https \
12-
perl-gd
5+
COPY package.json package.json
6+
COPY package-lock.json package-lock.json
137

14-
WORKDIR /opt
8+
RUN npm ci
159

16-
COPY zap2xml.pl zap2xml.pl
10+
COPY tsconfig.json tsconfig.json
1711
COPY entrypoint.sh entrypoint.sh
12+
COPY src/ src/
1813

19-
ENTRYPOINT ["./entrypoint.sh"]
14+
RUN npm run build
15+
16+
RUN ls -l /app
17+
18+
ENTRYPOINT ["/bin/sh", "-c", "/app/entrypoint.sh"]

README.md

Lines changed: 46 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,68 @@
11
# zap2xml
22

3-
See [zap2xml](https://web.archive.org/web/20200426004001/zap2xml.awardspace.info/) for original Perl script and guidance for the configuration file.
3+
See [zap2xml](https://web.archive.org/web/20200426004001/zap2xml.awardspace.info/) for original Perl script and guidance
4+
for the configuration file.
45

5-
## Docker
6+
## How to use
7+
8+
### Retrieving your Lineup ID
9+
10+
Visit the [Retrieving Lineup ID](https://github.com/jef/zap2xml/wiki/Retrieving-Lineup-ID) in the Wiki.
11+
12+
### Node.js
13+
14+
```bash
15+
npm i && npm run dev
16+
```
17+
18+
See [Command line arguments](#command-line-arguments) for configuration options.
19+
20+
### Docker
621

722
| Tag | Description |
823
| ------- | ----------------------- |
924
| latest | Stable zap2xml releases |
1025
| nightly | HEAD zap2xml release |
1126

12-
### docker-compose (recommended)
27+
#### docker-compose
1328

1429
```yaml
1530
services:
1631
zap2xml:
1732
container_name: zap2xml
1833
image: ghcr.io/jef/zap2xml:latest
1934
environment:
20-
OPT_ARGS: >-
21-
-I -D -C /config/.zap2xmlrc -o /xmltv/xmltv.xml
22-
TZ: America/New_York # Consider using your timezone
35+
OUTPUT_FILE: /xmltv/xmltv.xml
2336
volumes:
24-
- /path/to/zap2xml/config:/config
25-
- /path/to/xmltv:/xmltv # nice for mapping other drives to this that may use xmltv.xml
37+
- ./xmltv:/xmltv
2638
restart: unless-stopped
2739
```
2840
41+
See [Environment variables](#environment-variables) for configuration options.
42+
2943
## Configuration
3044
31-
### Optional environment variables
32-
33-
| Variable | Description | Type | Default |
34-
| ------------ | ---------------------------------------------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
35-
| `USER_AGENT` | Custom user agent string for HTTP requests. | String | `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36` |
36-
| `SLEEPTIME` | Number of seconds to sleep between runs (useful for scheduling in Docker or cron). | Integer | `43200` |
37-
| `TZ` | Timezone for program times (affects output XML and Perl's time calculations). | String | System default |
38-
39-
### Optional run configurations
40-
41-
| Option | Type | Default | Description | Config File | Command Line |
42-
| ---------------- | --------- | ----------- | ------------------------------------------------------ | ----------------------------- | ------------ |
43-
| `start` | Integer | `0` | Number of days to offset from today for the start date | `start=1` | `-s` |
44-
| `days` | Integer | `7` | Number of days of program data to fetch | `days=14` | `-d` |
45-
| `retries` | Integer | `3` | Number of connection retries before failure (max 20) | `retries=5` | `-r` |
46-
| `user` | String | (empty) | Username/email for Zap2it account | `[email protected]` | `-u` |
47-
| `pass` | String | (empty) | Password for Zap2it account | `pass=mypassword` | `-p` |
48-
| `cache` | Directory | `cache` | Directory to store cached data files | `cache=/config/cache` | `-c` |
49-
| `ncdays` | Integer | `0` | Number of days from the end to not cache | `ncdays=2` | `-n` |
50-
| `ncsdays` | Integer | `0` | Number of days from the start to not cache | `ncsdays=1` | `-N` |
51-
| `ncmday` | Integer | `-1` | Specific day number to not cache (1-based) | `ncmday=3` | `-B` |
52-
| `outfile` | File path | `xmltv.xml` | Output XML file path | `outfile=/xmltv/xmltv.xml` | `-o` |
53-
| `outformat` | String | `xmltv` | Output format (xmltv/xtvd) | `outformat=xtvd` | `-x` |
54-
| `lang` | String | `en` | Language code for program data | `lang=es` | `-l` |
55-
| `icon` | Directory | (disabled) | Directory to store channel icons | `icon=/config/icons` | `-i` |
56-
| `trailer` | Directory | (disabled) | Directory to store movie trailers | `trailer=/config/trailers` | `-t` |
57-
| `proxy` | URL | (none) | HTTP proxy server URL | `proxy=http://localhost:8080` | `-P` |
58-
| `lineuptype` | String | (none) | Type of lineup (XTVD only) | `lineuptype=Cable` | - |
59-
| `lineupname` | String | (none) | Name of the lineup (XTVD only) | `lineupname=My Provider` | - |
60-
| `lineuplocation` | String | (none) | Location of the lineup (XTVD only) | `lineuplocation=New York, NY` | - |
61-
| `lineupid` | String | (none) | Lineup ID for TV Guide | `lineupid=X:80000` | `-Y` |
62-
| `postalcode` | String | (none) | Postal code for TV Guide | `postalcode=01010` | `-Z` |
63-
| `shiftMinutes` | Integer | `0` | Offset program times by minutes | - | `-m` |
64-
| `sleeptime` | Integer | `0` | Sleep between requests (seconds) | - | `-S` |
65-
| `allChan` | Boolean | `false` | Output all channels (not just favorites) | - | `-a` |
66-
| `outputXTVD` | Boolean | `false` | Force XTVD output format | - | `-x` |
67-
| `includeDetails` | Boolean | `false` | Include program details (extra requests) | - | `-D` |
68-
| `includeIcons` | Boolean | `false` | Include program icons (extra requests) | - | `-I` |
69-
| `retainOrder` | Boolean | `false` | Retain website channel order | - | `-b` |
70-
| `quiet` | Boolean | `false` | Quiet mode (no status output) | - | `-q` |
71-
| `wait` | Boolean | `false` | Wait on exit (require keypress) | - | `-w` |
72-
| `hexEncode` | Boolean | `false` | Hex encode HTML entities | - | `-e` |
73-
| `utf8` | Boolean | `false` | UTF-8 encoding (default: ISO-8859-1) | - | `-U` |
74-
| `liveTag` | Boolean | `false` | Output `<live />` tag | - | `-L` |
75-
| `noTBA` | Boolean | `false` | Don't cache files with "TBA" titles | - | `-T` |
76-
| `channelFirst` | Boolean | `false` | Output channel names first | - | `-F` |
77-
| `oldStyle` | Boolean | `false` | Use old tv_grab_na style channel IDs | - | `-O` |
78-
| `appendFlags` | String | (none) | Append flags to program titles | - | `-A` |
79-
| `copyYear` | Boolean | `false` | Copy movie_year to sub-title tags | - | `-M` |
80-
| `addSeries` | Boolean | `false` | Add "series" category to non-movies | - | `-j` |
81-
| `includeXMLTV` | File | (none) | Include XMLTV file in output | - | `-J` |
82-
| `useTVGuide` | Boolean | `false` | Use tvguide.com instead of gracenote.com | - | `-z` |
83-
84-
### Notes
85-
86-
- Configuration file values can be overridden by command line options
87-
- The configuration file supports comments (lines starting with `#`)
88-
- Empty lines are ignored
89-
- Values are trimmed of leading/trailing whitespace
90-
- Boolean options (like `outformat=xtvd`) are case-insensitive
45+
### Environment variables
46+
47+
| Variable | Description | Type | Default |
48+
| ------------- | --------------------------------------------------------------------------------------------------------------- | ------- | -------------------------------- |
49+
| `LINEUP_ID` | Lineup ID; You can find this at https://tvlistings.gracenote.com/grid-affiliates.html?aid=orbebb | String | `USA-lineupId-DEFAULT` (Attenna) |
50+
| `TIMESPAN` | Either 3 or 6 hours of shows | Integer | 3 |
51+
| `PREF` | User Preferences, comma separated list. `m` for showing music, `p` for showing pay-per-view, `h` for showing HD | String | (empty) |
52+
| `POSTAL_CODE` | Postal code of where shows are available. | Integer | 30309 |
53+
| `USER_AGENT` | Custom user agent string for HTTP requests. | String | Uses random if not specified |
54+
| `TZ` | Timezone | String | System default |
55+
| `SLEEP_TIME` | Sleep time before next run in seconds (default: 10800, Only used with Docker.) | Integer | 10800 |
56+
| `OUTPUT_FILE` | Output file name (default: xmltv.xml) | String | xmltv.xml |
57+
58+
### Command line arguments
59+
60+
| Argument | Description | Type | Default |
61+
| -------------- | --------------------------------------------------------------------------------------------------------------- | ------- | -------------------------------- |
62+
| `--lineupId` | Lineup ID; You can find this at https://tvlistings.gracenote.com/grid-affiliates.html?aid=orbebb | String | `USA-lineupId-DEFAULT` (Attenna) |
63+
| `--timespan` | Either 3 or 6 hours of shows | Integer | 3 |
64+
| `--pref` | User Preferences, comma separated list. `m` for showing music, `p` for showing pay-per-view, `h` for showing HD | String | (empty) |
65+
| `--postalCode` | Postal code of where shows are available. | Integer | 30309 |
66+
| `--userAgent` | Custom user agent string for HTTP requests. | String | Uses random if not specified |
67+
| `--timezone` | Timezone | String | System default |
68+
| `--outputFile` | Output file name (default: xmltv.xml) | String | xmltv.xml |

entrypoint.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/bin/sh
22

3+
SLEEP_TIME=${SLEEP_TIME:-10800}
4+
35
while true; do
4-
DATE=$(date)
5-
eval /opt/zap2xml.pl "$OPT_ARGS"
6-
echo "Last run time: $DATE"
7-
echo "Will run in $SLEEPTIME seconds"
8-
sleep "$SLEEPTIME"
6+
DATE=$(date)
7+
node build/src/index.js
8+
echo "Last run time: $DATE"
9+
echo "Will run in $((SLEEP_TIME / 60)) minutes"
10+
sleep "$SLEEP_TIME"
911
done

eslint.config.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @ts-check
2+
3+
import eslint from "@eslint/js";
4+
import tseslint from "typescript-eslint";
5+
import prettierConfig from "eslint-plugin-prettier/recommended";
6+
7+
export default tseslint.config(
8+
eslint.configs.recommended,
9+
tseslint.configs.strict,
10+
tseslint.configs.stylistic,
11+
prettierConfig,
12+
{
13+
ignores: ["build"],
14+
},
15+
);

0 commit comments

Comments
 (0)