Skip to content

Commit f4e91f5

Browse files
authored
Merge pull request #83 from saibendalam/main
fix: fixed regex pattern to work with all playlist links
2 parents d231de2 + 9b05b14 commit f4e91f5

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

bun.lockb

0 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@
7070
"typescript": "^5.4.3",
7171
"vitest": "^1.4.0"
7272
}
73-
}
73+
}

src/modules/playlists/controllers/playlist.controller.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,30 @@ describe('PlaylistController', () => {
1111
playlistController.initRoutes()
1212
})
1313

14-
it('retrieve playlist by link', async () => {
14+
it('retrieve playlist by featured link', async () => {
1515
const response = await playlistController.controller.request(
1616
'/playlists?link=https://www.jiosaavn.com/featured/its-indie-english/AMoxtXyKHoU_'
1717
)
1818

1919
const { data } = (await response.json()) as { data: z.infer<typeof PlaylistModel> }
2020
expect(() => PlaylistModel.parse(data)).not.toThrow()
2121
})
22+
it('retrieve playlist by saavn domain link', async () => {
23+
const response = await playlistController.controller.request(
24+
'/playlists?link=https://www.saavn.com/s/playlist/cf3c2fb07449311f87f53670da0e3d20/gautham-menon-telugu-hits/4sylrSC21MjvZ3uUE6bUVw__'
25+
)
26+
27+
const { data } = (await response.json()) as { data: z.infer<typeof PlaylistModel> }
28+
expect(() => PlaylistModel.parse(data)).not.toThrow()
29+
})
30+
it('retrieve playlist by jiosaavn domain link', async () => {
31+
const response = await playlistController.controller.request(
32+
'/playlists?link=https://www.jiosaavn.com/s/playlist/cf3c2fb07449311f87f53670da0e3d20/best-of-2022/BD9hSFlc9ubvZ3uUE6bUVw__'
33+
)
34+
35+
const { data } = (await response.json()) as { data: z.infer<typeof PlaylistModel> }
36+
expect(() => PlaylistModel.parse(data)).not.toThrow()
37+
})
2238

2339
it('retrieve playlist by ID', async () => {
2440
const response = await playlistController.controller.request('/playlists?id=82914609')

src/modules/playlists/controllers/playlist.controller.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ export class PlaylistController implements Routes {
3434
.string()
3535
.url()
3636
.optional()
37-
.transform((value) => value?.match(/jiosaavn\.com\/featured\/[^/]+\/([^/]+)$/)?.[1])
37+
.transform((value) => {
38+
const matches = value?.match(
39+
/(?:jiosaavn\.com|saavn\.com)\/(?:featured|s\/playlist)\/[^/]+\/([^/]+)$|(?:\/([^/]+)$)/
40+
)
41+
const filteredMatches = matches?.filter((each) => each !== undefined)
42+
return (filteredMatches && filteredMatches[filteredMatches?.length - 1 || 0]) || undefined
43+
})
3844
.openapi({
3945
title: 'Playlist Link',
4046
description: 'A direct link to the playlist on JioSaavn',

0 commit comments

Comments
 (0)