Skip to content

Instantly share code, notes, and snippets.

@maccyber
Last active April 16, 2022 20:20
Show Gist options
  • Save maccyber/133d02428df3ea4b9e6494c24d5357e8 to your computer and use it in GitHub Desktop.
Save maccyber/133d02428df3ea4b9e6494c24d5357e8 to your computer and use it in GitHub Desktop.
import http from 'http'
import {readFile, stat, unlink} from 'fs/promises'
import {createWriteStream} from 'fs'
const fileContent = await readFile('./list', 'utf-8')
const listOfUrls = fileContent
.split(/\r?\n/)
.filter((line) => line)
listOfUrls.forEach(downloadFile)
async function downloadFile(url, i) {
const filename = `list_${i}.m3u`
http.get(url, (response) => {
if (response.statusCode !== 200) {
console.error(`${url}: ${response.statusCode}`)
return
}
const file = createWriteStream(filename)
response.pipe(file)
file.on('finish', async () => {
file.close()
const {size} = await stat(filename)
const content = await readFile(filename, 'utf-8')
if (content.slice(0, 7) !== '#EXTM3U') await unlink(filename)
console.log(`${url}: Downloaded to ${filename} - Size: ${size}`)
})
})
.on('error', (error) => console.error(`${url}, ${error.message}`))
}
@maccyber
Copy link
Author

maccyber commented Apr 16, 2022

30s streams:

mpv --keep-open=yes mpv --gapless-audio=yes --loop-playlist=inf http://cdn.ayproviders.xyz:80/ZjFB7A8ySw/EM5OYbdMBa/9711

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment