wyzie-lib 2.0.7 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -88
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Wyzie Lib is a package made for easily implementing [Wyzie Subs](https://sub.wyzie.ru) into your
|
|
4
4
|
project without all the fuss. [Read our source code!](https://github.com/itzcozi/wyzie-lib)
|
|
5
5
|
|
|
6
|
-
<sup>
|
|
6
|
+
<sup>New VTT Parser!</sup>
|
|
7
7
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
@@ -34,32 +34,32 @@ yarn add wyzie-lib
|
|
|
34
34
|
## Usage
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
|
-
import { type SubtitleData, searchSubtitles } from "wyzie-lib";
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
import { type SubtitleData, searchSubtitles, parseToVTT } from "wyzie-lib";
|
|
38
|
+
|
|
39
|
+
const params = { tmdb_id: 286217 };
|
|
40
|
+
|
|
41
|
+
// Fetches all subtitles for the media with the TMDB ID 286217
|
|
42
|
+
// -----------------------------------------------------------
|
|
43
|
+
const data: SubtitleData[] = await searchSubtitles(params);
|
|
44
|
+
console.log(data[0].id); // Prints the ID of the first subtitle object
|
|
45
|
+
|
|
46
|
+
// Converts the first subtitle to VTT format using the previous parameters provided
|
|
47
|
+
// --------------------------------------------------------------------------------
|
|
48
|
+
const vttContent = await parseToVTT(params, 0); // Use the first subtitle URL for convenience
|
|
49
|
+
console.log(vttContent); // Prints the raw VTT content
|
|
49
50
|
```
|
|
50
51
|
|
|
51
52
|
### Parameters
|
|
52
53
|
|
|
53
|
-
| Parameter
|
|
54
|
-
|
|
|
55
|
-
| **tmdb_id** - _number_
|
|
56
|
-
| **imdb_id** - _number_
|
|
57
|
-
| **format** - _string_
|
|
58
|
-
| **season** - _number_
|
|
59
|
-
| **episode** - _number_
|
|
60
|
-
| **language** - _string_
|
|
61
|
-
| **hi** - _boolean_
|
|
62
|
-
| **parseVTT** - _boolean_ | parseVTT | Parse and return the first subtitle in VTT format. |
|
|
54
|
+
| Parameter | Name | Description |
|
|
55
|
+
| ----------------------- | ----------------- | ----------------------------------------------------------------------------------------- |
|
|
56
|
+
| **tmdb_id** - _number_ | TmdbId | The TMDB ID of the movie or TV show. _(tmdb_id or imdb_id is required)_ |
|
|
57
|
+
| **imdb_id** - _number_ | ImdbId | The IMDB ID of the movie or TV show. _(imdb_id or tmdb_id is required)_ |
|
|
58
|
+
| **format** - _string_ | format | The file format of the subtitles returned. _(srt, ass, vtt, txt, sub, mpl, webvtt, dfxp)_ |
|
|
59
|
+
| **season** - _number_ | season | Disired season of subtites _(this requires episode parameter aswell)_ |
|
|
60
|
+
| **episode** - _number_ | episode | The episode of the given season. |
|
|
61
|
+
| **language** - _string_ | language | The ISO 3166 code of the provided subtitles. |
|
|
62
|
+
| **hi** - _boolean_ | isHearingImpaired | A boolean indicating if the subtitles are hearing impaired. |
|
|
63
63
|
|
|
64
64
|
### Types
|
|
65
65
|
|
|
@@ -70,84 +70,38 @@ console.log(vttContent); // Prints the VTT formatted subtitle content
|
|
|
70
70
|
```ts
|
|
71
71
|
interface SearchSubtitlesParams {
|
|
72
72
|
// Parameters for the searchSubtitles() function
|
|
73
|
-
tmdb_id?: number;
|
|
74
|
-
imdb_id?: number;
|
|
73
|
+
tmdb_id?: number; // Parsed automatically by the API to recognize if its TMDB or IMDB
|
|
74
|
+
imdb_id?: number; // Parsed automatically by the API to recognize if its TMDB or IMDB
|
|
75
75
|
season?: number;
|
|
76
|
-
episode?: number;
|
|
77
|
-
language?: string;
|
|
78
|
-
format?: string;
|
|
79
|
-
hi?: boolean;
|
|
76
|
+
episode?: number; // Season is required if episode is provided
|
|
77
|
+
language?: string; // ISO 3166 code
|
|
78
|
+
format?: string; // Subtitle file format
|
|
79
|
+
hi?: boolean; // If the subtitle is hearing impaired
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
interface QueryParams {
|
|
83
83
|
// Parameters for the wyzie-subs API
|
|
84
|
-
id: string;
|
|
85
|
-
season?: number;
|
|
86
|
-
episode?: number;
|
|
87
|
-
language?: string;
|
|
88
|
-
format?: string;
|
|
89
|
-
hi?: boolean;
|
|
84
|
+
id: string; // (Required) The TMDB or IMDB ID of the movie or TV show
|
|
85
|
+
season?: number; // The season of the TV show (Required if episode is provided)
|
|
86
|
+
episode?: number; // The episode of the TV show (Required if season is provided)
|
|
87
|
+
language?: string; // ISO 3166 code
|
|
88
|
+
format?: string; // Subtitle file format
|
|
89
|
+
hi?: boolean; // If the subtitle is hearing impaired
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
type SubtitleData = {
|
|
93
93
|
// Data returned by the API
|
|
94
|
-
id: string;
|
|
95
|
-
url: string;
|
|
96
|
-
format: string;
|
|
94
|
+
id: string; // Unique ID of the subtitle from opensubtitles
|
|
95
|
+
url: string; // Direct download link of the subtitle
|
|
96
|
+
format: string; // Subtitle file format
|
|
97
97
|
isHearingImpaired: boolean; // If the subtitle is hearing impaired
|
|
98
|
-
flagUrl: string;
|
|
99
|
-
media: string;
|
|
100
|
-
display: string;
|
|
101
|
-
language: string;
|
|
98
|
+
flagUrl: string; // Flag of the language
|
|
99
|
+
media: string; // Media name of the subtitle
|
|
100
|
+
display: string; // Actual name of the language
|
|
101
|
+
language: string; // ISO 3166 code
|
|
102
102
|
};
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
### VTT Parsing Features
|
|
106
|
-
|
|
107
|
-
The VTT parser now includes several improvements for handling subtitle files:
|
|
108
|
-
|
|
109
|
-
- **Robust Format Handling**: Automatically handles both SRT and VTT input formats
|
|
110
|
-
- **Timestamp Normalization**: Converts all timestamps to WebVTT format (HH:MM:SS.mmm)
|
|
111
|
-
- **Smart Block Processing**:
|
|
112
|
-
- Maintains proper spacing between subtitle blocks
|
|
113
|
-
- Removes subtitle numbers
|
|
114
|
-
- Handles multi-line subtitles
|
|
115
|
-
- Preserves text formatting
|
|
116
|
-
- **Error Handling**: Gracefully handles malformed input and network errors
|
|
117
|
-
|
|
118
|
-
Example VTT output:
|
|
119
|
-
|
|
120
|
-
```vtt
|
|
121
|
-
WEBVTT
|
|
122
|
-
|
|
123
|
-
00:02:05.872 --> 00:02:08.024
|
|
124
|
-
All right, team,
|
|
125
|
-
stay in sight of each other.
|
|
126
|
-
|
|
127
|
-
00:02:08.124 --> 00:02:10.484
|
|
128
|
-
Let's make NASA proud today.
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
### Error Handling
|
|
132
|
-
|
|
133
|
-
The library provides detailed error messages for common issues:
|
|
134
|
-
|
|
135
|
-
```ts
|
|
136
|
-
try {
|
|
137
|
-
const { subtitles, vttContent } = await searchSubtitles({
|
|
138
|
-
tmdb_id: 286217,
|
|
139
|
-
parseVTT: true,
|
|
140
|
-
});
|
|
141
|
-
} catch (error) {
|
|
142
|
-
// Handles various error cases:
|
|
143
|
-
// - Network errors
|
|
144
|
-
// - Invalid subtitle format
|
|
145
|
-
// - Missing required parameters
|
|
146
|
-
// - API errors
|
|
147
|
-
console.error(error);
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
105
|
<hr />
|
|
152
106
|
|
|
153
107
|
<sup>
|