mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-08 17:06:15 -08:00
refactor: code improvements and docs
This commit is contained in:
3 files changed
+31
-34
No files matched your search
@@ -4,7 +4,7 @@ import {
|
||||
UploadInput,
|
||||
UploadFile,
|
||||
humanizeBytes,
|
||||
UploaderOptions
|
||||
UploaderOptions,
|
||||
} from 'ngx-uploader';
|
||||
import { ChannelStore, createChannel } from 'src/app/state';
|
||||
import { M3uService } from 'src/app/services/m3u-service.service';
|
||||
@@ -13,10 +13,9 @@ import { Router } from '@angular/router';
|
||||
@Component({
|
||||
selector: 'app-playlist-uploader',
|
||||
templateUrl: './playlist-uploader.component.html',
|
||||
styleUrls: ['./playlist-uploader.component.css']
|
||||
styleUrls: ['./playlist-uploader.component.css'],
|
||||
})
|
||||
export class PlaylistUploaderComponent {
|
||||
url = 'http://localhost:4900/upload';
|
||||
formData: FormData;
|
||||
files: UploadFile[];
|
||||
uploadInput: EventEmitter<UploadInput>;
|
||||
@@ -24,6 +23,12 @@ export class PlaylistUploaderComponent {
|
||||
dragOver: boolean;
|
||||
options: UploaderOptions;
|
||||
|
||||
/**
|
||||
* Creates an instanceof PlaylistUploaderComponent
|
||||
* @param channelStore channels store
|
||||
* @param m3uService m3u service
|
||||
* @param router angulars router
|
||||
*/
|
||||
constructor(
|
||||
private channelStore: ChannelStore,
|
||||
private m3uService: M3uService,
|
||||
@@ -31,13 +36,17 @@ export class PlaylistUploaderComponent {
|
||||
) {
|
||||
this.options = {
|
||||
concurrency: 1,
|
||||
maxUploads: 1
|
||||
maxUploads: 1,
|
||||
};
|
||||
this.files = [];
|
||||
this.uploadInput = new EventEmitter<UploadInput>();
|
||||
this.humanizeBytes = humanizeBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles file upload
|
||||
* @param output
|
||||
*/
|
||||
onUploadOutput(output: UploadOutput): void {
|
||||
if (output.type === 'allAddedToQueue') {
|
||||
if (this.files.length > 0) {
|
||||
@@ -45,12 +54,12 @@ export class PlaylistUploaderComponent {
|
||||
fileReader.onload = fileLoadedEvent => {
|
||||
const result = (fileLoadedEvent.target as FileReader)
|
||||
.result;
|
||||
// console.log(result);
|
||||
|
||||
const array = (result as string).split('\n');
|
||||
// console.log(array);
|
||||
const playlist = this.m3uService.convertArrayToPlaylist(
|
||||
array
|
||||
);
|
||||
|
||||
playlist.segments.forEach(element => {
|
||||
this.channelStore.add(createChannel(element));
|
||||
this.navigateToPlayer();
|
||||
@@ -91,6 +100,9 @@ export class PlaylistUploaderComponent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigates to the video player route
|
||||
*/
|
||||
navigateToPlayer(): void {
|
||||
this.router.navigateByUrl('/iptv', { skipLocationChange: true });
|
||||
}
|
||||
|
||||
@@ -47,24 +47,6 @@ export class VideoPlayerComponent implements OnInit {
|
||||
) as HTMLVideoElement;
|
||||
}
|
||||
|
||||
/* playVideo(playlist: any): void {
|
||||
if (Hls.isSupported()) {
|
||||
this.hls.loadSource(channelUrl);
|
||||
this.hls.attachMedia(this.videoPlayer);
|
||||
|
||||
this.hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||
this.videoPlayer.play();
|
||||
});
|
||||
} else if (
|
||||
this.videoPlayer.canPlayType('application/vnd.apple.mpegurl')
|
||||
) {
|
||||
this.videoPlayer.src = channelUrl;
|
||||
this.videoPlayer.addEventListener('loadedmetadata', () => {
|
||||
this.videoPlayer.play();
|
||||
});
|
||||
}
|
||||
} */
|
||||
|
||||
/**
|
||||
* Closes sidebar
|
||||
*/
|
||||
@@ -86,6 +68,13 @@ export class VideoPlayerComponent implements OnInit {
|
||||
this.hls.loadSource(channel.url);
|
||||
this.hls.attachMedia(this.videoPlayer);
|
||||
this.channelTitle = channel.title;
|
||||
} else if (
|
||||
this.videoPlayer.canPlayType('application/vnd.apple.mpegurl')
|
||||
) {
|
||||
this.videoPlayer.src = channel.url;
|
||||
this.videoPlayer.addEventListener('loadedmetadata', () => {
|
||||
this.videoPlayer.play();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import * as M3U8FileParser from 'm3u8-file-parser';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class M3uService {
|
||||
/**
|
||||
* m3u8 parser
|
||||
*/
|
||||
m3u8FileParser = new M3U8FileParser();
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
/**
|
||||
* Returns playlist object
|
||||
* Converts string based array to playlist object
|
||||
* @param m3uArray m3u playlist as array with strings
|
||||
*/
|
||||
/* getPlaylist(): Observable<any> {
|
||||
return this.http.get('../your.json');
|
||||
} */
|
||||
|
||||
convertArrayToPlaylist(m3uArray: any[]): any {
|
||||
this.m3u8FileParser.read(m3uArray.join('\n'));
|
||||
return this.m3u8FileParser.getResult();
|
||||
|
||||
Reference in new issue
Block a user