refactor!: uses TypeScript, better API usage (#38)

This commit is contained in:
Jef LeCompte
2025-07-18 20:35:06 -07:00
parent 81ae3ac3f6
commit fb28b7d6e6
20 changed files with 4455 additions and 1747 deletions

108
README.md
View File

@@ -1,15 +1,30 @@
# zap2xml
See [zap2xml](https://web.archive.org/web/20200426004001/zap2xml.awardspace.info/) for original Perl script and guidance for the configuration file.
See [zap2xml](https://web.archive.org/web/20200426004001/zap2xml.awardspace.info/) for original Perl script and guidance
for the configuration file.
## Docker
## How to use
### Retrieving your Lineup ID
Visit the [Retrieving Lineup ID](https://github.com/jef/zap2xml/wiki/Retrieving-Lineup-ID) in the Wiki.
### Node.js
```bash
npm i && npm run dev
```
See [Command line arguments](#command-line-arguments) for configuration options.
### Docker
| Tag | Description |
| ------- | ----------------------- |
| latest | Stable zap2xml releases |
| nightly | HEAD zap2xml release |
### docker-compose (recommended)
#### docker-compose
```yaml
services:
@@ -17,74 +32,37 @@ services:
container_name: zap2xml
image: ghcr.io/jef/zap2xml:latest
environment:
OPT_ARGS: >-
-I -D -C /config/.zap2xmlrc -o /xmltv/xmltv.xml
TZ: America/New_York # Consider using your timezone
OUTPUT_FILE: /xmltv/xmltv.xml
volumes:
- /path/to/zap2xml/config:/config
- /path/to/xmltv:/xmltv # nice for mapping other drives to this that may use xmltv.xml
- ./xmltv:/xmltv
restart: unless-stopped
```
See [Environment variables](#environment-variables) for configuration options.
## Configuration
### Optional environment variables
### Environment variables
| Variable | Description | Type | Default |
| ------------ | ---------------------------------------------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
| `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` |
| `SLEEPTIME` | Number of seconds to sleep between runs (useful for scheduling in Docker or cron). | Integer | `43200` |
| `TZ` | Timezone for program times (affects output XML and Perl's time calculations). | String | System default |
| Variable | Description | Type | Default |
| ------------- | --------------------------------------------------------------------------------------------------------------- | ------- | -------------------------------- |
| `LINEUP_ID` | Lineup ID; You can find this at https://tvlistings.gracenote.com/grid-affiliates.html?aid=orbebb | String | `USA-lineupId-DEFAULT` (Attenna) |
| `TIMESPAN` | Either 3 or 6 hours of shows | Integer | 3 |
| `PREF` | User Preferences, comma separated list. `m` for showing music, `p` for showing pay-per-view, `h` for showing HD | String | (empty) |
| `POSTAL_CODE` | Postal code of where shows are available. | Integer | 30309 |
| `USER_AGENT` | Custom user agent string for HTTP requests. | String | Uses random if not specified |
| `TZ` | Timezone | String | System default |
| `SLEEP_TIME` | Sleep time before next run in seconds (default: 10800, Only used with Docker.) | Integer | 10800 |
| `OUTPUT_FILE` | Output file name (default: xmltv.xml) | String | xmltv.xml |
### Optional run configurations
### Command line arguments
| Option | Type | Default | Description | Config File | Command Line |
| ---------------- | --------- | ----------- | ------------------------------------------------------ | ----------------------------- | ------------ |
| `start` | Integer | `0` | Number of days to offset from today for the start date | `start=1` | `-s` |
| `days` | Integer | `7` | Number of days of program data to fetch | `days=14` | `-d` |
| `retries` | Integer | `3` | Number of connection retries before failure (max 20) | `retries=5` | `-r` |
| `user` | String | (empty) | Username/email for Zap2it account | `user=myemail@example.com` | `-u` |
| `pass` | String | (empty) | Password for Zap2it account | `pass=mypassword` | `-p` |
| `cache` | Directory | `cache` | Directory to store cached data files | `cache=/config/cache` | `-c` |
| `ncdays` | Integer | `0` | Number of days from the end to not cache | `ncdays=2` | `-n` |
| `ncsdays` | Integer | `0` | Number of days from the start to not cache | `ncsdays=1` | `-N` |
| `ncmday` | Integer | `-1` | Specific day number to not cache (1-based) | `ncmday=3` | `-B` |
| `outfile` | File path | `xmltv.xml` | Output XML file path | `outfile=/xmltv/xmltv.xml` | `-o` |
| `outformat` | String | `xmltv` | Output format (xmltv/xtvd) | `outformat=xtvd` | `-x` |
| `lang` | String | `en` | Language code for program data | `lang=es` | `-l` |
| `icon` | Directory | (disabled) | Directory to store channel icons | `icon=/config/icons` | `-i` |
| `trailer` | Directory | (disabled) | Directory to store movie trailers | `trailer=/config/trailers` | `-t` |
| `proxy` | URL | (none) | HTTP proxy server URL | `proxy=http://localhost:8080` | `-P` |
| `lineuptype` | String | (none) | Type of lineup (XTVD only) | `lineuptype=Cable` | - |
| `lineupname` | String | (none) | Name of the lineup (XTVD only) | `lineupname=My Provider` | - |
| `lineuplocation` | String | (none) | Location of the lineup (XTVD only) | `lineuplocation=New York, NY` | - |
| `lineupid` | String | (none) | Lineup ID for TV Guide | `lineupid=X:80000` | `-Y` |
| `postalcode` | String | (none) | Postal code for TV Guide | `postalcode=01010` | `-Z` |
| `shiftMinutes` | Integer | `0` | Offset program times by minutes | - | `-m` |
| `sleeptime` | Integer | `0` | Sleep between requests (seconds) | - | `-S` |
| `allChan` | Boolean | `false` | Output all channels (not just favorites) | - | `-a` |
| `outputXTVD` | Boolean | `false` | Force XTVD output format | - | `-x` |
| `includeDetails` | Boolean | `false` | Include program details (extra requests) | - | `-D` |
| `includeIcons` | Boolean | `false` | Include program icons (extra requests) | - | `-I` |
| `retainOrder` | Boolean | `false` | Retain website channel order | - | `-b` |
| `quiet` | Boolean | `false` | Quiet mode (no status output) | - | `-q` |
| `wait` | Boolean | `false` | Wait on exit (require keypress) | - | `-w` |
| `hexEncode` | Boolean | `false` | Hex encode HTML entities | - | `-e` |
| `utf8` | Boolean | `false` | UTF-8 encoding (default: ISO-8859-1) | - | `-U` |
| `liveTag` | Boolean | `false` | Output `<live />` tag | - | `-L` |
| `noTBA` | Boolean | `false` | Don't cache files with "TBA" titles | - | `-T` |
| `channelFirst` | Boolean | `false` | Output channel names first | - | `-F` |
| `oldStyle` | Boolean | `false` | Use old tv_grab_na style channel IDs | - | `-O` |
| `appendFlags` | String | (none) | Append flags to program titles | - | `-A` |
| `copyYear` | Boolean | `false` | Copy movie_year to sub-title tags | - | `-M` |
| `addSeries` | Boolean | `false` | Add "series" category to non-movies | - | `-j` |
| `includeXMLTV` | File | (none) | Include XMLTV file in output | - | `-J` |
| `useTVGuide` | Boolean | `false` | Use tvguide.com instead of gracenote.com | - | `-z` |
### Notes
- Configuration file values can be overridden by command line options
- The configuration file supports comments (lines starting with `#`)
- Empty lines are ignored
- Values are trimmed of leading/trailing whitespace
- Boolean options (like `outformat=xtvd`) are case-insensitive
| Argument | Description | Type | Default |
| -------------- | --------------------------------------------------------------------------------------------------------------- | ------- | -------------------------------- |
| `--lineupId` | Lineup ID; You can find this at https://tvlistings.gracenote.com/grid-affiliates.html?aid=orbebb | String | `USA-lineupId-DEFAULT` (Attenna) |
| `--timespan` | Either 3 or 6 hours of shows | Integer | 3 |
| `--pref` | User Preferences, comma separated list. `m` for showing music, `p` for showing pay-per-view, `h` for showing HD | String | (empty) |
| `--postalCode` | Postal code of where shows are available. | Integer | 30309 |
| `--userAgent` | Custom user agent string for HTTP requests. | String | Uses random if not specified |
| `--timezone` | Timezone | String | System default |
| `--outputFile` | Output file name (default: xmltv.xml) | String | xmltv.xml |