From e1f20180a69b3d28a4daec264ea132e7ed2aee20 Mon Sep 17 00:00:00 2001 From: Joe Ipson Date: Sun, 3 Oct 2021 15:55:04 -0600 Subject: [PATCH] Changed the login flow and added some logging for stream starting --- .dockerignore | 5 +++++ Dockerfile | 1 + services/get-stream-data.ts | 27 +++++++++++++++++---------- services/launch-channel.ts | 14 ++++++++++---- stream_channel.sh | 2 +- 5 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a16e9c0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +node_modules/ +config/ +tmp/ +run*.sh +.DS_Store \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 43a533c..81227b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,7 @@ RUN \ EXPOSE 8000 +RUN chmod +x stream_channel.sh RUN chown pwuser:pwuser /app USER pwuser diff --git a/services/get-stream-data.ts b/services/get-stream-data.ts index 8f87472..333bb80 100644 --- a/services/get-stream-data.ts +++ b/services/get-stream-data.ts @@ -54,22 +54,29 @@ export const getStreamData = async (eventId: string) => { try { // Not logged in, do it manually - const pathSelector = 'xpath=//iframe[starts-with(@id,"btm_activity")]'; + const pathSelector = 'xpath=//iframe[starts-with(@src,"https://plus.espn.com/en/paywall")]'; await page.waitForSelector(pathSelector); const frame = await (await page.$(pathSelector)).contentFrame(); if (frame) { await frame.click('text=Log In'); - await sleep(1000); - await page.keyboard.type(process.env.ESPN_USER); - await page.keyboard.press('Tab'); - await page.keyboard.type(process.env.ESPN_PASS); - await page.keyboard.down('Shift'); - await page.keyboard.press('Tab'); - await page.keyboard.up('Shift'); - await page.keyboard.press('Enter'); + await page.waitForSelector('#disneyid-iframe'); + const loginFrame = await (await page.$('#disneyid-iframe')).contentFrame(); + + if (loginFrame) { + await sleep(1000); + await loginFrame.fill('xpath=//input[@type="email"]', process.env.ESPN_USER); + await sleep(1000); + await loginFrame.fill('xpath=//input[@type="password"]', process.env.ESPN_PASS); + await sleep(1000); + await page.screenshot({path: 'config/loginfilled.png'}); + await loginFrame.click('text=Log In'); + } } - } catch (e) {} + } catch (e) { + console.log('Could not find stream. Has the event ended?'); + return await close(); + } totalTries = 1500; currentTry = 0; diff --git a/services/launch-channel.ts b/services/launch-channel.ts index 2cf564e..d2b1e22 100644 --- a/services/launch-channel.ts +++ b/services/launch-channel.ts @@ -33,15 +33,21 @@ const startChannelStream = async (channelId: string, appStatus, appUrl) => { return; } - console.log('Starting stream'); - const currentM3u8 = slateStream.getSlate('soon', appUrl); fs.writeFileSync(path.join(tmpPath, `${channelId}/${channelId}.m3u8`), currentM3u8, 'utf8'); - const child = spawn(path.join(process.cwd(), 'stream_channel.sh'), [], {env: {CHANNEL: channelId, URL: url, AUTH_TOKEN: authToken, APP_URL: appUrl}, detached: true, stdio: 'ignore'}); + + const out = fs.openSync(path.join(tmpPath, `${channelId}-log.txt`), 'a'); + const child = spawn(path.join(process.cwd(), 'stream_channel.sh'), [], {env: {CHANNEL: channelId, URL: url, AUTH_TOKEN: authToken, APP_URL: appUrl}, detached: true, stdio: ['ignore', out, out]}); + appStatus.channels[channelId].pid = child.pid; - child.on('close', () => fsExtra.emptyDirSync(path.join(tmpPath, `${channelId}`))); + console.log('Stream started on PID: ', child.pid); + + child.on('close', () => { + console.log(`Stream for ${channelId} stopped.`); + fsExtra.emptyDirSync(path.join(tmpPath, `${channelId}`)); + }); }; const delayedStart = async (channelId: string, appStatus, appUrl) => { diff --git a/stream_channel.sh b/stream_channel.sh index 341aec0..e803d6b 100755 --- a/stream_channel.sh +++ b/stream_channel.sh @@ -5,4 +5,4 @@ streamlink \ "hlsvariant://${URL}" \ best \ --stdout \ - | ffmpeg -i pipe:0 -c copy -hls_base_url "${APP_URL}/channels/${CHANNEL}/" -hls_flags append_list+omit_endlist -hls_segment_filename tmp/${CHANNEL}/%09d.ts tmp/${CHANNEL}/${CHANNEL}.m3u8 \ No newline at end of file + | ffmpeg -i pipe:0 -c copy -hls_base_url "${APP_URL}/channels/${CHANNEL}/" -hls_flags append_list+omit_endlist -hls_segment_filename tmp/eplustv/${CHANNEL}/%09d.ts tmp/eplustv/${CHANNEL}/${CHANNEL}.m3u8 \ No newline at end of file