|
|
@ -9,31 +9,34 @@ async function main() {
|
|
|
|
|
|
|
|
|
|
|
|
const storage = new Storage(DATA_DIR)
|
|
|
|
const storage = new Storage(DATA_DIR)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('loading issues...')
|
|
|
|
|
|
|
|
const issues = await loader.load()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('loading streams...')
|
|
|
|
|
|
|
|
const streamsStorage = new Storage(STREAMS_DIR)
|
|
|
|
|
|
|
|
const parser = new PlaylistParser({ storage: streamsStorage })
|
|
|
|
|
|
|
|
const files = await streamsStorage.list('**/*.m3u')
|
|
|
|
|
|
|
|
const streams = await parser.parse(files)
|
|
|
|
|
|
|
|
const streamsGroupedByUrl = streams.groupBy((stream: Stream) => stream.url)
|
|
|
|
|
|
|
|
const streamsGroupedByChannel = streams.groupBy((stream: Stream) => stream.channel)
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('loading channels from api...')
|
|
|
|
logger.info('loading channels from api...')
|
|
|
|
const channelsContent = await storage.json('channels.json')
|
|
|
|
const channelsContent = await storage.json('channels.json')
|
|
|
|
const groupedChannels = new Collection(channelsContent)
|
|
|
|
const channelsGroupedById = new Collection(channelsContent)
|
|
|
|
.map(data => new Channel(data))
|
|
|
|
.map(data => new Channel(data))
|
|
|
|
.groupBy((channel: Channel) => channel.id)
|
|
|
|
.groupBy((channel: Channel) => channel.id)
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('loading blocklist from api...')
|
|
|
|
logger.info('loading blocklist from api...')
|
|
|
|
const blocklistContent = await storage.json('blocklist.json')
|
|
|
|
const blocklistContent = await storage.json('blocklist.json')
|
|
|
|
const groupedBlocklist = new Collection(blocklistContent)
|
|
|
|
const blocklistGroupedByChannel = new Collection(blocklistContent)
|
|
|
|
.map(data => new Blocked(data))
|
|
|
|
.map(data => new Blocked(data))
|
|
|
|
.groupBy((blocked: Blocked) => blocked.channel)
|
|
|
|
.groupBy((blocked: Blocked) => blocked.channel)
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('loading streams...')
|
|
|
|
|
|
|
|
const streamsStorage = new Storage(STREAMS_DIR)
|
|
|
|
|
|
|
|
const parser = new PlaylistParser({ storage: streamsStorage })
|
|
|
|
|
|
|
|
const files = await streamsStorage.list('**/*.m3u')
|
|
|
|
|
|
|
|
const streams = await parser.parse(files)
|
|
|
|
|
|
|
|
const groupedStreams = streams.groupBy((stream: Stream) => stream.url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('creating report...')
|
|
|
|
|
|
|
|
let report = new Collection()
|
|
|
|
let report = new Collection()
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('checking streams:add requests...')
|
|
|
|
logger.info('checking streams:add requests...')
|
|
|
|
const addRequests = await loader.load({ labels: ['streams:add'] })
|
|
|
|
const addRequests = issues.filter(issue => issue.labels.includes('streams:add'))
|
|
|
|
const buffer = new Dictionary()
|
|
|
|
const addRequestsBuffer = new Dictionary()
|
|
|
|
addRequests.forEach((issue: Issue) => {
|
|
|
|
addRequests.forEach((issue: Issue) => {
|
|
|
|
const channelId = issue.data.getString('channel_id') || undefined
|
|
|
|
const channelId = issue.data.getString('channel_id') || undefined
|
|
|
|
const streamUrl = issue.data.getString('stream_url')
|
|
|
|
const streamUrl = issue.data.getString('stream_url')
|
|
|
@ -42,24 +45,25 @@ async function main() {
|
|
|
|
issueNumber: issue.number,
|
|
|
|
issueNumber: issue.number,
|
|
|
|
type: 'streams:add',
|
|
|
|
type: 'streams:add',
|
|
|
|
channelId,
|
|
|
|
channelId,
|
|
|
|
status: undefined
|
|
|
|
streamUrl,
|
|
|
|
|
|
|
|
status: 'pending'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (!channelId) result.set('status', 'missing_id')
|
|
|
|
if (!channelId) result.set('status', 'missing_id')
|
|
|
|
else if (!streamUrl) result.set('status', 'missing_link')
|
|
|
|
else if (!streamUrl) result.set('status', 'missing_link')
|
|
|
|
else if (groupedBlocklist.has(channelId)) result.set('status', 'blocked')
|
|
|
|
else if (blocklistGroupedByChannel.has(channelId)) result.set('status', 'blocked')
|
|
|
|
else if (groupedChannels.missing(channelId)) result.set('status', 'invalid_id')
|
|
|
|
else if (channelsGroupedById.missing(channelId)) result.set('status', 'wrong_id')
|
|
|
|
else if (groupedStreams.has(streamUrl)) result.set('status', 'fullfilled')
|
|
|
|
else if (streamsGroupedByUrl.has(streamUrl)) result.set('status', 'on_playlist')
|
|
|
|
else if (buffer.has(streamUrl)) result.set('status', 'duplicate')
|
|
|
|
else if (addRequestsBuffer.has(streamUrl)) result.set('status', 'duplicate')
|
|
|
|
else result.set('status', 'pending')
|
|
|
|
else result.set('status', 'pending')
|
|
|
|
|
|
|
|
|
|
|
|
buffer.set(streamUrl, true)
|
|
|
|
addRequestsBuffer.set(streamUrl, true)
|
|
|
|
|
|
|
|
|
|
|
|
report.add(result.data())
|
|
|
|
report.add(result.data())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('checking streams:edit requests...')
|
|
|
|
logger.info('checking streams:edit requests...')
|
|
|
|
const editRequests = await loader.load({ labels: ['streams:edit'] })
|
|
|
|
const editRequests = issues.filter(issue => issue.labels.find(label => label === 'streams:edit'))
|
|
|
|
editRequests.forEach((issue: Issue) => {
|
|
|
|
editRequests.forEach((issue: Issue) => {
|
|
|
|
const channelId = issue.data.getString('channel_id') || undefined
|
|
|
|
const channelId = issue.data.getString('channel_id') || undefined
|
|
|
|
const streamUrl = issue.data.getString('stream_url') || undefined
|
|
|
|
const streamUrl = issue.data.getString('stream_url') || undefined
|
|
|
@ -68,37 +72,82 @@ async function main() {
|
|
|
|
issueNumber: issue.number,
|
|
|
|
issueNumber: issue.number,
|
|
|
|
type: 'streams:edit',
|
|
|
|
type: 'streams:edit',
|
|
|
|
channelId,
|
|
|
|
channelId,
|
|
|
|
status: undefined
|
|
|
|
streamUrl,
|
|
|
|
|
|
|
|
status: 'pending'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (!streamUrl) result.set('status', 'missing_link')
|
|
|
|
if (!streamUrl) result.set('status', 'missing_link')
|
|
|
|
else if (groupedStreams.missing(streamUrl)) result.set('status', 'invalid_link')
|
|
|
|
else if (streamsGroupedByUrl.missing(streamUrl)) result.set('status', 'invalid_link')
|
|
|
|
else if (channelId && groupedChannels.missing(channelId)) result.set('status', 'invalid_id')
|
|
|
|
else if (channelId && channelsGroupedById.missing(channelId)) result.set('status', 'invalid_id')
|
|
|
|
else result.set('status', 'pending')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
report.add(result.data())
|
|
|
|
report.add(result.data())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('checking broken streams reports...')
|
|
|
|
logger.info('checking broken streams reports...')
|
|
|
|
const brokenStreamReports = await loader.load({ labels: ['broken stream'] })
|
|
|
|
const brokenStreamReports = issues.filter(issue =>
|
|
|
|
|
|
|
|
issue.labels.find(label => label === 'broken stream')
|
|
|
|
|
|
|
|
)
|
|
|
|
brokenStreamReports.forEach((issue: Issue) => {
|
|
|
|
brokenStreamReports.forEach((issue: Issue) => {
|
|
|
|
const brokenLinks = issue.data.getString('broken_links') || undefined
|
|
|
|
const brokenLinks = issue.data.getArray('broken_links') || []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!brokenLinks.length) {
|
|
|
|
|
|
|
|
const result = new Dictionary({
|
|
|
|
|
|
|
|
issueNumber: issue.number,
|
|
|
|
|
|
|
|
type: 'broken stream',
|
|
|
|
|
|
|
|
channelId: undefined,
|
|
|
|
|
|
|
|
streamUrl: undefined,
|
|
|
|
|
|
|
|
status: 'missing_link'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
report.add(result.data())
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for (const streamUrl of brokenLinks) {
|
|
|
|
|
|
|
|
const result = new Dictionary({
|
|
|
|
|
|
|
|
issueNumber: issue.number,
|
|
|
|
|
|
|
|
type: 'broken stream',
|
|
|
|
|
|
|
|
channelId: undefined,
|
|
|
|
|
|
|
|
streamUrl: undefined,
|
|
|
|
|
|
|
|
status: 'pending'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (streamsGroupedByUrl.missing(streamUrl)) {
|
|
|
|
|
|
|
|
result.set('streamUrl', streamUrl)
|
|
|
|
|
|
|
|
result.set('status', 'wrong_link')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
report.add(result.data())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('checking channel search requests...')
|
|
|
|
|
|
|
|
const channelSearchRequests = issues.filter(issue =>
|
|
|
|
|
|
|
|
issue.labels.find(label => label === 'channel search')
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
const channelSearchRequestsBuffer = new Dictionary()
|
|
|
|
|
|
|
|
channelSearchRequests.forEach((issue: Issue) => {
|
|
|
|
|
|
|
|
const channelId = issue.data.getString('channel_id')
|
|
|
|
|
|
|
|
|
|
|
|
const result = new Dictionary({
|
|
|
|
const result = new Dictionary({
|
|
|
|
issueNumber: issue.number,
|
|
|
|
issueNumber: issue.number,
|
|
|
|
type: 'broken stream',
|
|
|
|
type: 'channel search',
|
|
|
|
channelId: undefined,
|
|
|
|
channelId,
|
|
|
|
status: undefined
|
|
|
|
streamUrl: undefined,
|
|
|
|
|
|
|
|
status: 'pending'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (!brokenLinks) result.set('status', 'missing_link')
|
|
|
|
if (!channelId) result.set('status', 'missing_id')
|
|
|
|
else if (groupedStreams.missing(brokenLinks)) result.set('status', 'invalid_link')
|
|
|
|
else if (channelsGroupedById.missing(channelId)) result.set('status', 'invalid_id')
|
|
|
|
else result.set('status', 'pending')
|
|
|
|
else if (channelSearchRequestsBuffer.has(channelId)) result.set('status', 'duplicate')
|
|
|
|
|
|
|
|
else if (blocklistGroupedByChannel.has(channelId)) result.set('status', 'blocked')
|
|
|
|
|
|
|
|
else if (streamsGroupedByChannel.has(channelId)) result.set('status', 'fulfilled')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
channelSearchRequestsBuffer.set(channelId, true)
|
|
|
|
|
|
|
|
|
|
|
|
report.add(result.data())
|
|
|
|
report.add(result.data())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
report = report.orderBy(item => item.issueNumber)
|
|
|
|
report = report.orderBy(item => item.issueNumber).filter(item => item.status !== 'pending')
|
|
|
|
|
|
|
|
|
|
|
|
console.table(report.all())
|
|
|
|
console.table(report.all())
|
|
|
|
}
|
|
|
|
}
|
|
|
|