mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-08 17:06:15 -08:00
feat: open playlist from file system
This commit is contained in:
1 parent
5a12c6ca29
commit
861e480b70
2 files changed
+42
No files matched your search
@@ -5,6 +5,7 @@ import { guid } from '@datorama/akita';
|
||||
import { Playlist } from './src/app/playlist-uploader/playlist.interface';
|
||||
import Nedb from 'nedb-promises-ts';
|
||||
|
||||
const fs = require('fs');
|
||||
const join = require('path').join;
|
||||
const openAboutWindow = require('about-window').default;
|
||||
const userData = app.getPath('userData');
|
||||
@@ -70,6 +71,28 @@ export class Api {
|
||||
package_json_dir: __dirname,
|
||||
});
|
||||
});
|
||||
|
||||
// open playlist from file system
|
||||
ipcMain.on('open-file', (event, args) => {
|
||||
fs.readFile(args.filePath, 'utf-8', (err, data) => {
|
||||
if (err) {
|
||||
console.log(
|
||||
'An error ocurred reading the file :' + err.message
|
||||
);
|
||||
return;
|
||||
}
|
||||
const array = (data as string).split('\n');
|
||||
const parsedPlaylist = this.parsePlaylist(array);
|
||||
const playlistObject = this.createPlaylistObject(
|
||||
args.fileName,
|
||||
parsedPlaylist
|
||||
);
|
||||
this.insertToDb(playlistObject);
|
||||
event.sender.send('parse-response', {
|
||||
payload: playlistObject,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,5 +50,24 @@ export class AppComponent {
|
||||
this.router.navigateByUrl('/', { skipLocationChange: true });
|
||||
});
|
||||
});
|
||||
|
||||
if (
|
||||
(this.electronService.remote.process.platform === 'linux' ||
|
||||
this.electronService.remote.process.platform === 'win32') &&
|
||||
this.electronService.remote.process.argv.length > 2
|
||||
) {
|
||||
const filePath = this.electronService.remote.process.argv.find(
|
||||
(filepath) =>
|
||||
filepath.endsWith('.m3u') || filepath.endsWith('.m3u8')
|
||||
);
|
||||
if (filePath) {
|
||||
const filePathsArray = filePath.split('/');
|
||||
const fileName = filePathsArray[filePathsArray.length - 1];
|
||||
this.electronService.ipcRenderer.send('open-file', {
|
||||
filePath,
|
||||
fileName,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user