-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement function to auto-select most relevant quality
- Loading branch information
1 parent
cef427d
commit 27161ed
Showing
9 changed files
with
50 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"sessionCookie": "", | ||
"defaultResolution": { | ||
"resolution": { | ||
"width": 1920, | ||
"height": 1080 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,48 @@ | ||
import {parsePageFromUrl} from 'Main/pageParser'; | ||
import {get} from 'Main/client'; | ||
import {WistiaMedia} from 'MainTypes/types'; | ||
import {WistiaAsset, WistiaMedia} from 'MainTypes/types'; | ||
import {Resolution} from 'Types/types'; | ||
|
||
// TODO think of a better name for this file | ||
|
||
export async function getMediaOptionsForVideo(url: string) { | ||
const videoParsed = await parsePageFromUrl(url, 'video'); | ||
|
||
const mediaJson = await get(videoParsed[0].nextUrl); | ||
|
||
const wistiaMedia = JSON.parse(mediaJson) as WistiaMedia; | ||
|
||
return wistiaMedia.media.assets.filter(x => x.ext === 'mp4' || x.slug === 'original' || x.type === 'still_image'); | ||
} | ||
|
||
export function getClosestQuality(assets: WistiaAsset[], resolution: Resolution) { | ||
const exactMatch = assets.find(x => x.height === resolution.height && x.width === resolution.width); | ||
|
||
if (exactMatch) { | ||
return exactMatch; | ||
} | ||
|
||
const referenceAsset = { | ||
width: resolution.width, | ||
height: resolution.height, | ||
bitrate: 0, | ||
ext: '', | ||
display_name: '', | ||
type: '', | ||
size: 0, | ||
codec: '', | ||
url: '', | ||
slug: '' | ||
}; | ||
|
||
assets.push(referenceAsset); | ||
|
||
assets = assets.sort((a, b) => { | ||
return (a.height * a.width) - (b.height * b.width); | ||
}); | ||
|
||
const insertedPosition = assets.indexOf(referenceAsset); | ||
const isAtTop = insertedPosition === assets.length - 1; | ||
|
||
return isAtTop ? assets[assets.length - 2] : assets[insertedPosition + 1]; | ||
} |