Update update-playlists.js
This commit is contained in:
		| @@ -9,7 +9,7 @@ async function main() { | |||||||
|  |  | ||||||
|   for (const filepath in files) { |   for (const filepath in files) { | ||||||
|     const items = files[filepath] |     const items = files[filepath] | ||||||
|     await generator.saveAsM3U(filepath, items, { includeGuides: false }) |     await generator.saveAsM3U(filepath, items) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -50,11 +50,11 @@ generator.generate = async function (filepath, query = {}, options = {}) { | |||||||
|   return { filepath, query, options, count: items.length } |   return { filepath, query, options, count: items.length } | ||||||
| } | } | ||||||
|  |  | ||||||
| async function saveAsM3U(filepath, items, options) { | async function saveAsM3U(filepath, items, options = {}) { | ||||||
|   const playlist = await createPlaylist(filepath) |   const playlist = await createPlaylist(filepath) | ||||||
|  |  | ||||||
|   const header = {} |   const header = {} | ||||||
|   if (options.includeGuides) { |   if (options.public) { | ||||||
|     let guides = items.map(item => item.guides) |     let guides = items.map(item => item.guides) | ||||||
|     guides = _.uniq(_.flatten(guides)).sort().join(',') |     guides = _.uniq(_.flatten(guides)).sort().join(',') | ||||||
|  |  | ||||||
| @@ -64,23 +64,28 @@ async function saveAsM3U(filepath, items, options) { | |||||||
|   await playlist.header(header) |   await playlist.header(header) | ||||||
|   for (const item of items) { |   for (const item of items) { | ||||||
|     const stream = store.create(item) |     const stream = store.create(item) | ||||||
|     await playlist.link( |  | ||||||
|       stream.get('url'), |     let attrs | ||||||
|       stream.get('title'), |     if (options.public) { | ||||||
|       { |       attrs = { | ||||||
|         'tvg-id': stream.get('tvg_id'), |         'tvg-id': stream.get('tvg_id'), | ||||||
|         'tvg-country': stream.get('tvg_country'), |         'tvg-country': stream.get('tvg_country'), | ||||||
|         'tvg-language': stream.get('tvg_language'), |         'tvg-language': stream.get('tvg_language'), | ||||||
|         'tvg-logo': stream.get('tvg_logo'), |         'tvg-logo': stream.get('tvg_logo'), | ||||||
|         // 'tvg-url': stream.get('tvg_url') || undefined, |  | ||||||
|         'user-agent': stream.get('http.user-agent') || undefined, |         'user-agent': stream.get('http.user-agent') || undefined, | ||||||
|         'group-title': stream.get('group_title') |         'group-title': stream.get('group_title') | ||||||
|       }, |       } | ||||||
|       { |     } else { | ||||||
|  |       attrs = { | ||||||
|  |         'tvg-id': stream.get('tvg_id'), | ||||||
|  |         'user-agent': stream.get('http.user-agent') || undefined | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     await playlist.link(stream.get('url'), stream.get('display_name'), attrs, { | ||||||
|       'http-referrer': stream.get('http.referrer') || undefined, |       'http-referrer': stream.get('http.referrer') || undefined, | ||||||
|       'http-user-agent': stream.get('http.user-agent') || undefined |       'http-user-agent': stream.get('http.user-agent') || undefined | ||||||
|       } |     }) | ||||||
|     ) |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| module.exports = function () { | module.exports = function () { | ||||||
|   let title = this.name |   let title = this.title | ||||||
| 
 | 
 | ||||||
|   if (this.resolution.height) { |   if (this.resolution.height) { | ||||||
|     title += ` (${this.resolution.height}p)` |     title += ` (${this.resolution.height}p)` | ||||||
| @@ -1,5 +1,5 @@ | |||||||
| exports.group_title = require('./group_title') | exports.group_title = require('./group_title') | ||||||
| exports.title = require('./title') | exports.display_name = require('./display_name') | ||||||
| exports.tvg_country = require('./tvg_country') | exports.tvg_country = require('./tvg_country') | ||||||
| exports.tvg_id = require('./tvg_id') | exports.tvg_id = require('./tvg_id') | ||||||
| exports.tvg_language = require('./tvg_language') | exports.tvg_language = require('./tvg_language') | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								tests/__data__/expected/channels/ad.m3u
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/__data__/expected/channels/ad.m3u
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | #EXTM3U | ||||||
|  | #EXTINF:-1 tvg-id="AndorraTV.ad",ATV (720p) [Offline] | ||||||
|  | https://iptv-all.lanesh4d0w.repl.co/andorra/atv | ||||||
							
								
								
									
										3
									
								
								tests/__data__/expected/channels/ru.m3u
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/__data__/expected/channels/ru.m3u
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | #EXTM3U | ||||||
|  | #EXTINF:-1 tvg-id="LDPRTV.ru",ЛДПР ТВ (1080p) | ||||||
|  | http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8 | ||||||
							
								
								
									
										5
									
								
								tests/__data__/expected/channels/uk.m3u
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								tests/__data__/expected/channels/uk.m3u
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | |||||||
|  | #EXTM3U | ||||||
|  | #EXTINF:-1 tvg-id="AndorraTV.ad",Andorra TV (720p) [Not 24/7] | ||||||
|  | http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8 | ||||||
|  | #EXTINF:-1 tvg-id="BBCNews.uk",BBC News HD (720p) [Not 24/7] | ||||||
|  | https://query-streamlink.herokuapp.com/iptv-query?streaming-ip=https://www.twitch.tv/absliveantigua3/ | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| {"title":"ЛДПР ТВ","id":"LDPRTV.ru","filepath":"tests/__data__/output/channels/ru.m3u","resolution":{"height":1080,"width":null},"status":{"label":"","code":"online","level":1},"url":"http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8","http":{"referrer":"","user-agent":""},"is_broken":false,"updated":false,"cluster_id":1,"_id":"2ST8btby3mmsgPF0"} | {"title":"ЛДПР ТВ","id":"LDPRTV.ru","filepath":"tests/__data__/output/channels/ru.m3u","resolution":{"height":1080,"width":null},"status":{"label":"","code":"online","level":1},"url":"http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8","http":{"referrer":"","user-agent":""},"is_broken":false,"updated":false,"cluster_id":1,"_id":"2ST8btby3mmsgPF0"} | ||||||
| {"title":"BBC News HD","id":"BBCNews.uk","filepath":"tests/__data__/output/channels/uk.m3u","resolution":{"height":720,"width":null},"status":{"label":"Not 24/7","code":"not_247","level":3},"url":"http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8","http":{"referrer":"","user-agent":""},"is_broken":false,"updated":false,"cluster_id":3,"_id":"3TbieV1ptnZVCIdn"} | {"title":"BBC News HD","id":"BBCNews.uk","filepath":"tests/__data__/output/channels/uk.m3u","resolution":{"height":720,"width":null},"status":{"label":"Not 24/7","code":"not_247","level":3},"url":"https://query-streamlink.herokuapp.com/iptv-query?streaming-ip=https://www.twitch.tv/absliveantigua3/","http":{"referrer":"","user-agent":""},"is_broken":false,"updated":false,"cluster_id":3,"_id":"3TbieV1ptnZVCIdn"} | ||||||
| {"title":"ATV","id":"AndorraTV.ad","filepath":"tests/__data__/output/channels/ad.m3u","resolution":{"height":720,"width":null},"status":{"label":"Offline","code":"offline","level":5},"url":"https://iptv-all.lanesh4d0w.repl.co/andorra/atv","http":{"referrer":"","user-agent":""},"is_broken":true,"updated":false,"cluster_id":1,"_id":"I6cjG2xCBRFFP4sz"} | {"title":"ATV","id":"AndorraTV.ad","filepath":"tests/__data__/output/channels/ad.m3u","resolution":{"height":720,"width":null},"status":{"label":"Offline","code":"offline","level":5},"url":"https://iptv-all.lanesh4d0w.repl.co/andorra/atv","http":{"referrer":"","user-agent":""},"is_broken":true,"updated":false,"cluster_id":1,"_id":"I6cjG2xCBRFFP4sz"} | ||||||
| {"title":"BBC News HD","id":"AndorraTV.ad","filepath":"tests/__data__/output/channels/uk.m3u","resolution":{"height":720,"width":null},"status":{"label":"Not 24/7","code":"not_247","level":3},"url":"http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8","http":{"referrer":"","user-agent":""},"is_broken":false,"updated":false,"cluster_id":3,"_id":"WTbieV1ptnZVCIdn"} | {"title":"Andorra TV","id":"AndorraTV.ad","filepath":"tests/__data__/output/channels/uk.m3u","resolution":{"height":720,"width":null},"status":{"label":"Not 24/7","code":"not_247","level":3},"url":"http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8","http":{"referrer":"","user-agent":""},"is_broken":false,"updated":false,"cluster_id":3,"_id":"WTbieV1ptnZVCIdn"} | ||||||
|   | |||||||
| @@ -1,37 +1,36 @@ | |||||||
| const fs = require('fs') | const fs = require('fs-extra') | ||||||
| const path = require('path') | const path = require('path') | ||||||
| const { execSync } = require('child_process') | const { execSync } = require('child_process') | ||||||
|  |  | ||||||
| beforeEach(() => { | beforeEach(() => { | ||||||
|   fs.copyFileSync('tests/__data__/input/test.db', 'tests/__data__/temp/test.db') |   fs.emptyDirSync('tests/__data__/temp') | ||||||
| }) |   fs.copyFileSync('tests/__data__/input/streams.db', 'tests/__data__/temp/streams.db') | ||||||
|  |  | ||||||
| afterEach(() => { |   const stdout = execSync( | ||||||
|   fs.rmdirSync('tests/__data__/temp', { recursive: true }) |     'DB_FILEPATH=tests/__data__/temp/streams.db node scripts/commands/update-playlists.js', | ||||||
|   fs.mkdirSync('tests/__data__/temp') |     { encoding: 'utf8' } | ||||||
|  |   ) | ||||||
| }) | }) | ||||||
|  |  | ||||||
| it('can update playlist', () => { | it('can update playlist', () => { | ||||||
|   const result = execSync( |   const output1 = content('tests/__data__/output/channels/ad.m3u') | ||||||
|     'DB_FILEPATH=tests/__data__/temp/test.db node scripts/commands/update-playlists.js', |   const expected1 = content('tests/__data__/expected/channels/ad.m3u') | ||||||
|     { encoding: 'utf8' } |  | ||||||
|   ) |  | ||||||
|  |  | ||||||
|   const adPlaylist = fs.readFileSync('tests/__data__/output/channels/ad.m3u', { |   expect(output1).toBe(expected1) | ||||||
|  |  | ||||||
|  |   const output2 = content('tests/__data__/output/channels/ru.m3u') | ||||||
|  |   const expected2 = content('tests/__data__/expected/channels/ru.m3u') | ||||||
|  |  | ||||||
|  |   expect(output2).toBe(expected2) | ||||||
|  |  | ||||||
|  |   const output3 = content('tests/__data__/output/channels/uk.m3u') | ||||||
|  |   const expected3 = content('tests/__data__/expected/channels/uk.m3u') | ||||||
|  |  | ||||||
|  |   expect(output3).toBe(expected3) | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | function content(filepath) { | ||||||
|  |   return fs.readFileSync(path.resolve(filepath), { | ||||||
|     encoding: 'utf8' |     encoding: 'utf8' | ||||||
|   }) |   }) | ||||||
|  | } | ||||||
|   expect(adPlaylist).toBe(`#EXTM3U |  | ||||||
| #EXTINF:-1 tvg-id="AndorraTV.ad" tvg-country="AD" tvg-language="Catalan" tvg-logo="https://i.imgur.com/kJCjeQ4.png" group-title="General",ATV (720p) [Offline] |  | ||||||
| https://iptv-all.lanesh4d0w.repl.co/andorra/atv |  | ||||||
| `) |  | ||||||
|  |  | ||||||
|   const ruPlaylist = fs.readFileSync('tests/__data__/output/channels/ru.m3u', { |  | ||||||
|     encoding: 'utf8' |  | ||||||
|   }) |  | ||||||
|  |  | ||||||
|   expect(ruPlaylist).toBe(`#EXTM3U |  | ||||||
| #EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="General",ЛДПР ТВ (1080p) |  | ||||||
| http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8 |  | ||||||
| `) |  | ||||||
| }) |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user