Skip to content

Commit

Permalink
update File.GetHLSStreamURL method
Browse files Browse the repository at this point in the history
  • Loading branch information
altaywtf committed May 10, 2023
1 parent 5e1e1e6 commit 120a5e1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
35 changes: 35 additions & 0 deletions src/resources/Files/File.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import PutioAPIClient from '../../index'

describe('resources/Files/File', () => {
const API = new PutioAPIClient({
baseURL: '',
})

it('should create correct HLS stream URL when no params given', () => {
expect(API.File.GetHLSStreamURL(0)).toBe('/files/0/hls/media.m3u8')
})

it('should add token to HLS stream url if set', () => {
API.setToken('token')

expect(API.File.GetHLSStreamURL(0)).toBe(
'/files/0/hls/media.m3u8?oauth_token=token',
)

API.clearToken()
})

it('should create correct HLS stream URL when params given', () => {
expect(API.File.GetHLSStreamURL(0, { playOriginal: true })).toBe(
'/files/0/hls/media.m3u8?original=1',
)

expect(API.File.GetHLSStreamURL(0, { maxSubtitleCount: 1 })).toBe(
'/files/0/hls/media.m3u8?max_subtitle_count=1',
)

expect(
API.File.GetHLSStreamURL(0, { playOriginal: true, maxSubtitleCount: 1 }),
).toBe('/files/0/hls/media.m3u8?max_subtitle_count=1&original=1')
})
})
11 changes: 8 additions & 3 deletions src/resources/Files/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export default class File {
{
token = '',
subtitleLanguages = [],
maxSubtitleCount = -1,
playOriginal = false,
maxSubtitleCount,
playOriginal,
}: {
token?: string
subtitleLanguages?: string[]
Expand All @@ -72,7 +72,12 @@ export default class File {
oauth_token: token || this.client.token,
subtitle_languages: subtitleLanguages,
max_subtitle_count: maxSubtitleCount,
original: playOriginal ? 1 : 0,
original:
typeof playOriginal === 'boolean'
? playOriginal
? 1
: 0
: undefined,
})
.toString()
}
Expand Down

0 comments on commit 120a5e1

Please sign in to comment.