mirror of
https://github.com/iptv-org/iptv
synced 2026-09-06 03:50:47 -04:00
Update scripts
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
|
import { getStreamInfo, loadStreamData } from '../../utils'
|
||||||
import { Collection, Logger } from '@freearhey/core'
|
import { Collection, Logger } from '@freearhey/core'
|
||||||
import { OptionValues, program } from 'commander'
|
import { OptionValues, program } from 'commander'
|
||||||
import { Stream, Playlist } from '../../models'
|
import { Stream, Playlist } from '../../models'
|
||||||
import { Storage } from '@freearhey/storage-js'
|
import { Storage } from '@freearhey/storage-js'
|
||||||
import { STREAMS_DIR } from '../../constants'
|
import { STREAMS_DIR } from '../../constants'
|
||||||
import { PlaylistParser } from '../../core'
|
import { PlaylistParser } from '../../core'
|
||||||
import { getStreamInfo } from '../../utils'
|
|
||||||
import { loadData, data } from '../../api'
|
import { loadData, data } from '../../api'
|
||||||
import cliProgress from 'cli-progress'
|
import cliProgress from 'cli-progress'
|
||||||
import { eachLimit } from 'async'
|
import { eachLimit } from 'async'
|
||||||
@@ -83,7 +83,7 @@ async function main() {
|
|||||||
return stream
|
return stream
|
||||||
})
|
})
|
||||||
|
|
||||||
logger.info('adding the missing quality...')
|
logger.info('adding the missing quality and label...')
|
||||||
const progressBar = new cliProgress.SingleBar({
|
const progressBar = new cliProgress.SingleBar({
|
||||||
clearOnComplete: true,
|
clearOnComplete: true,
|
||||||
format: '[{bar}] {percentage}% | {value}/{total}'
|
format: '[{bar}] {percentage}% | {value}/{total}'
|
||||||
@@ -91,21 +91,28 @@ async function main() {
|
|||||||
progressBar.start(streams.count(), 0)
|
progressBar.start(streams.count(), 0)
|
||||||
await eachLimit(streams.all(), options.parallel, async (stream: Stream) => {
|
await eachLimit(streams.all(), options.parallel, async (stream: Stream) => {
|
||||||
progressBar.increment()
|
progressBar.increment()
|
||||||
if (stream.quality) return
|
if (stream.quality && stream.label) return
|
||||||
|
|
||||||
const streamInfo = await getStreamInfo(stream.url, {
|
const { data: streamData, error } = await loadStreamData(stream.url, {
|
||||||
httpUserAgent: stream.user_agent,
|
httpUserAgent: stream.user_agent,
|
||||||
httpReferrer: stream.referrer,
|
httpReferrer: stream.referrer,
|
||||||
timeout: options.timeout,
|
timeout: options.timeout,
|
||||||
proxy: options.proxy
|
proxy: options.proxy
|
||||||
})
|
})
|
||||||
|
|
||||||
if (streamInfo) {
|
if (error?.code === 403 && !stream.label) {
|
||||||
const height = streamInfo?.resolution?.height
|
stream.label = 'Geo-blocked'
|
||||||
|
}
|
||||||
|
|
||||||
if (height) {
|
if (stream.quality) return
|
||||||
stream.quality = `${height}p`
|
if (!streamData) return
|
||||||
}
|
|
||||||
|
const streamInfo = getStreamInfo(stream.url, streamData)
|
||||||
|
if (!streamInfo) return
|
||||||
|
|
||||||
|
const height = streamInfo?.resolution?.height
|
||||||
|
if (height) {
|
||||||
|
stream.quality = `${height}p`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
progressBar.stop()
|
progressBar.stop()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getStreamInfo, loadIssues, createThread } from '../../utils'
|
import { getStreamInfo, loadIssues, createThread, loadStreamData } from '../../utils'
|
||||||
import { STREAMS_DIR, LOGS_DIR } from '../../constants'
|
import { STREAMS_DIR, LOGS_DIR } from '../../constants'
|
||||||
import { Playlist, Issue, Stream } from '../../models'
|
import { Playlist, Issue, Stream } from '../../models'
|
||||||
import { loadData, data as apiData } from '../../api'
|
import { loadData, data as apiData } from '../../api'
|
||||||
@@ -241,14 +241,24 @@ async function addStream(issue: Issue) {
|
|||||||
const httpReferrer = data.getString('http_referrer') || null
|
const httpReferrer = data.getString('http_referrer') || null
|
||||||
|
|
||||||
let quality = data.getString('quality') || null
|
let quality = data.getString('quality') || null
|
||||||
if (!quality) {
|
let label = data.getString('label') || null
|
||||||
const streamInfo = await getStreamInfo(streamUrl, { httpUserAgent, httpReferrer })
|
if (!quality || !label) {
|
||||||
|
const { data: streamData, error } = await loadStreamData(streamUrl, {
|
||||||
|
httpUserAgent,
|
||||||
|
httpReferrer
|
||||||
|
})
|
||||||
|
|
||||||
if (streamInfo) {
|
if (error?.code === 403 && !label) {
|
||||||
const height = streamInfo?.resolution?.height
|
label = `Geo-blocked`
|
||||||
|
}
|
||||||
|
|
||||||
if (height) {
|
if (streamData && !quality) {
|
||||||
quality = `${height}p`
|
const streamInfo = getStreamInfo(streamUrl, streamData)
|
||||||
|
if (streamInfo) {
|
||||||
|
const height = streamInfo?.resolution?.height
|
||||||
|
if (height) {
|
||||||
|
quality = `${height}p`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,7 +271,7 @@ async function addStream(issue: Issue) {
|
|||||||
user_agent: httpUserAgent,
|
user_agent: httpUserAgent,
|
||||||
referrer: httpReferrer,
|
referrer: httpReferrer,
|
||||||
quality,
|
quality,
|
||||||
label: data.getString('label') || ''
|
label
|
||||||
})
|
})
|
||||||
|
|
||||||
stream.updateTitle().updateFilepath()
|
stream.updateTitle().updateFilepath()
|
||||||
|
|||||||
@@ -107,6 +107,10 @@ export class Stream extends sdk.Models.Stream {
|
|||||||
return !channel.is_nsfw
|
return !channel.is_nsfw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isGeoBlocked(): boolean {
|
||||||
|
return this.label === 'Geo-blocked'
|
||||||
|
}
|
||||||
|
|
||||||
getUniqKey(): string {
|
getUniqKey(): string {
|
||||||
const filepath = this.getFilepath()
|
const filepath = this.getFilepath()
|
||||||
const tvgId = this.getTvgId()
|
const tvgId = this.getTvgId()
|
||||||
|
|||||||
+41
-8
@@ -44,7 +44,18 @@ type StreamInfo = {
|
|||||||
codecs: string
|
codecs: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStreamInfo(
|
function getStreamType(url: string): string | undefined {
|
||||||
|
if (url.includes('.m3u8')) return 'HLS'
|
||||||
|
if (url.includes('.mpd')) return 'DASH'
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
type HTTPError = {
|
||||||
|
code: number
|
||||||
|
message: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function loadStreamData(
|
||||||
url: string,
|
url: string,
|
||||||
options: {
|
options: {
|
||||||
httpUserAgent?: string | null
|
httpUserAgent?: string | null
|
||||||
@@ -52,10 +63,21 @@ export async function getStreamInfo(
|
|||||||
timeout?: number
|
timeout?: number
|
||||||
proxy?: string
|
proxy?: string
|
||||||
}
|
}
|
||||||
): Promise<StreamInfo | undefined> {
|
): Promise<{ data: string | undefined; error: HTTPError | undefined }> {
|
||||||
let data: string | undefined
|
let data: string | undefined
|
||||||
|
let error: HTTPError | undefined
|
||||||
if (TESTING) {
|
if (TESTING) {
|
||||||
if (url.includes('.m3u8')) {
|
if (
|
||||||
|
[
|
||||||
|
'srt://stream.alabbassia.com:8890?mode=caller&latency=200&streamid=read:live/alabbassia',
|
||||||
|
'https://60efd7a2b4d02.streamlock.net/a_steiermark/ngrp:livestream_all/playlist.m3u8'
|
||||||
|
].includes(url)
|
||||||
|
) {
|
||||||
|
error = {
|
||||||
|
code: 403,
|
||||||
|
message: 'Forbidden'
|
||||||
|
}
|
||||||
|
} else if (url.includes('.m3u8')) {
|
||||||
data = fs.readFileSync(
|
data = fs.readFileSync(
|
||||||
path.resolve(__dirname, '../tests/__data__/input/playlist_update/playlist.m3u8'),
|
path.resolve(__dirname, '../tests/__data__/input/playlist_update/playlist.m3u8'),
|
||||||
'utf8'
|
'utf8'
|
||||||
@@ -96,16 +118,27 @@ export async function getStreamInfo(
|
|||||||
const response = await axios(url, request)
|
const response = await axios(url, request)
|
||||||
|
|
||||||
data = response.data
|
data = response.data
|
||||||
} catch {
|
} catch (err) {
|
||||||
// do nothing
|
if (err.response) {
|
||||||
|
error = {
|
||||||
|
code: err.status,
|
||||||
|
message: err.message
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data) return undefined
|
return { data, error }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getStreamInfo(url: string, data: string): StreamInfo | undefined {
|
||||||
|
if (!url || !data) return undefined
|
||||||
|
|
||||||
|
const type = getStreamType(url)
|
||||||
|
|
||||||
let info: StreamInfo | undefined
|
let info: StreamInfo | undefined
|
||||||
|
|
||||||
if (url.includes('.m3u8')) {
|
if (type === 'HLS') {
|
||||||
setOptions({ silent: true })
|
setOptions({ silent: true })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -126,7 +159,7 @@ export async function getStreamInfo(
|
|||||||
} catch {
|
} catch {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
} else if (url.includes('.mpd')) {
|
} else if (type === 'DASH') {
|
||||||
const manifest = parseManifest(data, {
|
const manifest = parseManifest(data, {
|
||||||
manifestUri: url,
|
manifestUri: url,
|
||||||
eventHandler: ({ type, message }) => console.log(`${type}: ${message}`)
|
eventHandler: ({ type, message }) => console.log(`${type}: ${message}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user