diff --git a/package.json b/package.json index ce19cab95..d349271dc 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "db:create": "node scripts/commands/database/create.js", "db:matrix": "node scripts/commands/database/matrix.js", "db:update": "node scripts/commands/database/update.js", + "db:export": "node scripts/commands/database/export.js", "db:cleanup": "node scripts/commands/database/cleanup.js", "cluster:load": "node scripts/commands/cluster/load.js", "playlist:validate": "node scripts/commands/playlist/validate.js", diff --git a/scripts/commands/database/export.js b/scripts/commands/database/export.js new file mode 100644 index 000000000..e7a003624 --- /dev/null +++ b/scripts/commands/database/export.js @@ -0,0 +1,23 @@ +const { logger, db, file } = require('../../core') +const _ = require('lodash') + +const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages' + +async function main() { + await db.streams.load() + let streams = await db.streams.find({}) + streams = _.sortBy(streams, 'channel_id') + streams = streams.map(stream => { + return { + channel: stream.channel_id, + display_name: stream.display_name, + url: stream.url, + http_referrer: stream.http['referrer'], + user_agent: stream.http['user-agent'] + } + }) + + await file.create(`${PUBLIC_DIR}/streams.json`, JSON.stringify(streams)) +} + +main() diff --git a/tests/__data__/expected/.gh-pages/streams.json b/tests/__data__/expected/.gh-pages/streams.json index 6076b3626..42cf48c7d 100644 --- a/tests/__data__/expected/.gh-pages/streams.json +++ b/tests/__data__/expected/.gh-pages/streams.json @@ -1 +1 @@ -[{"name":"BBC News HD","logo":"https://i.imgur.com/eNPIQ9f.png","url":"http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8","categories":[{"name":"News","slug":"news"}],"countries":[{"name":"United Kingdom","code":"UK"}],"languages":[{"name":"English","code":"eng"}],"tvg":{"id":"BBCNews.uk","name":"BBC News HD","url":""}},{"name":"BBC News HD","logo":"https://i.imgur.com/eNPIQ9f.png","url":"http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/playlist.m3u8","categories":[{"name":"News","slug":"news"}],"countries":[{"name":"United Kingdom","code":"UK"}],"languages":[{"name":"English","code":"eng"}],"tvg":{"id":"BBCNews.uk","name":"BBC News HD","url":""}},{"name":"Daawah TV","logo":"","url":"http://51.15.246.58:8081/daawahtv/daawahtv2/playlist.m3u8","categories":[],"countries":[],"languages":[],"tvg":{"id":"","name":"Daawah TV","url":""}},{"name":"Tastemade","logo":"","url":"https://tastemade-freetv16min-plex.amagi.tv/hls/amagi_hls_data_tastemade-tastemadefreetv16-plex/CDN/playlist.m3u8","categories":[{"name":"Cooking","slug":"cooking"}],"countries":[{"name":"Andorra","code":"AD"},{"name":"Russia","code":"RU"},{"name":"United Kingdom","code":"UK"}],"languages":[],"tvg":{"id":"","name":"Tastemade","url":""}},{"name":"Visit-X TV","logo":"","url":"https://stream.visit-x.tv/vxtv/ngrp:live_all/playlist.m3u8","categories":[{"name":"XXX","slug":"xxx"}],"countries":[],"languages":[],"tvg":{"id":"","name":"Visit-X TV","url":""}},{"name":"ЛДПР ТВ","logo":"https://iptvx.one/icn/ldpr-tv.png","url":"http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8","categories":[{"name":"General","slug":"general"},{"name":"Legislative","slug":"legislative"}],"countries":[{"name":"Russia","code":"RU"}],"languages":[{"name":"Russian","code":"rus"}],"tvg":{"id":"LDPRTV.ru","name":"ЛДПР ТВ","url":"https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"}}] \ No newline at end of file +[{"channel":"AndorraTV.ad","display_name":"ATV (720p) [Offline]","url":"https://iptv-all.lanesh4d0w.repl.co/andorra/atv","http_referrer":"","user_agent":""},{"channel":"AndorraTV.ad","display_name":"Andorra TV (720p) [Not 24/7]","url":"http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8","http_referrer":"","user_agent":""},{"channel":"BBCNews.uk","display_name":"BBC News HD (720p) [Not 24/7]","url":"https://query-streamlink.herokuapp.com/iptv-query?streaming-ip=https://www.twitch.tv/absliveantigua3/","http_referrer":"","user_agent":""},{"channel":"LDPRTV.ru","display_name":"ЛДПР ТВ (1080p)","url":"http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8","http_referrer":"","user_agent":""}] \ No newline at end of file diff --git a/tests/commands/database/export.test.js b/tests/commands/database/export.test.js new file mode 100644 index 000000000..a6ddb3285 --- /dev/null +++ b/tests/commands/database/export.test.js @@ -0,0 +1,25 @@ +const { execSync } = require('child_process') +const fs = require('fs-extra') + +beforeEach(() => { + fs.emptyDirSync('tests/__data__/output') + fs.copyFileSync( + 'tests/__data__/input/database/base_streams.db', + 'tests/__data__/output/streams.db' + ) + + const stdout = execSync( + 'DB_DIR=tests/__data__/output PUBLIC_DIR=tests/__data__/output/.gh-pages npm run db:export', + { encoding: 'utf8' } + ) +}) + +it('can create streams.json', () => { + expect(content(`output/.gh-pages/streams.json`)).toBe(content(`expected/.gh-pages/streams.json`)) +}) + +function content(filepath) { + return fs.readFileSync(`tests/__data__/${filepath}`, { + encoding: 'utf8' + }) +}