mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-12 01:50:04 -04:00
Update scripts
This commit is contained in:
parent
89b87ad5c8
commit
bb2935878d
16 changed files with 248 additions and 231 deletions
|
@ -1,22 +0,0 @@
|
|||
import Datastore from '@seald-io/nedb'
|
||||
import * as path from 'path'
|
||||
|
||||
export class Database {
|
||||
rootDir: string
|
||||
|
||||
constructor(rootDir: string) {
|
||||
this.rootDir = rootDir
|
||||
}
|
||||
|
||||
async load(filepath: string) {
|
||||
const absFilepath = path.join(this.rootDir, filepath)
|
||||
|
||||
return new Datastore({
|
||||
filename: path.resolve(absFilepath),
|
||||
autoload: true,
|
||||
onload: (error: Error): any => {
|
||||
if (error) console.error(error.message)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
export * from './database'
|
||||
export * from './logger'
|
||||
export * from './playlistParser'
|
||||
export * from './numberParser'
|
||||
|
|
|
@ -1,33 +1,31 @@
|
|||
import { Dictionary } from './'
|
||||
import { Issue } from '../models'
|
||||
import _ from 'lodash'
|
||||
|
||||
const FIELDS = new Dictionary({
|
||||
'Channel ID': 'channel_id',
|
||||
'Channel ID (required)': 'channel_id',
|
||||
'Broken Link': 'stream_url',
|
||||
'Stream URL': 'stream_url',
|
||||
'Stream URL (optional)': 'stream_url',
|
||||
'Stream URL (required)': 'stream_url',
|
||||
Label: 'label',
|
||||
Quality: 'quality',
|
||||
'Channel Name': 'channel_name',
|
||||
'HTTP User-Agent': 'user_agent',
|
||||
'HTTP Referrer': 'http_referrer',
|
||||
Reason: 'reason',
|
||||
'What happened to the stream?': 'reason',
|
||||
'Possible Replacement (optional)': 'possible_replacement',
|
||||
Notes: 'notes',
|
||||
'Notes (optional)': 'notes'
|
||||
})
|
||||
|
||||
export class IssueParser {
|
||||
parse(issue: any): Dictionary {
|
||||
const data = new Dictionary()
|
||||
data.set('issue_number', issue.number)
|
||||
|
||||
const idDict = new Dictionary({
|
||||
'Channel ID': 'channel_id',
|
||||
'Channel ID (required)': 'channel_id',
|
||||
'Broken Link': 'stream_url',
|
||||
'Stream URL': 'stream_url',
|
||||
'Stream URL (optional)': 'stream_url',
|
||||
'Stream URL (required)': 'stream_url',
|
||||
Label: 'label',
|
||||
Quality: 'quality',
|
||||
'Channel Name': 'channel_name',
|
||||
'HTTP User-Agent': 'user_agent',
|
||||
'HTTP Referrer': 'http_referrer',
|
||||
Reason: 'reason',
|
||||
'What happened to the stream?': 'reason',
|
||||
'Possible Replacement (optional)': 'possible_replacement',
|
||||
Notes: 'notes',
|
||||
'Notes (optional)': 'notes'
|
||||
})
|
||||
|
||||
parse(issue: any): Issue {
|
||||
const fields = issue.body.split('###')
|
||||
|
||||
if (!fields.length) return data
|
||||
|
||||
const data = new Dictionary()
|
||||
fields.forEach((field: string) => {
|
||||
let [_label, , _value] = field.split(/\r?\n/)
|
||||
_label = _label ? _label.trim() : ''
|
||||
|
@ -35,7 +33,7 @@ export class IssueParser {
|
|||
|
||||
if (!_label || !_value) return data
|
||||
|
||||
const id: string = idDict.get(_label)
|
||||
const id: string = FIELDS.get(_label)
|
||||
const value: string = _value === '_No response_' || _value === 'None' ? '' : _value
|
||||
|
||||
if (!id) return
|
||||
|
@ -43,6 +41,6 @@ export class IssueParser {
|
|||
data.set(id, value)
|
||||
})
|
||||
|
||||
return data
|
||||
return new Issue({ number: issue.number, data })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import parser from 'iptv-playlist-parser'
|
||||
import { Playlist, Stream } from '../models'
|
||||
import { Stream } from '../models'
|
||||
import { Collection, Storage } from './'
|
||||
import path from 'path'
|
||||
import { STREAMS_DIR } from '../constants'
|
||||
|
||||
export class PlaylistParser {
|
||||
storage: Storage
|
||||
|
@ -9,7 +11,19 @@ export class PlaylistParser {
|
|||
this.storage = storage
|
||||
}
|
||||
|
||||
async parse(filepath: string): Promise<Playlist> {
|
||||
async parse(files: string[]): Promise<Collection> {
|
||||
let streams = new Collection()
|
||||
|
||||
for (let filepath of files) {
|
||||
const relativeFilepath = filepath.replace(path.normalize(STREAMS_DIR), '')
|
||||
const _streams: Collection = await this.parseFile(relativeFilepath)
|
||||
streams = streams.concat(_streams)
|
||||
}
|
||||
|
||||
return streams
|
||||
}
|
||||
|
||||
async parseFile(filepath: string): Promise<Collection> {
|
||||
const streams = new Collection()
|
||||
|
||||
const content = await this.storage.read(filepath)
|
||||
|
@ -32,7 +46,7 @@ export class PlaylistParser {
|
|||
streams.add(stream)
|
||||
})
|
||||
|
||||
return new Playlist(streams)
|
||||
return streams
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,10 +10,12 @@ export class Storage {
|
|||
this.rootDir = path.normalize(rootDir || './')
|
||||
}
|
||||
|
||||
list(pattern: string): Promise<string[]> {
|
||||
return glob(pattern, {
|
||||
async list(pattern: string): Promise<string[]> {
|
||||
const files = await glob(pattern, {
|
||||
cwd: this.rootDir
|
||||
})
|
||||
|
||||
return files.sort()
|
||||
}
|
||||
|
||||
async createDir(dir: string): Promise<void> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue