Skip to content

Commit 57c5e54

Browse files
committed
refactor: use TypeScript
1 parent 5b6a9f7 commit 57c5e54

18 files changed

+4485
-1739
lines changed

.github/workflows/ci.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,27 @@ jobs:
1515

1616
- name: Build service
1717
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

.gitignore

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

4-
config/
5-
xmltv/
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.22.1
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: 43 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,89 +3,67 @@
33
See [zap2xml](https://web.archive.org/web/20200426004001/zap2xml.awardspace.info/) for original Perl script and guidance
44
for the configuration file.
55

6-
## Docker
6+
## How to use
7+
8+
### Node.js
9+
10+
```bash
11+
npm i && npm run dev
12+
```
13+
14+
See below for configuration options.
15+
16+
### Docker
717

818
| Tag | Description |
9-
|---------|-------------------------|
19+
| ------- | ----------------------- |
1020
| latest | Stable zap2xml releases |
1121
| nightly | HEAD zap2xml release |
1222

13-
### docker-compose (recommended)
23+
#### docker-compose
1424

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

85-
### Notes
59+
### Command line arguments
8660

87-
- Configuration file values can be overridden by command line options
88-
- The configuration file supports comments (lines starting with `#`)
89-
- Empty lines are ignored
90-
- Values are trimmed of leading/trailing whitespace
91-
- Boolean options (like `outformat=xtvd`) are case-insensitive
61+
| Argument | Description | Type | Default |
62+
| -------------- | --------------------------------------------------------------------------------------------------------------- | ------- | -------------------------------- |
63+
| `--lineupId` | Lineup ID; You can find this at https://tvlistings.gracenote.com/grid-affiliates.html?aid=orbebb | String | `USA-lineupId-DEFAULT` (Attenna) |
64+
| `--timespan` | Either 3 or 6 hours of shows | Integer | 3 |
65+
| `--pref` | User Preferences, comma separated list. `m` for showing music, `p` for showing pay-per-view, `h` for showing HD | String | (empty) |
66+
| `--postalCode` | Postal code of where shows are available. | Integer | 30309 |
67+
| `--userAgent` | Custom user agent string for HTTP requests. | String | Uses random if not specified |
68+
| `--timezone` | Timezone | String | System default |
69+
| `--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)