Skip to content

Commit

Permalink
Merge pull request #685 from 3flex/axios-getDownloadSpeed
Browse files Browse the repository at this point in the history
Migrate getDownloadSpeed to jellyfin-sdk-typescript
  • Loading branch information
nielsvanvelzen authored Nov 7, 2024
2 parents f4639e4 + dd58410 commit aa1095c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/components/jellyfinActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,21 @@ export async function getLiveStream(
* @returns the bitrate in bits/s
*/
export async function getDownloadSpeed(byteSize: number): Promise<number> {
const path = `Playback/BitrateTest?size=${byteSize}`;

const now = new Date().getTime();

const response = await JellyfinApi.authAjax(path, {
timeout: 5000,
type: 'GET'
});
const response = await getMediaInfoApi(
JellyfinApi.jellyfinApi
).getBitrateTestBytes(
{
size: byteSize
},
{
timeout: 5000
}
);

// Force javascript to download the whole response before calculating bitrate
await response.blob();
await response.data;

const responseTimeSeconds = (new Date().getTime() - now) / 1000;
const bytesPerSecond = byteSize / responseTimeSeconds;
Expand Down

0 comments on commit aa1095c

Please sign in to comment.