feat: add support of specific user-agent and referer on channel level

This commit closes #57
This commit is contained in:
4gray committed 2021-06-27 11:25:24 +02:00
1 parent f7689539c8
commit a55f741a32
6 files changed
+56 -17

No files matched your search

+26 -3
View File
@@ -1,11 +1,12 @@
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 axios from 'axios';
import { guid } from '@datorama/akita';
import { Playlist, PlaylistUpdateState } from './playlist.interface';
import Nedb, { Cursor } from 'nedb-promises-ts';
import {
CHANNEL_SET_USER_AGENT,
EPG_ERROR,
EPG_FETCH,
EPG_FETCH_DONE,
@@ -33,6 +34,9 @@ export class Api {
/** Default user agent stored as a fallback value */
defaultUserAgent: string;
/** Default referer url value */
defaultReferer: string;
/** Instance of the epg browser window */
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();
}
@@ -253,12 +268,20 @@ export class Api {
/**
* Sets the user agent header for all http requests
* @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 === '') {
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`);
}
+3
View File
@@ -15,3 +15,6 @@ export const PLAYLIST_UPDATE_RESPONSE = 'PLAYLIST:UPDATE_RESPONSE';
// General
export const SHOW_WHATS_NEW = 'SHOW_WHATS_NEW';
export const ERROR = 'error';
// Channels
export const CHANNEL_SET_USER_AGENT = 'CHANNEL:SET_USER_AGENT';
+11 -12
View File
@@ -22,7 +22,7 @@
"custom-electron-titlebar": "3.2.5",
"epg-parser": "0.1.1",
"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",
"material-icons": "0.3.1",
"moment": "2.29.1",
@@ -4259,7 +4259,6 @@
"version": "11.1.2",
"resolved": "https://registry.npmjs.org/@angular/common/-/common-11.1.2.tgz",
"integrity": "sha512-/+tMeFikT55VgOnx30y6M/WTuSwUarehpKhJ9F61hLZBTzWAIWuaD5DODZVnZ7b15pwgEO8UWnfr4778HTQlTw==",
"dev": true,
"dependencies": {
"tslib": "^2.0.0"
}
@@ -4477,7 +4476,6 @@
"version": "11.1.2",
"resolved": "https://registry.npmjs.org/@angular/core/-/core-11.1.2.tgz",
"integrity": "sha512-5urIQTcRZ2hd9Q2JE0KQocjlIvuRdlrSGzxjf9OZbOuapXDNF0Sb3uEcVnt980NS7vw0Am5thVP9gDspS45c7Q==",
"dev": true,
"dependencies": {
"tslib": "^2.0.0"
}
@@ -19901,9 +19899,9 @@
}
},
"node_modules/iptv-playlist-parser": {
"version": "0.6.0",
"resolved": "git+ssh://git@github.com/4gray/iptv-playlist-parser.git#fbd5900e7c396df57eabad42194ff15267075e1b",
"license": "MIT"
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/iptv-playlist-parser/-/iptv-playlist-parser-0.8.0.tgz",
"integrity": "sha512-83+6Fl248rxm6tyzgPi2rqHQU1IBZnZvbWXyGAcBxveitckc+sh6b4+aDqQa+u2IJP2HVZilRd2C229kqJtLuQ=="
},
"node_modules/is-absolute-url": {
"version": "2.1.0",
@@ -44366,7 +44364,6 @@
"version": "11.1.2",
"resolved": "https://registry.npmjs.org/@angular/common/-/common-11.1.2.tgz",
"integrity": "sha512-/+tMeFikT55VgOnx30y6M/WTuSwUarehpKhJ9F61hLZBTzWAIWuaD5DODZVnZ7b15pwgEO8UWnfr4778HTQlTw==",
"dev": true,
"requires": {
"tslib": "^2.0.0"
}
@@ -44538,7 +44535,6 @@
"version": "11.1.2",
"resolved": "https://registry.npmjs.org/@angular/core/-/core-11.1.2.tgz",
"integrity": "sha512-5urIQTcRZ2hd9Q2JE0KQocjlIvuRdlrSGzxjf9OZbOuapXDNF0Sb3uEcVnt980NS7vw0Am5thVP9gDspS45c7Q==",
"dev": true,
"requires": {
"tslib": "^2.0.0"
}
@@ -57547,8 +57543,9 @@
"dev": true
},
"iptv-playlist-parser": {
"version": "git+ssh://git@github.com/4gray/iptv-playlist-parser.git#fbd5900e7c396df57eabad42194ff15267075e1b",
"from": "iptv-playlist-parser@git+https://github.com/4gray/iptv-playlist-parser.git"
"version": "0.8.0",
"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": {
"version": "2.1.0",
@@ -66882,7 +66879,8 @@
"version": "0.36.2",
"resolved": "https://registry.npmjs.org/postcss-syntax/-/postcss-syntax-0.36.2.tgz",
"integrity": "sha512-nBRg/i7E3SOHWxF3PpF5WnJM/jQ1YpY9000OaVXlAQj6Zp/kIqJxEDWIZ67tAd7NLuk7zqN4yqe9nc0oNAOs1w==",
"dev": true
"dev": true,
"requires": {}
},
"postcss-unique-selectors": {
"version": "4.0.1",
@@ -70787,7 +70785,8 @@
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-5.0.0.tgz",
"integrity": "sha512-c8aubuARSu5A3vEHLBeOSJt1udOdS+1iue7BmJDTSXoCBmfEQmmWX+59vYIj3NQdJBY6a/QRv1ozVFpaB9jaqA==",
"dev": true
"dev": true,
"requires": {}
},
"stylelint-config-standard": {
"version": "22.0.0",
+1 -1
View File
@@ -123,7 +123,7 @@
"custom-electron-titlebar": "3.2.5",
"epg-parser": "0.1.1",
"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",
"material-icons": "0.3.1",
"moment": "2.29.1",
+5
View File
@@ -25,6 +25,10 @@ export interface Channel {
source?: string;
days?: string;
};
http: {
referrer: string;
'user-agent': string;
};
}
/**
@@ -39,5 +43,6 @@ export function createChannel(params: Partial<Channel>): Channel {
url: params.url,
tvg: params.tvg,
timeshift: params.timeshift,
http: params.http,
} as Channel;
}
+10 -1
View File
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
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 { Channel } from './channel.model';
import * as moment from 'moment';
@@ -61,6 +61,15 @@ export class ChannelStore extends EntityStore<ChannelState> {
this.electronService.ipcRenderer.send(EPG_GET_PROGRAM, {
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 {
...store,