aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-07-26 10:10:25 +0000
committerFuwn <[email protected]>2024-07-26 10:15:02 +0000
commit2199fe9a0c318db29a61ddcd50289d9b0036c7f7 (patch)
tree54025c5b14c4dbd6dff676e4675a6c468bd549b1 /src/lib
downloadiptv-jp-browser-2199fe9a0c318db29a61ddcd50289d9b0036c7f7.tar.xz
iptv-jp-browser-2199fe9a0c318db29a61ddcd50289d9b0036c7f7.zip
feat: initial release
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/m3u.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/lib/m3u.ts b/src/lib/m3u.ts
new file mode 100644
index 0000000..e5138e0
--- /dev/null
+++ b/src/lib/m3u.ts
@@ -0,0 +1,36 @@
+export interface Channel {
+ groupTitle: string;
+ tvgId: string;
+ tvgLogo: string;
+ name: string;
+ url: string;
+}
+
+export const parseM3U = (m3uContent: string): Channel[] => {
+ const lines = m3uContent.split('\n');
+ const channels: Channel[] = [];
+ let currentChannel: Partial<Channel> = {};
+
+ for (const line of lines)
+ if (line.startsWith('#EXTINF')) {
+ const groupTitleMatch = line.match(/group-title="([^"]*)"/);
+ const tvgIdMatch = line.match(/tvg-id="([^"]*)"/);
+ const tvgLogoMatch = line.match(/tvg-logo="([^"]*)"/);
+ const nameMatch = line.match(/,([^,]*)$/);
+
+ currentChannel = {
+ groupTitle: groupTitleMatch ? groupTitleMatch[1].trim() : '',
+ tvgId: tvgIdMatch ? tvgIdMatch[1].trim() : '',
+ tvgLogo: tvgLogoMatch ? tvgLogoMatch[1].trim() : '',
+ name: nameMatch ? nameMatch[1].trim() : ''
+ };
+ } else if (line && !line.startsWith('#')) {
+ currentChannel.url = line.trim();
+
+ channels.push(currentChannel as Channel);
+
+ currentChannel = {};
+ }
+
+ return channels;
+};