mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-10 01:56:16 -08:00
feat: add support of specific user-agent and referer on channel level
This commit closes #57
This commit is contained in:
6 files changed
+56
-17
No files matched your search
@@ -1,11 +1,12 @@
|
|||||||
import { ParsedPlaylist } from './src/typings.d';
|
import { ParsedPlaylist } from './src/typings.d';
|
||||||
import { app, BrowserWindow, ipcMain } from 'electron';
|
import { app, BrowserWindow, ipcMain, session } from 'electron';
|
||||||
import { parse } from 'iptv-playlist-parser';
|
import { parse } from 'iptv-playlist-parser';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { guid } from '@datorama/akita';
|
import { guid } from '@datorama/akita';
|
||||||
import { Playlist, PlaylistUpdateState } from './playlist.interface';
|
import { Playlist, PlaylistUpdateState } from './playlist.interface';
|
||||||
import Nedb, { Cursor } from 'nedb-promises-ts';
|
import Nedb, { Cursor } from 'nedb-promises-ts';
|
||||||
import {
|
import {
|
||||||
|
CHANNEL_SET_USER_AGENT,
|
||||||
EPG_ERROR,
|
EPG_ERROR,
|
||||||
EPG_FETCH,
|
EPG_FETCH,
|
||||||
EPG_FETCH_DONE,
|
EPG_FETCH_DONE,
|
||||||
@@ -33,6 +34,9 @@ export class Api {
|
|||||||
/** Default user agent stored as a fallback value */
|
/** Default user agent stored as a fallback value */
|
||||||
defaultUserAgent: string;
|
defaultUserAgent: string;
|
||||||
|
|
||||||
|
/** Default referer url value */
|
||||||
|
defaultReferer: string;
|
||||||
|
|
||||||
/** Instance of the epg browser window */
|
/** Instance of the epg browser window */
|
||||||
workerWindow: BrowserWindow;
|
workerWindow: BrowserWindow;
|
||||||
|
|
||||||
@@ -190,6 +194,17 @@ export class Api {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ipcMain.on(
|
||||||
|
CHANNEL_SET_USER_AGENT,
|
||||||
|
(event, args: { userAgent: string; referer?: string }) => {
|
||||||
|
if (args.userAgent && args.referer) {
|
||||||
|
this.setUserAgent(args.userAgent, args.referer);
|
||||||
|
} else {
|
||||||
|
this.setUserAgent(this.defaultUserAgent, 'localhost');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
this.refreshPlaylists();
|
this.refreshPlaylists();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,12 +268,20 @@ export class Api {
|
|||||||
/**
|
/**
|
||||||
* Sets the user agent header for all http requests
|
* Sets the user agent header for all http requests
|
||||||
* @param userAgent user agent to use
|
* @param userAgent user agent to use
|
||||||
|
* @param referer referer to use
|
||||||
*/
|
*/
|
||||||
setUserAgent(userAgent: string): void {
|
setUserAgent(userAgent: string, referer?: string): void {
|
||||||
if (userAgent === undefined || userAgent === null || userAgent === '') {
|
if (userAgent === undefined || userAgent === null || userAgent === '') {
|
||||||
userAgent = this.defaultUserAgent;
|
userAgent = this.defaultUserAgent;
|
||||||
}
|
}
|
||||||
this.mainWindow.webContents.setUserAgent(userAgent);
|
|
||||||
|
session.defaultSession.webRequest.onBeforeSendHeaders(
|
||||||
|
(details, callback) => {
|
||||||
|
details.requestHeaders['User-Agent'] = userAgent;
|
||||||
|
details.requestHeaders['Referer'] = referer;
|
||||||
|
callback({ requestHeaders: details.requestHeaders });
|
||||||
|
}
|
||||||
|
);
|
||||||
console.log(`Success: Set "${userAgent}" as user agent header`);
|
console.log(`Success: Set "${userAgent}" as user agent header`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,3 +15,6 @@ export const PLAYLIST_UPDATE_RESPONSE = 'PLAYLIST:UPDATE_RESPONSE';
|
|||||||
// General
|
// General
|
||||||
export const SHOW_WHATS_NEW = 'SHOW_WHATS_NEW';
|
export const SHOW_WHATS_NEW = 'SHOW_WHATS_NEW';
|
||||||
export const ERROR = 'error';
|
export const ERROR = 'error';
|
||||||
|
|
||||||
|
// Channels
|
||||||
|
export const CHANNEL_SET_USER_AGENT = 'CHANNEL:SET_USER_AGENT';
|
||||||
Generated
+11
-12
@@ -22,7 +22,7 @@
|
|||||||
"custom-electron-titlebar": "3.2.5",
|
"custom-electron-titlebar": "3.2.5",
|
||||||
"epg-parser": "0.1.1",
|
"epg-parser": "0.1.1",
|
||||||
"hls.js": "0.14.16",
|
"hls.js": "0.14.16",
|
||||||
"iptv-playlist-parser": "git+https://github.com/4gray/iptv-playlist-parser.git",
|
"iptv-playlist-parser": "0.8.0",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
"material-icons": "0.3.1",
|
"material-icons": "0.3.1",
|
||||||
"moment": "2.29.1",
|
"moment": "2.29.1",
|
||||||
@@ -4259,7 +4259,6 @@
|
|||||||
"version": "11.1.2",
|
"version": "11.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/@angular/common/-/common-11.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/common/-/common-11.1.2.tgz",
|
||||||
"integrity": "sha512-/+tMeFikT55VgOnx30y6M/WTuSwUarehpKhJ9F61hLZBTzWAIWuaD5DODZVnZ7b15pwgEO8UWnfr4778HTQlTw==",
|
"integrity": "sha512-/+tMeFikT55VgOnx30y6M/WTuSwUarehpKhJ9F61hLZBTzWAIWuaD5DODZVnZ7b15pwgEO8UWnfr4778HTQlTw==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.0.0"
|
"tslib": "^2.0.0"
|
||||||
}
|
}
|
||||||
@@ -4477,7 +4476,6 @@
|
|||||||
"version": "11.1.2",
|
"version": "11.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/@angular/core/-/core-11.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/core/-/core-11.1.2.tgz",
|
||||||
"integrity": "sha512-5urIQTcRZ2hd9Q2JE0KQocjlIvuRdlrSGzxjf9OZbOuapXDNF0Sb3uEcVnt980NS7vw0Am5thVP9gDspS45c7Q==",
|
"integrity": "sha512-5urIQTcRZ2hd9Q2JE0KQocjlIvuRdlrSGzxjf9OZbOuapXDNF0Sb3uEcVnt980NS7vw0Am5thVP9gDspS45c7Q==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.0.0"
|
"tslib": "^2.0.0"
|
||||||
}
|
}
|
||||||
@@ -19901,9 +19899,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/iptv-playlist-parser": {
|
"node_modules/iptv-playlist-parser": {
|
||||||
"version": "0.6.0",
|
"version": "0.8.0",
|
||||||
"resolved": "git+ssh://git@github.com/4gray/iptv-playlist-parser.git#fbd5900e7c396df57eabad42194ff15267075e1b",
|
"resolved": "https://registry.npmjs.org/iptv-playlist-parser/-/iptv-playlist-parser-0.8.0.tgz",
|
||||||
"license": "MIT"
|
"integrity": "sha512-83+6Fl248rxm6tyzgPi2rqHQU1IBZnZvbWXyGAcBxveitckc+sh6b4+aDqQa+u2IJP2HVZilRd2C229kqJtLuQ=="
|
||||||
},
|
},
|
||||||
"node_modules/is-absolute-url": {
|
"node_modules/is-absolute-url": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
@@ -44366,7 +44364,6 @@
|
|||||||
"version": "11.1.2",
|
"version": "11.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/@angular/common/-/common-11.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/common/-/common-11.1.2.tgz",
|
||||||
"integrity": "sha512-/+tMeFikT55VgOnx30y6M/WTuSwUarehpKhJ9F61hLZBTzWAIWuaD5DODZVnZ7b15pwgEO8UWnfr4778HTQlTw==",
|
"integrity": "sha512-/+tMeFikT55VgOnx30y6M/WTuSwUarehpKhJ9F61hLZBTzWAIWuaD5DODZVnZ7b15pwgEO8UWnfr4778HTQlTw==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"tslib": "^2.0.0"
|
"tslib": "^2.0.0"
|
||||||
}
|
}
|
||||||
@@ -44538,7 +44535,6 @@
|
|||||||
"version": "11.1.2",
|
"version": "11.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/@angular/core/-/core-11.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/core/-/core-11.1.2.tgz",
|
||||||
"integrity": "sha512-5urIQTcRZ2hd9Q2JE0KQocjlIvuRdlrSGzxjf9OZbOuapXDNF0Sb3uEcVnt980NS7vw0Am5thVP9gDspS45c7Q==",
|
"integrity": "sha512-5urIQTcRZ2hd9Q2JE0KQocjlIvuRdlrSGzxjf9OZbOuapXDNF0Sb3uEcVnt980NS7vw0Am5thVP9gDspS45c7Q==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"tslib": "^2.0.0"
|
"tslib": "^2.0.0"
|
||||||
}
|
}
|
||||||
@@ -57547,8 +57543,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"iptv-playlist-parser": {
|
"iptv-playlist-parser": {
|
||||||
"version": "git+ssh://git@github.com/4gray/iptv-playlist-parser.git#fbd5900e7c396df57eabad42194ff15267075e1b",
|
"version": "0.8.0",
|
||||||
"from": "iptv-playlist-parser@git+https://github.com/4gray/iptv-playlist-parser.git"
|
"resolved": "https://registry.npmjs.org/iptv-playlist-parser/-/iptv-playlist-parser-0.8.0.tgz",
|
||||||
|
"integrity": "sha512-83+6Fl248rxm6tyzgPi2rqHQU1IBZnZvbWXyGAcBxveitckc+sh6b4+aDqQa+u2IJP2HVZilRd2C229kqJtLuQ=="
|
||||||
},
|
},
|
||||||
"is-absolute-url": {
|
"is-absolute-url": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
@@ -66882,7 +66879,8 @@
|
|||||||
"version": "0.36.2",
|
"version": "0.36.2",
|
||||||
"resolved": "https://registry.npmjs.org/postcss-syntax/-/postcss-syntax-0.36.2.tgz",
|
"resolved": "https://registry.npmjs.org/postcss-syntax/-/postcss-syntax-0.36.2.tgz",
|
||||||
"integrity": "sha512-nBRg/i7E3SOHWxF3PpF5WnJM/jQ1YpY9000OaVXlAQj6Zp/kIqJxEDWIZ67tAd7NLuk7zqN4yqe9nc0oNAOs1w==",
|
"integrity": "sha512-nBRg/i7E3SOHWxF3PpF5WnJM/jQ1YpY9000OaVXlAQj6Zp/kIqJxEDWIZ67tAd7NLuk7zqN4yqe9nc0oNAOs1w==",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"requires": {}
|
||||||
},
|
},
|
||||||
"postcss-unique-selectors": {
|
"postcss-unique-selectors": {
|
||||||
"version": "4.0.1",
|
"version": "4.0.1",
|
||||||
@@ -70787,7 +70785,8 @@
|
|||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-5.0.0.tgz",
|
||||||
"integrity": "sha512-c8aubuARSu5A3vEHLBeOSJt1udOdS+1iue7BmJDTSXoCBmfEQmmWX+59vYIj3NQdJBY6a/QRv1ozVFpaB9jaqA==",
|
"integrity": "sha512-c8aubuARSu5A3vEHLBeOSJt1udOdS+1iue7BmJDTSXoCBmfEQmmWX+59vYIj3NQdJBY6a/QRv1ozVFpaB9jaqA==",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"requires": {}
|
||||||
},
|
},
|
||||||
"stylelint-config-standard": {
|
"stylelint-config-standard": {
|
||||||
"version": "22.0.0",
|
"version": "22.0.0",
|
||||||
|
|||||||
+1
-1
@@ -123,7 +123,7 @@
|
|||||||
"custom-electron-titlebar": "3.2.5",
|
"custom-electron-titlebar": "3.2.5",
|
||||||
"epg-parser": "0.1.1",
|
"epg-parser": "0.1.1",
|
||||||
"hls.js": "0.14.16",
|
"hls.js": "0.14.16",
|
||||||
"iptv-playlist-parser": "git+https://git@github.com/4gray/iptv-playlist-parser.git",
|
"iptv-playlist-parser": "0.8.0",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
"material-icons": "0.3.1",
|
"material-icons": "0.3.1",
|
||||||
"moment": "2.29.1",
|
"moment": "2.29.1",
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ export interface Channel {
|
|||||||
source?: string;
|
source?: string;
|
||||||
days?: string;
|
days?: string;
|
||||||
};
|
};
|
||||||
|
http: {
|
||||||
|
referrer: string;
|
||||||
|
'user-agent': string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,5 +43,6 @@ export function createChannel(params: Partial<Channel>): Channel {
|
|||||||
url: params.url,
|
url: params.url,
|
||||||
tvg: params.tvg,
|
tvg: params.tvg,
|
||||||
timeshift: params.timeshift,
|
timeshift: params.timeshift,
|
||||||
|
http: params.http,
|
||||||
} as Channel;
|
} as Channel;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { EntityState, EntityStore, StoreConfig } from '@datorama/akita';
|
import { EntityState, EntityStore, StoreConfig } from '@datorama/akita';
|
||||||
import { EPG_GET_PROGRAM } from '../../../ipc-commands';
|
import { CHANNEL_SET_USER_AGENT, EPG_GET_PROGRAM } from '../../../ipc-commands';
|
||||||
import { ElectronService } from '../services/electron.service';
|
import { ElectronService } from '../services/electron.service';
|
||||||
import { Channel } from './channel.model';
|
import { Channel } from './channel.model';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
@@ -61,6 +61,15 @@ export class ChannelStore extends EntityStore<ChannelState> {
|
|||||||
this.electronService.ipcRenderer.send(EPG_GET_PROGRAM, {
|
this.electronService.ipcRenderer.send(EPG_GET_PROGRAM, {
|
||||||
channelName: channel.name,
|
channelName: channel.name,
|
||||||
});
|
});
|
||||||
|
if (channel.http['user-agent']) {
|
||||||
|
this.electronService.ipcRenderer.send(
|
||||||
|
CHANNEL_SET_USER_AGENT,
|
||||||
|
{
|
||||||
|
referer: channel.http.referrer,
|
||||||
|
userAgent: channel.http['user-agent'],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...store,
|
...store,
|
||||||
|
|||||||
Reference in new issue
Block a user