Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
appujet committed Oct 13, 2024
1 parent b1ebff2 commit 65f217d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a simple Node.js API that allows you to search for tracks, artists, albums, and playlists on JioSaavn.

[![image](https://user-images.githubusercontent.com/23035000/116934239-b0d4a400-ac32-11eb-83f6-0c4119d59fa8.png)](https://dash.deno.com/new?url=https://github.com/appujet/jiosaavn-plugin-api)
[![image](https://user-images.githubusercontent.com/23035000/116934239-b0d4a400-ac32-11eb-83f6-0c4119d59fa8.png)](https://raw.githubusercontent.com/appujet/jiosaavn-plugin-api/refs/heads/master/main.ts)


# API Endpoints
Expand Down
140 changes: 70 additions & 70 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,6 @@ import { logger } from 'hono/logger'
import { prettyJSON } from 'hono/pretty-json'
import { HTTPException } from 'hono/http-exception'



const app = new Hono()

app.use('*', cors())
app.use('*', logger())
app.use('*', prettyJSON())

app.get('/', (c) => {
return c.text('Hello Hono!')
})
const api = new JioSaavnAPI()

app.get('/search', async (c) => {
const query = c.req.query('q')
if (!query) return c.json({ error: 'Missing query' })
const results = await api.search(encodeURIComponent(query))
return c.json(results)
})

app.get('/track', async (c) => {
const url = c.req.query('url')
const trackID = c.req.query('id')
if (trackID) {
const track = await api.getTrackById(trackID)
return c.json(track)
}
if (!url) return c.json({ error: 'Missing URL' })
const id = api.extract.track(url)
if (!id) return c.json({ error: 'Invalid URL' })
const track = await api.getTrack(id)
return c.json(track)
})

app.get('/album', async (c) => {
const url = c.req.query('url')
if (!url) return c.json({ error: 'Missing URL' })
const id = api.extract.album(url)
if (!id) return c.json({ error: 'Invalid URL' })
const album = await api.getAlbum(id)
return c.json(album)
})

app.get('/artist', async (c) => {
const url = c.req.query('url')
if (!url) return c.json({ error: 'Missing URL' })
const id = api.extract.artist(url)
if (!id) return c.json({ error: 'Invalid URL' })
const artist = await api.getArtist(id)
return c.json(artist)
})

app.get('/playlist', async (c) => {
const url = c.req.query('url')
const limit = Number(c.req.query('limit')) || 100
if (!url) return c.json({ error: 'Missing URL' })
const id = api.extract.playlist(url)
if (!id) return c.json({ error: 'Invalid URL' })
const playlist = await api.getPlaylist(id, limit)
return c.json(playlist)
})

app.get('/recommendations', async (c) => {
const id = c.req.query('id')
const limit = Number(c.req.query('limit')) || 10
if (!id) return c.json({ error: 'Missing ' })
const recommendations = await api.getRecommendations(id, limit)
return c.json(recommendations)
})

class JioSaavnAPI {

private async request<T>({
Expand Down Expand Up @@ -274,4 +204,74 @@ class JioSaavnAPI {
}
}

const app = new Hono()

app.use('*', cors())
app.use('*', logger())
app.use('*', prettyJSON())

app.get('/', (c) => {
return c.text('Hello Hono!')
})
const api = new JioSaavnAPI()

app.get('/search', async (c) => {
const query = c.req.query('q')
if (!query) return c.json({ error: 'Missing query' })
const results = await api.search(encodeURIComponent(query))
return c.json(results)
})

app.get('/track', async (c) => {
const url = c.req.query('url')
const trackID = c.req.query('id')
if (trackID) {
const track = await api.getTrackById(trackID)
return c.json(track)
}
if (!url) return c.json({ error: 'Missing URL' })
const id = api.extract.track(url)
if (!id) return c.json({ error: 'Invalid URL' })
const track = await api.getTrack(id)
return c.json(track)
})

app.get('/album', async (c) => {
const url = c.req.query('url')
if (!url) return c.json({ error: 'Missing URL' })
const id = api.extract.album(url)
if (!id) return c.json({ error: 'Invalid URL' })
const album = await api.getAlbum(id)
return c.json(album)
})

app.get('/artist', async (c) => {
const url = c.req.query('url')
if (!url) return c.json({ error: 'Missing URL' })
const id = api.extract.artist(url)
if (!id) return c.json({ error: 'Invalid URL' })
const artist = await api.getArtist(id)
return c.json(artist)
})

app.get('/playlist', async (c) => {
const url = c.req.query('url')
const limit = Number(c.req.query('limit')) || 100
if (!url) return c.json({ error: 'Missing URL' })
const id = api.extract.playlist(url)
if (!id) return c.json({ error: 'Invalid URL' })
const playlist = await api.getPlaylist(id, limit)
return c.json(playlist)
})

app.get('/recommendations', async (c) => {
const id = c.req.query('id')
const limit = Number(c.req.query('limit')) || 10
if (!id) return c.json({ error: 'Missing ' })
const recommendations = await api.getRecommendations(id, limit)
return c.json(recommendations)
})



Deno.serve(app.fetch)

0 comments on commit 65f217d

Please sign in to comment.