Eerste versie: IPTV-app met zenderfilter, tv-gids en eigen Homebrew-bron
This commit is contained in:
26 files changed
+1740
No files matched your search
@@ -0,0 +1,105 @@
|
||||
/* Zenders ophalen: M3U-afspeellijst of Xtream Codes-API. Alleen live-tv, geen films/series. */
|
||||
(function (App) {
|
||||
'use strict';
|
||||
|
||||
function chKey(c) { return c.tvgId ? 'id:' + c.tvgId.toLowerCase() : 'nm:' + App.normName(c.name) + '|' + (c.group || ''); }
|
||||
App.chKey = chKey;
|
||||
|
||||
/* Zet een M3U-tekst om naar { epgUrl, channels[] } */
|
||||
App.parseM3U = function (text) {
|
||||
var lines = text.split(/\r?\n/);
|
||||
var out = [], epgUrl = '', cur = null, grp = '';
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var line = lines[i].trim();
|
||||
if (!line) continue;
|
||||
if (line.indexOf('#EXTM3U') === 0) {
|
||||
var m = /(?:x-tvg-url|url-tvg)="([^"]+)"/.exec(line);
|
||||
if (m) epgUrl = m[1].split(',')[0].trim();
|
||||
} else if (line.indexOf('#EXTINF') === 0) {
|
||||
var attrs = {}, re = /([\w-]+)="([^"]*)"/g, a;
|
||||
while ((a = re.exec(line)) !== null) attrs[a[1].toLowerCase()] = a[2];
|
||||
var comma = line.lastIndexOf('",');
|
||||
var name = comma >= 0 ? line.slice(comma + 2) : line.slice(line.indexOf(',') + 1);
|
||||
cur = {
|
||||
name: (name || attrs['tvg-name'] || '').trim(),
|
||||
tvgId: (attrs['tvg-id'] || '').trim(),
|
||||
logo: attrs['tvg-logo'] || '',
|
||||
group: attrs['group-title'] || ''
|
||||
};
|
||||
} else if (line.indexOf('#EXTGRP:') === 0) {
|
||||
grp = line.slice(8).trim();
|
||||
} else if (line.charAt(0) !== '#') {
|
||||
if (cur) {
|
||||
cur.url = line;
|
||||
if (!cur.group) cur.group = grp || 'Overig';
|
||||
if (!/\/(movie|series)\//i.test(line) && !/\.(mp4|mkv|avi)(\?|$)/i.test(line)) {
|
||||
cur.key = chKey(cur);
|
||||
out.push(cur);
|
||||
}
|
||||
}
|
||||
cur = null; grp = '';
|
||||
}
|
||||
}
|
||||
return { epgUrl: epgUrl, channels: dedupe(out) };
|
||||
};
|
||||
|
||||
/* Twee zenders met dezelfde sleutel krijgen een volgnummer, zodat ze apart te kiezen zijn */
|
||||
function dedupe(list) {
|
||||
var seen = {};
|
||||
list.forEach(function (c) {
|
||||
if (seen[c.key]) { seen[c.key]++; c.key = c.key + '#' + seen[c.key]; } else seen[c.key] = 1;
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
function trimSlash(s) { return String(s || '').trim().replace(/\/+$/, ''); }
|
||||
|
||||
App.xtreamEpgUrl = function (cfg) {
|
||||
return trimSlash(cfg.server) + '/xmltv.php?username=' + encodeURIComponent(cfg.user) +
|
||||
'&password=' + encodeURIComponent(cfg.pass);
|
||||
};
|
||||
|
||||
/* Xtream Codes: live-categorieën en -zenders via player_api.php (veel kleiner dan de m3u_plus-lijst) */
|
||||
App.loadXtream = function (cfg) {
|
||||
var base = trimSlash(cfg.server);
|
||||
if (!/^https?:\/\//i.test(base)) base = 'http://' + base;
|
||||
var api = base + '/player_api.php?username=' + encodeURIComponent(cfg.user) + '&password=' + encodeURIComponent(cfg.pass);
|
||||
var ext = cfg.output === 'ts' ? 'ts' : 'm3u8';
|
||||
return App.fetchText(api, 30000).then(function (t) {
|
||||
var info = JSON.parse(t);
|
||||
if (info && info.user_info && String(info.user_info.auth) === '0') throw new Error('Inloggen geweigerd: controleer gebruikersnaam en wachtwoord.');
|
||||
return Promise.all([
|
||||
App.fetchText(api + '&action=get_live_categories', 60000),
|
||||
App.fetchText(api + '&action=get_live_streams', 120000)
|
||||
]);
|
||||
}).then(function (res) {
|
||||
var cats = {}, list = [];
|
||||
(JSON.parse(res[0]) || []).forEach(function (c) { cats[c.category_id] = c.category_name; });
|
||||
(JSON.parse(res[1]) || []).forEach(function (s) {
|
||||
var c = {
|
||||
name: String(s.name || '').trim(),
|
||||
tvgId: String(s.epg_channel_id || '').trim(),
|
||||
logo: s.stream_icon || '',
|
||||
group: cats[s.category_id] || 'Overig',
|
||||
url: base + '/live/' + encodeURIComponent(cfg.user) + '/' + encodeURIComponent(cfg.pass) + '/' + s.stream_id + '.' + ext
|
||||
};
|
||||
c.key = 'xt:' + s.stream_id;
|
||||
list.push(c);
|
||||
});
|
||||
return { epgUrl: App.xtreamEpgUrl(cfg), channels: list };
|
||||
});
|
||||
};
|
||||
|
||||
/* Haal de volledige lijst op volgens de instellingen */
|
||||
App.loadSource = function (cfg) {
|
||||
if (cfg.type === 'xtream') {
|
||||
if (!cfg.server || !cfg.user) return Promise.reject(new Error('Vul server, gebruikersnaam en wachtwoord in.'));
|
||||
return App.loadXtream(cfg);
|
||||
}
|
||||
if (!cfg.m3u) return Promise.reject(new Error('Vul de M3U-URL in.'));
|
||||
return App.fetchText(cfg.m3u, 120000).then(function (t) {
|
||||
if (t.indexOf('#EXTINF') < 0) throw new Error('Dit lijkt geen M3U-afspeellijst te zijn.');
|
||||
return App.parseM3U(t);
|
||||
});
|
||||
};
|
||||
})(window.App);
|
||||
Reference in new issue
Block a user