Merge branch 'dev' into patch-1

This commit is contained in:
Adrian Calinescu 2020-03-22 14:17:08 +02:00 committed by GitHub
commit 470ab23d1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 103 additions and 103 deletions

201
README.md
View file

@ -1,102 +1,99 @@
# Destreamer # Destreamer
![](logo.png) ![](logo.png)
## Saves Microsoft Stream videos for offline enjoyment. ## Saves Microsoft Stream videos for offline enjoyment.
Alpha-quality, don't expect much. It does work though, so that's a neat feature. Alpha-quality, don't expect much. It does work though, so that's a neat feature.
It's slow (e.g. a 60-min video takes 20-30 minutes to download). Not much i can do about it for now unless i find a better way than ripping HLS. It's slow (e.g. a 60-min video takes 20-30 minutes to download). Not much i can do about it for now unless i find a better way than ripping HLS.
## NEW `dev` BRANCH! ## NEW `dev` BRANCH!
This is now a TypeScript project if you checkout the `dev` branch. This is now a TypeScript project if you checkout the `dev` branch.
All new development happens on `dev` branch. All new development happens on `dev` branch.
Use the `master` branch for the older vanilla JavaScript version. Use the `master` branch for the older vanilla JavaScript version.
## DISCLAIMER ## DISCLAIMER
Hopefully this doesn't break the end user agreement for Microsoft Stream. Since we're simply saving the HLS stream to disk as if we were a browser, this does not abuse the streaming endpoints. However i take no responsibility if either Microsoft or your Office 365 admins request a chat with you in a small white room. Hopefully this doesn't break the end user agreement for Microsoft Stream. Since we're simply saving the HLS stream to disk as if we were a browser, this does not abuse the streaming endpoints. However i take no responsibility if either Microsoft or your Office 365 admins request a chat with you in a small white room.
## PREREQS ## PREREQS
* **Node.js**: anything above v8.0 seems to work. A GitHub Action runs tests on Node 8, 10 and 12 on every commit. * **Node.js**: anything above v8.0 seems to work. A GitHub Action runs tests on Node 8, 10 and 12 on every commit.
* **youtube-dl**: https://ytdl-org.github.io/youtube-dl/download.html, you'll need a fairly recent version that understands encrypted HLS streams. This needs to be in your $PATH. Destreamer calls `youtube-dl` with a bunch of arguments. * **youtube-dl**: https://ytdl-org.github.io/youtube-dl/download.html, you'll need a fairly recent version that understands encrypted HLS streams. This needs to be in your $PATH. Destreamer calls `youtube-dl` with a bunch of arguments.
* **ffmpeg**: a recent version (year 2019 or above), in `$PATH`. * **ffmpeg**: a recent version (year 2019 or above), in `$PATH`.
Destreamer takes a [honeybadger](https://www.youtube.com/watch?v=4r7wHMg5Yjg) approach towards the OS it's running on, tested on Windows, results may vary, feel free to open an issue if trouble arise. Destreamer takes a [honeybadger](https://www.youtube.com/watch?v=4r7wHMg5Yjg) approach towards the OS it's running on, tested on Windows, results may vary, feel free to open an issue if trouble arise.
## USAGE ## USAGE
* Edit `destreamer.ts` and replace the username const with your own, you may still need to enter your password or go through 2FA if you don't have the STS cookie saved in Chrome. If you do (i.e. you usually log in to Microsoft Stream with Chrome), then you may try turning `headless: false` to `true` for a truly headless experience) * Edit `destreamer.ts` and replace the username const with your own, you may still need to enter your password or go through 2FA if you don't have the STS cookie saved in Chrome. If you do (i.e. you usually log in to Microsoft Stream with Chrome), then you may try turning `headless: false` to `true` for a truly headless experience)
* To choose preferred video format and quality you can use the "--format" option, it doesn't add anyting new, it only expose a native youtube-dl option, you can find details about accepted parameters on official youtube-dl README here ===> [FORMAT SELECTION](https://github.com/ytdl-org/youtube-dl/blob/master/README.md#format-selection) * `npm install` to restore packages* `npm install` to restore packages
If you do not pass any option it will download the best available quality by default. * `npm run -s build` to transpile TypeScript to JavaScript
=======
* Edit `destreamer.ts` (`.js` if using the vanilla JS master branch) and replace the username const with your own, you may still need to enter your password or go through 2FA if you don't have the STS cookie saved in Chrome. If you do (i.e. you usually log in to Microsoft Stream with Chrome), then you may try turning `headless: false` to `true` for a truly headless experience) ```
* `npm install` to restore packages* `npm install` to restore packages $ node ./destreamer.js
* `npm run -s build` to transpile TypeScript to JavaScript
Options:
``` --help Show help [boolean]
$ node ./destreamer.js --version Show version number [boolean]
--videoUrls [array] [required]
Options: --username [string] [required]
--help Show help [boolean] --outputDirectory [string] [default: "videos"]
--version Show version number [boolean] --format, -f Expose youtube-dl --format option, for details see
--videoUrls [array] [required] https://github.com/ytdl-org/youtube-dl/blob/master/README.m
--username [string] [required] d#format-selection [string] [default: "best"]
--outputDirectory [string] [default: "videos"]
--format, -f Expose youtube-dl --format option, for details see
https://github.com/ytdl-org/youtube-dl/blob/master/README.m $ node destreamer.js --username username@example.com --outputDirectory "videos" \
d#format-selection [string] [default: "best"] --videoUrls "https://web.microsoftstream.com/video/VIDEO-1" \
"https://web.microsoftstream.com/video/VIDEO-2" \
"https://web.microsoftstream.com/video/VIDEO-3"
$ node destreamer.js --username username@example.com --outputDirectory "videos" \ ```
--videoUrls "https://web.microsoftstream.com/video/VIDEO-1" \ You can use an absolute path for `--outputDirectory`, for example `/mnt/videos`.
"https://web.microsoftstream.com/video/VIDEO-2" \
"https://web.microsoftstream.com/video/VIDEO-3" To choose preferred video format and quality you can use the `-f` (`--format`) option. It exposes a native [`youtube-dl` parameter][4].
``` If you do not pass this parameter then `youtube-dl` will download the best available quality for each video.
You can use an absolute path for `--outputDirectory`, for example `/mnt/videos`.
## EXPECTED OUTPUT
### To download a list of videos
```
~~There's no implementation that does that (yet). There's some work happening to support this, give it some time.~~ Using youtube-dl version 2019.01.17
See usage above. Launching headless Chrome to perform the OpenID Connect dance...
## EXPECTED OUTPUT Navigating to STS login page...
We are logged in. Sorry, i mean "you".
``` Got cookie. Consuming cookie...
Using youtube-dl version 2019.01.17 Looking up AMS stream locator...
Launching headless Chrome to perform the OpenID Connect dance... Video title is: Mondays with IGD 11th March-2019
At this point Chrome's job is done, shutting it down...
Navigating to STS login page... Constructing HLSv3 URL...
We are logged in. Sorry, i mean "you". Spawning youtube-dl with cookie and HLSv3 URL...
Got cookie. Consuming cookie...
Looking up AMS stream locator... [generic] manifest(format=m3u8-aapl-v3): Requesting header
Video title is: Mondays with IGD 11th March-2019 [generic] manifest(format=m3u8-aapl-v3): Downloading m3u8 information
At this point Chrome's job is done, shutting it down... [download] Destination: Mondays with IGD 11th March-2019.mp4
Constructing HLSv3 URL... ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
Spawning youtube-dl with cookie and HLSv3 URL... built with gcc 7.3.1 (GCC) 20180722
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib
[generic] manifest(format=m3u8-aapl-v3): Requesting header
[generic] manifest(format=m3u8-aapl-v3): Downloading m3u8 information [...]
[download] Destination: Mondays with IGD 11th March-2019.mp4
ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers frame= 8435 fps= 67 q=-1.0 Lsize= 192018kB time=00:05:37.38 bitrate=4662.3kbits/s speed=2.68x
built with gcc 7.3.1 (GCC) 20180722 video:186494kB audio:5380kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.074759%
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib [ffmpeg] Downloaded 196626728 bytes
[download] Download completed
[...] ```
frame= 8435 fps= 67 q=-1.0 Lsize= 192018kB time=00:05:37.38 bitrate=4662.3kbits/s speed=2.68x The video is now saved under `videos/`, or whatever the `outputDirectory` const points to.
video:186494kB audio:5380kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.074759%
[ffmpeg] Downloaded 196626728 bytes
[download] Download completed ## _IT JUST KEEPS CRASHING FOR ME!_
``` Check out this issue if it keeps crashing for you -
https://github.com/snobu/destreamer/issues/6
The video is now saved under `videos/`, or whatever the `outputDirectory` const points to.
[4]: https://github.com/ytdl-org/youtube-dl/blob/master/README.md#format-selection
## _IT JUST KEEPS CRASHING FOR ME!_
Check out this issue if it keeps crashing for you -
https://github.com/snobu/destreamer/issues/6

View file

@ -96,12 +96,15 @@ async function rentVideoForLater(videoUrls: string[], username: string, outputDi
() => { return amp.Player.players["vjs_video_3"].cache_.src } () => { return amp.Player.players["vjs_video_3"].cache_.src }
); );
const title = await page.evaluate( let title = await page.evaluate(
// Clear abuse of null assertion operator, // Clear abuse of null assertion operator,
// someone fix this please // someone fix this please
() => { return document!.querySelector(".title")!.textContent!.trim() } () => { return document!.querySelector(".title")!.textContent!.trim() }
); );
// Sanitize title
title = title.replace(/"/g, '');
console.log(`Video title is: ${title}`); console.log(`Video title is: ${title}`);
console.log('Constructing HLS URL...'); console.log('Constructing HLS URL...');