Skip to content

Commit

Permalink
V2.2.0 - channels.csv, hibakezelések, id-k átfordítása
Browse files Browse the repository at this point in the history
  • Loading branch information
szabbenjamin committed Apr 24, 2020
1 parent aadfee6 commit 19b8bb3
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 6 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ log/
package-lock.json
channels_IPTV.m3u8
channels_tvheadend.m3u8
channels.csv
epg.xml
epg.timestamp
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ log/
package-lock.json
channels_IPTV.m3u8
channels_tvheadend.m3u8
channels.csv
epg.timestamp
epg.xml
digionline.sh
digionline.service
digionline.service
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ Telepítési segédlet Ubuntu 18.04 rendszerre: [Wiki](https://github.com/szabbe

**Frissítések**

V2.2.0

Stabilitással és új funkciókkal kapcsolatos kiadás

- channels.csv generálása, hogy ha szükséged van rá olvashatóbb, feldolgozhatóbb csatornalistát kapj

- Kezelje le a program ha egy digionline rendszerében nem létező csatornát akarok lekérni és az eredeti oldal 404-et dob

- Elérhető fájlok/források URL-je a könnyebb kezdéshez, illetve eligazodáshoz konzolon indításkor

- Mivel változott a digionline csatornák ID-ja (számozása), így akik nem a dinamikusan frissülő IPTV m3u8 fájlt használják hanem például tvheadend-et azoknak készült egy fordító, hogy a régi ID-t meghívva annak megfelelő új párjára kerüljön átfordításra. A régi-új párokat a helpers/pairs.json fájl tartalmazza.

V2.1.4

- Biztonsági javítások
Expand Down
1 change: 1 addition & 0 deletions helpers/pairs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"o":42,"n":243},{"o":10,"n":244},{"o":34,"n":245},{"o":7,"n":246},{"o":12,"n":247},{"o":26,"n":248},{"o":27,"n":249},{"o":131,"n":250},{"o":1,"n":251},{"o":203,"n":252},{"o":43,"n":253},{"o":44,"n":254},{"o":205,"n":255},{"o":210,"n":256},{"o":206,"n":257},{"o":232,"n":258},{"o":32,"n":259},{"o":2,"n":260},{"o":45,"n":261},{"o":211,"n":262},{"o":212,"n":263},{"o":213,"n":264},{"o":227,"n":265},{"o":39,"n":266},{"o":40,"n":267},{"o":41,"n":268},{"o":132,"n":269},{"o":226,"n":270},{"o":214,"n":271},{"o":228,"n":272},{"o":5,"n":274},{"o":220,"n":276},{"o":222,"n":278},{"o":207,"n":281},{"o":35,"n":282},{"o":225,"n":284},{"o":219,"n":285},{"o":29,"n":286},{"o":234,"n":287},{"o":130,"n":288},{"o":126,"n":289},{"o":118,"n":290},{"o":208,"n":291},{"o":235,"n":292},{"o":215,"n":295},{"o":23,"n":296},{"o":204,"n":297},{"o":4,"n":298},{"o":21,"n":299},{"o":216,"n":300}]
16 changes: 14 additions & 2 deletions lib/digionline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Reszletek: https://github.com/szabbenjamin/digionline/issues/25
this.checkLoggedIn(loggedIn => {
if (loggedIn) {
Log.write(`Logged in: ${CONFIG.login.email}`);
this.donateMeMsg();
}
else {
Log.error(`Sikertelen belepes (helyes a felhasznalonev es jelszo?)`, '1');
Expand Down Expand Up @@ -175,8 +176,8 @@ Reszletek: https://github.com/szabbenjamin/digionline/issues/25
private generateChannelList() : void {
Log.write('Generating channel list...', '.m3u8');
let simpleIPTVList = `#EXTM3U tvg-shift="${Common.getStaticTimeZoneOffset()}"\n`,
tvheadendList = simpleIPTVList;

tvheadendList = simpleIPTVList,
csv = 'ID;Channel name;Category;Stream URL;Channel logo URL\n';

this.channelList.forEach(channel => {
const header = `#EXTINF:-${channel.id} tvg-id="id${channel.id}" tvg-name="${channel.name}" tvg-logo="${channel.logoUrl}" group-title="${channel.category}", ${channel.name} \n`,
Expand All @@ -189,10 +190,13 @@ Reszletek: https://github.com/szabbenjamin/digionline/issues/25
// for TVHeadend
tvheadendList += header;
tvheadendList += `pipe:///usr/bin/ffmpeg -i ${url} -c copy -f mpegts pipe:1\n`;

csv += `${channel.id};${channel.name};${channel.category};${url};${channel.logoUrl}\n`;
});

FileHandler.writeFile('channels_IPTV.m3u8', simpleIPTVList);
FileHandler.writeFile('channels_tvheadend.m3u8', tvheadendList);
FileHandler.writeFile('channels.csv', csv);

Log.write('Channel list ready.');
}
Expand Down Expand Up @@ -226,6 +230,11 @@ Reszletek: https://github.com/szabbenjamin/digionline/issues/25
const playlistBaseUrl = "https://online.digi.hu/api/streams/playlist/";
const playlistExtension = ".m3u8";

if (response.indexOf('404 - Tartalom nem található') !== -1) {
Log.error('Channel id is not found.');
return;
}

let playlistSplit = response.split(playlistBaseUrl);
if (playlistSplit.length < 2) {
Log.write("Unexpected response! Are we logged in?");
Expand Down Expand Up @@ -320,7 +329,10 @@ Reszletek: https://github.com/szabbenjamin/digionline/issues/25
Log.write(`loaded from cache`, channelKey);
loadChannel(this.player[channelKey].response);
}
}

private donateMeMsg() : void {
console.log('@\n@\n@\n@\n@ Ha támogatni szeretnéd a munkámat (vagy meg szeretnél hívni egy sörre, kávéra) Paypal-on van erre lehetőséged: https://paypal.me/dicsportal\n@\n@\n@');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Log {
}

public static error (...input) : void {
Log.write(`################# FATAL (${input[1]}) #############`);
Log.write(`################# FATAL ERROR #############`);
Log.write(...input);
setTimeout(() => {
process.exit();
Expand Down
59 changes: 57 additions & 2 deletions lib/webconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import Common from "./common";
class Webconnect {
private digi : Digionline;
private server : any;
private translations : {oldIds : Array<number>, pairs : Array<{o : number, n : number}>};

public constructor() {
const filesAllowed = [
'/channels_IPTV.m3u8',
'/channels_tvheadend.m3u8',
'/epg.xml'
'/epg.xml',
'/channels.csv'
];

this.server = http.createServer((request, response) => {
Expand All @@ -30,6 +32,17 @@ class Webconnect {
response.end();
}
});

this.showServices(filesAllowed);

this.translations = this.initTranslate();
}

private showServices (filesAllowed : Array<string>) : void {
Log.write('===Elerheto csatornalista formatumok kulso lejatszokhoz===');
for (let file of filesAllowed) {
Log.write(`http://${CONFIG.webconnect.domain}:${CONFIG.webconnect.port}${file}`);
}
}

public listen() : void {
Expand All @@ -47,7 +60,17 @@ class Webconnect {

private getChannel(get : string, response : any) : void {
const self = this;
const id : number = Number(get.replace('/channel/', '').replace('.m3u8', ''));
let id : number = Number(get.replace('/channel/', '').replace('.m3u8', ''));

Log.write(`GET channel ${id}`);

// ha olyan ID-t kap ami még egy régi rendszerezésből származik át kell forgatnunk az új ID-ra
if (this.translations.oldIds.indexOf(id) !== -1) {
Log.write('Ez egy regi rendszeru ID, frissitsd a listadat!');
let oldId = id;
id = this.getNewId(id);
Log.write(`Regi-uj ID atforgatas sikeres. oldId: ${oldId}, newId: ${id}`);
}

this.digi.getChannel(id, channel => {
const channelUrl = channel.url.replace('https', 'http');
Expand Down Expand Up @@ -75,6 +98,38 @@ class Webconnect {
response.write(fileContent);
response.end();
}

/**
* Mivel megváltoztak a csatorna id-k így készült egy eljárás arra az esetre, hogy a régieket az új id-ra forgassa át
* Hasznos abban az esetben ha tvheadend-ben nem kívánjuk az összes csatornát egyesével átírkálni (én nem kívántam)
*/
private initTranslate() : {oldIds : Array<number>, pairs : Array<{o : number, n : number}>} {
const oldIds = [],
pairs = FileHandler.readJsonFile('helpers/pairs.json') as Array<{o : number, n : number}>;

for (let row of pairs) {
oldIds.push(row.o);
}

return {
oldIds: oldIds,
pairs: pairs
}
}

private getNewId(oldId : number) : number {
if (this.translations.pairs.length === 0) {
throw new Error('Pairs array is empty');
}

for (let row of this.translations.pairs) {
if (row.o === oldId) {
return row.n;
}
}

throw new Error('oldId not exist');
}
}

export default Webconnect;

0 comments on commit 19b8bb3

Please sign in to comment.