Skip to content

Commit

Permalink
Changed the login flow and added some logging for stream starting
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ngr31 committed Oct 3, 2021
1 parent 338c607 commit e1f2018
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
config/
tmp/
run*.sh
.DS_Store
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN \

EXPOSE 8000

RUN chmod +x stream_channel.sh
RUN chown pwuser:pwuser /app

USER pwuser
Expand Down
27 changes: 17 additions & 10 deletions services/get-stream-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions services/launch-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion stream_channel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
| 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

0 comments on commit e1f2018

Please sign in to comment.