From 3d39ae84490ca8149bafc493052a559982abb419 Mon Sep 17 00:00:00 2001 From: vidya sagar Date: Sat, 27 Nov 2021 11:48:12 +0530 Subject: [PATCH] first commit --- JioSaavn/__init__.py | 15 ++ JioSaavn/_baseApiUrl.py | 17 ++ JioSaavn/_fetch.py | 393 +++++++++++++++++++++++++++++++++++++ JioSaavn/_helper.py | 31 +++ JioSaavn/_parseResponse.py | 87 ++++++++ JioSaavn/_requests.py | 17 ++ JioSaavn/_useragent.py | 20 ++ setup.py | 11 ++ 8 files changed, 591 insertions(+) create mode 100644 JioSaavn/__init__.py create mode 100644 JioSaavn/_baseApiUrl.py create mode 100644 JioSaavn/_fetch.py create mode 100644 JioSaavn/_helper.py create mode 100644 JioSaavn/_parseResponse.py create mode 100644 JioSaavn/_requests.py create mode 100644 JioSaavn/_useragent.py create mode 100644 setup.py diff --git a/JioSaavn/__init__.py b/JioSaavn/__init__.py new file mode 100644 index 0000000..ad43ac9 --- /dev/null +++ b/JioSaavn/__init__.py @@ -0,0 +1,15 @@ +from JioSaavn._fetch import searchSong,song,songFromURL,searchAlbum,lyrics,lyricsFromURL,album + +__title__ = "JioSaavn" +__description__ = "JioSaavn Api, for Python 3." +__version__ = "0.1" + +__all__ =[ + 'searchSong', + 'song', + 'songFromURL', + 'searchAlbum', + 'lyrics', + 'lyricsFromURL', + 'album', +] diff --git a/JioSaavn/_baseApiUrl.py b/JioSaavn/_baseApiUrl.py new file mode 100644 index 0000000..3a78e35 --- /dev/null +++ b/JioSaavn/_baseApiUrl.py @@ -0,0 +1,17 @@ + + +def albumFromID(id:int): + return f'https://www.jiosaavn.com/api.php?__call=content.getAlbumDetails&_format=json&cc=in&_marker=0%3F_marker=0&albumid={id}' + +def albumsearchFromSTRING(query:str): + return f'https://www.jiosaavn.com/api.php?__call=autocomplete.get&_format=json&_marker=0&cc=in&includeMetaTags=1&query={"+".join(query.split(" "))}' + +def songFromID(id:str): + return f'https://www.jiosaavn.com/api.php?__call=song.getDetails&cc=in&_marker=0%3F_marker%3D0&_format=json&pids={id}' + +def songsearchFromSTRING(query:str,p:int,n:int): + return f'https://www.jiosaavn.com/api.php?p={p}&_format=json&_marker=0&api_version=4&ctx=wap6dot0&n={n}&__call=search.getResults&q={"+".join(query.split(" "))}' + +def lyricsFromID(id:str): + return f'https://www.jiosaavn.com/api.php?__call=lyrics.getLyrics&ctx=web6dot0&api_version=4&_format=json&_marker=0%3F_marker=0&lyrics_id={id}' + diff --git a/JioSaavn/_fetch.py b/JioSaavn/_fetch.py new file mode 100644 index 0000000..64040f4 --- /dev/null +++ b/JioSaavn/_fetch.py @@ -0,0 +1,393 @@ + +from . import _baseApiUrl,_requests +from . import _parseResponse as parse +from ._helper import getsongID + + +async def searchSong(query:str,page:int=1,limit:int=10): + '''Searches for song in JioSaavn. + Args: + query (str): Sets the search query. + page (int, optional): Sets page to the number of page. Defaults to 1. + limit (int, optional): Sets limit to the number of results. Defaults to 10. + Examples: + Calling `searchSong` function gives the search result. + >>> search = await searchSong('alone') + >>> print(search) + [ + { + "id": "HgyjuLNF", + "title": "Alone Alone (From "Malli Modalaindi")", + "image": "https://c.saavncdn.com/156/Alone-Alone-From-Malli-Modalaindi--Telugu-2021-20210920131019-150x150.jpg", + "images": { + "50x50": "https://c.saavncdn.com/156/Alone-Alone-From-Malli-Modalaindi--Telugu-2021-20210920131019-50x50.jpg", + "150x150": "https://c.saavncdn.com/156/Alone-Alone-From-Malli-Modalaindi--Telugu-2021-20210920131019-150x150.jpg", + "500x500": "https://c.saavncdn.com/156/Alone-Alone-From-Malli-Modalaindi--Telugu-2021-20210920131019-500x500.jpg" + }, + "album": "Alone Alone (From "Malli Modalaindi")", + "description": "Alone Alone (From "Malli Modalaindi") - Sid Sriram, Anup Rubens", + "has_lyrics": "false", + "singers": [ + "Sid Sriram", + "Anup Rubens" + ], + "language": "Telugu", + "album_id": "29782034", + "url": { + "song": "https://www.jiosaavn.com/song/alone-alone-from-malli-modalaindi/OA8SWwF8eXU", + "album": "https://www.jiosaavn.com/album/alone-alone-from-malli-modalaindi/lLQ4oVnaTvM_" + }, + }, + { + "id": "veJXEDAz", + "title": "Alone", + "image": "https://c.saavncdn.com/743/Alone-Punjabi-2020-20200507184621-150x150.jpg", + "images": { + "50x50": "https://c.saavncdn.com/743/Alone-Punjabi-2020-20200507184621-50x50.jpg", + "150x150": "https://c.saavncdn.com/743/Alone-Punjabi-2020-20200507184621-150x150.jpg", + "500x500": "https://c.saavncdn.com/743/Alone-Punjabi-2020-20200507184621-500x500.jpg" + }, + "album": "Alone", + "description": "Alone - Raashi Sood", + "has_lyrics": "false", + "singers": [ + "Raashi Sood" + ], + "language": "Punjabi", + "album_id": "20256407", + "url": { + "song": "https://www.jiosaavn.com/song/alone/Bg0haTF0dkk", + "album": "https://www.jiosaavn.com/album/alone/,kQ0LrBIybc_" + }, + } + ] + + ''' + return await parse.makeSearchResponse(data=await _requests.get(url=_baseApiUrl.songsearchFromSTRING(query=query,p=page,n=limit))) + +async def songFromURL(url:str,lyrics:bool=False): + '''Get song info from JioSaavn. + Args: + url (str): Sets the url of song. + lyrics (bool, optional): Sets the lyrics whether to get lyrics. Defaults to False. + Examples: + Calling `songFromURL` function gives the search result. + >>> result = await songFromURL('https://www.jiosaavn.com/song/alone/Bg0haTF0dkk') + >>> print(result) + { + "id": "veJXEDAz", + "song": "Alone", + "album": "Alone", + "year": "2020", + "primary_artists": [ + "Raashi Sood" + ], + "singers": [ + "Raashi Sood" + ], + "image": "https://c.saavncdn.com/743/Alone-Punjabi-2020-20200507184621-500x500.jpg", + "images": { + "50x50": "https://c.saavncdn.com/743/Alone-Punjabi-2020-20200507184621-50x50.jpg", + "150x150": "https://c.saavncdn.com/743/Alone-Punjabi-2020-20200507184621-150x150.jpg", + "500x500": "https://c.saavncdn.com/743/Alone-Punjabi-2020-20200507184621-500x500.jpg" + }, + "duration": "120", + "label": "Raashi Sood Music", + "albumid": "20256407", + "language": "Punjabi", + "copyright_text": "© 2020 Raashi Sood Music", + "has_lyrics": "false", + "lyrics": null, + "media_url": "https://aac.saavncdn.com/743/dc78d52426dff2c0bf8e755c4721c398_160.mp4", + "media_urls": { + "96_KBPS": "https://aac.saavncdn.com/743/dc78d52426dff2c0bf8e755c4721c398_96.mp4", + "160_KBPS": "https://aac.saavncdn.com/743/dc78d52426dff2c0bf8e755c4721c398_160.mp4", + "320_KBPS": "https://aac.saavncdn.com/743/dc78d52426dff2c0bf8e755c4721c398_320.mp4" + }, + "release_date": "2020-05-07", + "url": { + "song": "https://www.jiosaavn.com/song/alone/Bg0haTF0dkk", + "album": "https://www.jiosaavn.com/album/alone/,kQ0LrBIybc_" + }, + } + ''' + return await song(id=await getsongID(url=url),lyrics=lyrics) + +async def song(id:str,lyrics:bool=False): + '''Get song info from JioSaavn. + Args: + id (str): Sets the id of song. + lyrics (bool, optional): Sets the lyrics whether to get lyrics. Defaults to False. + Examples: + Calling `songFromID` function gives the search result. + >>> result = await songFromID('veJXEDAz') + >>> print(result) + { + "id": "veJXEDAz", + "song": "Alone", + "album": "Alone", + "year": "2020", + "primary_artists": [ + "Raashi Sood" + ], + "singers": [ + "Raashi Sood" + ], + "image": "https://c.saavncdn.com/743/Alone-Punjabi-2020-20200507184621-500x500.jpg", + "images": { + "50x50": "https://c.saavncdn.com/743/Alone-Punjabi-2020-20200507184621-50x50.jpg", + "150x150": "https://c.saavncdn.com/743/Alone-Punjabi-2020-20200507184621-150x150.jpg", + "500x500": "https://c.saavncdn.com/743/Alone-Punjabi-2020-20200507184621-500x500.jpg" + }, + "duration": "120", + "label": "Raashi Sood Music", + "albumid": "20256407", + "language": "Punjabi", + "copyright_text": "© 2020 Raashi Sood Music", + "has_lyrics": "false", + "lyrics": null, + "media_url": "https://aac.saavncdn.com/743/dc78d52426dff2c0bf8e755c4721c398_160.mp4", + "media_urls": { + "96_KBPS": "https://aac.saavncdn.com/743/dc78d52426dff2c0bf8e755c4721c398_96.mp4", + "160_KBPS": "https://aac.saavncdn.com/743/dc78d52426dff2c0bf8e755c4721c398_160.mp4", + "320_KBPS": "https://aac.saavncdn.com/743/dc78d52426dff2c0bf8e755c4721c398_320.mp4" + }, + "release_date": "2020-05-07", + "url": { + "song": "https://www.jiosaavn.com/song/alone/Bg0haTF0dkk", + "album": "https://www.jiosaavn.com/album/alone/,kQ0LrBIybc_" + }, + } + ''' + response = await _requests.get(url=_baseApiUrl.songFromID(id=id)) + return await parse.makeSongResponse(song=response[id],lyrics=lyrics) + +async def lyricsFromURL(url:str): + '''Get lyrics of a song from url (If Available) + Args: + url (str): Sets the url of song. + Examples: + Calling `lyrics` function gives the search result. + >>> result = await lyrics('blMuXL1P') + >>> print(result) + { + "lyrics": "bhali bhali bhalira bhali
sahore bahubali
bhali bhali bhalira bhali
sahore bahubali
jayaarti nike pattali pattali
bhuvanalanni jai kottali
gaganale chhatra pattali

haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass

aa janani deeksha achalam
i koduke kavachan
ippuda ammaki amm ainanduka
pulkarinchindiga i kshana

aduulu guttal mittal gaminch
pidikit pidugul patti minch
arikul vargal durgal jayinch
avaniki swarganne dinch

ant maha baludina amm ori pasiwade
shivudaina bhavudaina ammaku sat kadantade

haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haiss rudrass
haisarbhadra samudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass

bhali bhali bhalira bhali
sahore bahubali
jayaarti nike pattali
bhali bhali bhalira bhali
sahore bahubali
jayaarti nike pattali pattali
bhuvanalanni jai kottali
gaganale chhatra pattali", + "lyrics_copyright": "Writer(s): M. M. Keeravaani, Shiva Shakthi Datta, K. Ramakrishna Lyrics powered by www.musixmatch.com", + "snippet": "haiss rudrass haisarbhadra samudrass" + } + ''' + data = await _requests.get(_baseApiUrl.lyricsFromID(id=await getsongID(url=url))) + if data.get('status' ) == "failure": + return {'status': f'{id} Has No Lyric'} + return {'lyrics':data.get('lyrics'), + 'lyrics_copyright':data.get('lyrics_copyright'), + 'snippet':data.get('snippet') + } + +async def lyrics(id:str): + '''Get lyrics of a song from id (If Available) + Args: + id (str): Sets the id of song. + Examples: + Calling `lyrics` function gives the search result. + >>> result = await lyrics('blMuXL1P') + >>> print(result) + { + "lyrics": "bhali bhali bhalira bhali
sahore bahubali
bhali bhali bhalira bhali
sahore bahubali
jayaarti nike pattali pattali
bhuvanalanni jai kottali
gaganale chhatra pattali

haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass

aa janani deeksha achalam
i koduke kavachan
ippuda ammaki amm ainanduka
pulkarinchindiga i kshana

aduulu guttal mittal gaminch
pidikit pidugul patti minch
arikul vargal durgal jayinch
avaniki swarganne dinch

ant maha baludina amm ori pasiwade
shivudaina bhavudaina ammaku sat kadantade

haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haiss rudrass
haisarbhadra samudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass
haiss rudrass haisarbhadra samudrass

bhali bhali bhalira bhali
sahore bahubali
jayaarti nike pattali
bhali bhali bhalira bhali
sahore bahubali
jayaarti nike pattali pattali
bhuvanalanni jai kottali
gaganale chhatra pattali", + "lyrics_copyright": "Writer(s): M. M. Keeravaani, Shiva Shakthi Datta, K. Ramakrishna Lyrics powered by www.musixmatch.com", + "snippet": "haiss rudrass haisarbhadra samudrass" + } + ''' + data = await _requests.get(_baseApiUrl.lyricsFromID(id=id)) + if data.get('status' ) == "failure": + return {'status': f'{id} Has No Lyric'} + return {'lyrics':data.get('lyrics'), + 'lyrics_copyright':data.get('lyrics_copyright'), + 'snippet':data.get('snippet') + } + +async def searchAlbum(query:str): + '''Searches for album in JioSaavn. + Args: + query (str): Sets the search query. + Examples: + Calling `searchAlbum` function gives the search result. + >>> search = await searchAlbum('Alone') + >>> print(search) + [ + { + "id": "29782034", + "title": "Alone Alone (From "Malli Modalaindi")", + "image": "https://c.saavncdn.com/156/Alone-Alone-From-Malli-Modalaindi--Telugu-2021-20210920131019-150x150.jpg", + "images": { + "50x50": "https://c.saavncdn.com/156/Alone-Alone-From-Malli-Modalaindi--Telugu-2021-20210920131019-50x50.jpg", + "150x150": "https://c.saavncdn.com/156/Alone-Alone-From-Malli-Modalaindi--Telugu-2021-20210920131019-150x150.jpg", + "500x500": "https://c.saavncdn.com/156/Alone-Alone-From-Malli-Modalaindi--Telugu-2021-20210920131019-500x500.jpg" + }, + "music": "Sid Sriram, Anup Rubens", + "description": "2021 · Telugu Album · Sid Sriram, Anup Rubens", + "year": "2021", + "language": "Telugu", + "url": "https://www.jiosaavn.com/album/alone-alone-from-malli-modalaindi/lLQ4oVnaTvM_", + "song": "HgyjuLNF", + }, + { + "id": "1215558", + "title": "Alone", + "image": "https://c.saavncdn.com/794/Alone-Hindi-2014-150x150.jpg", + "images": { + "50x50": "https://c.saavncdn.com/794/Alone-Hindi-2014-50x50.jpg", + "150x150": "https://c.saavncdn.com/794/Alone-Hindi-2014-150x150.jpg", + "500x500": "https://c.saavncdn.com/794/Alone-Hindi-2014-500x500.jpg" + }, + "music": "Ankit Tiwari", + "description": "2014 · Hindi Film · Ankit Tiwari", + "year": "2014", + "language": "Hindi", + "url": "https://www.jiosaavn.com/album/alone/MmI5C7Qd8xU_", + "song": "woZT1XKb, BW3ZjaVE, 30LGCvEo, IVnaw30E", + }, + ] + ''' + return await parse.makeAlbumSearchResponse(data=await _requests.get(_baseApiUrl.albumsearchFromSTRING(query=query))) + +async def album(id:str): + '''Searches for album in JioSaavn. + Args: + id (str): Sets thr id of album. + Examples: + Calling `album` function gives the search result. + >>> result = await album('1215558') + >>> print(result) + { + "albumid": "10496527", + "title": "Baahubali 2 - The Conclusion", + "name": "Baahubali 2 - The Conclusion", + "year": "2017", + "primary_artists": [ + "M. M. Keeravani" + ], + "image": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-150x150.jpg", + "songs": [ + { + "id": "blMuXL1P", + "song": "Saahore Baahubali", + "album": "Baahubali 2 - The Conclusion", + "year": "2017", + "primary_artists": [ + "Daler Mehndi", + "M. M. Keeravani", + "Mounima Ch" + ], + "singers": [ + "Daler Mehndi", + "M. M. Keeravani", + "Mounima Ch" + ], + "image": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-500x500.jpg", + "images": { + "50x50": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-50x50.jpg", + "150x150": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-150x150.jpg", + "500x500": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-500x500.jpg" + }, + "duration": "203", + "label": "Lahari Music", + "albumid": "10496527", + "language": "Telugu", + "copyright_text": "© 2017 Lahari Music", + "has_lyrics": "true", + "lyrics": null, + "media_url": "https://aac.saavncdn.com/271/22dda6f74d38544c0b0d27d65ddddac1_160.mp4", + "media_urls": { + "96_KBPS": "https://aac.saavncdn.com/271/22dda6f74d38544c0b0d27d65ddddac1_96.mp4", + "160_KBPS": "https://aac.saavncdn.com/271/22dda6f74d38544c0b0d27d65ddddac1_160.mp4", + "320_KBPS": "https://aac.saavncdn.com/271/22dda6f74d38544c0b0d27d65ddddac1_320.mp4" + }, + "release_date": "2017-03-26", + "url": { + "song": "https://www.jiosaavn.com/song/saahore-baahubali/EgQmRCx8BmM", + "album": "https://www.jiosaavn.com/album/baahubali-2---the-conclusion/Vm5jaOSkM7E_" + }, + }, + { + "id": "XvwEmXL_", + "song": "Hamsa Naava", + "album": "Baahubali 2 - The Conclusion", + "year": "2017", + "primary_artists": [ + "Sony", + "Deepu" + ], + "singers": [ + "Sony", + "Deepu" + ], + "image": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-500x500.jpg", + "images": { + "50x50": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-50x50.jpg", + "150x150": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-150x150.jpg", + "500x500": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-500x500.jpg" + }, + "duration": "204", + "label": "Lahari Music", + "albumid": "10496527", + "language": "Telugu", + "copyright_text": "© 2017 Lahari Music", + "has_lyrics": "true", + "lyrics": null, + "media_url": "https://aac.saavncdn.com/271/5d651eeaa54b93af16a7c39999615f2d_160.mp4", + "media_urls": { + "96_KBPS": "https://aac.saavncdn.com/271/5d651eeaa54b93af16a7c39999615f2d_96.mp4", + "160_KBPS": "https://aac.saavncdn.com/271/5d651eeaa54b93af16a7c39999615f2d_160.mp4", + "320_KBPS": "https://aac.saavncdn.com/271/5d651eeaa54b93af16a7c39999615f2d_320.mp4" + }, + "release_date": "2017-03-26", + "url": { + "song": "https://www.jiosaavn.com/song/hamsa-naava/KB4cdBloe2w", + "album": "https://www.jiosaavn.com/album/baahubali-2---the-conclusion/Vm5jaOSkM7E_" + }, + }, + { + "id": "M3D7qn6T", + "song": "Kannaa Nidurinchara", + "album": "Baahubali 2 - The Conclusion", + "year": "2017", + "primary_artists": [ + "Sreenidhi Tirumala", + "V. Srisoumya" + ], + "singers": [ + "Sreenidhi Tirumala", + "V. Srisoumya" + ], + "image": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-500x500.jpg", + "images": { + "50x50": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-50x50.jpg", + "150x150": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-150x150.jpg", + "500x500": "https://c.saavncdn.com/271/Baahubali-2-The-Conclusion-Telugu-2017-500x500.jpg" + }, + "duration": "291", + "label": "Lahari Music", + "albumid": "10496527", + "language": "Telugu", + "copyright_text": "© 2017 Lahari Music", + "has_lyrics": "true", + "lyrics": null, + "media_url": "https://aac.saavncdn.com/271/5e4fe5350641ff6c285d79676a483222_160.mp4", + "media_urls": { + "96_KBPS": "https://aac.saavncdn.com/271/5e4fe5350641ff6c285d79676a483222_96.mp4", + "160_KBPS": "https://aac.saavncdn.com/271/5e4fe5350641ff6c285d79676a483222_160.mp4", + "320_KBPS": "https://aac.saavncdn.com/271/5e4fe5350641ff6c285d79676a483222_320.mp4" + }, + "release_date": "2017-03-26", + "url": { + "song": "https://www.jiosaavn.com/song/kannaa-nidurinchara/PVsvBgVeAWc", + "album": "https://www.jiosaavn.com/album/baahubali-2---the-conclusion/Vm5jaOSkM7E_" + }, + }, + ], + "perma_url": "https://www.jiosaavn.com/album/baahubali-2---the-conclusion/Vm5jaOSkM7E_", + "release_date": "2017-03-26" + } + ''' + return await parse.makeAlbumResponse(data=await _requests.get(_baseApiUrl.albumFromID(id=id))) diff --git a/JioSaavn/_helper.py b/JioSaavn/_helper.py new file mode 100644 index 0000000..328df42 --- /dev/null +++ b/JioSaavn/_helper.py @@ -0,0 +1,31 @@ + +import aiohttp + + +def ucfirst(string:str): + return string.capitalize() + +def makeDifferentQualityMediaUrls(url:str): + replaced = url.replace("preview.saavncdn.com", "aac.saavncdn.com") + return {"96_KBPS": replaced.replace("_96_p", "_96"), + "160_KBPS": replaced.replace("_96_p", "_160"), + "320_KBPS": replaced.replace("_96_p", "_320"),} + +def makeDifferentQualityImages(image:str): + image = image[:image.rfind('-')] + return {"50x50": f'{image}-50x50.jpg', + "150x150": f'{image}-150x150.jpg', + "500x500": f'{image}-500x500.jpg',} + +async def getsongID(url): + async with aiohttp.ClientSession() as session: + async with session.get(url,data=[('bitrate', '320')]) as resp: + res = await resp.text() + try: + return res.split('"song":{"type":"')[1].split('","image":')[0].split('"id":"')[-1] + except IndexError: + return(res.split('"pid":"'))[1].split('","')[0] + +# def generateAPIUrlsFromPids(pids:str): +# return [f'{APP_URL}/song?id={i}' for i in pids.split(', ')] + diff --git a/JioSaavn/_parseResponse.py b/JioSaavn/_parseResponse.py new file mode 100644 index 0000000..cdf8f4e --- /dev/null +++ b/JioSaavn/_parseResponse.py @@ -0,0 +1,87 @@ + +from . import _fetch ,_helper + + +async def makeSearchResponse(data): + result =[] + for i in data['results']: + images = _helper.makeDifferentQualityImages(i['image']) + singers = ', '.join([q['name'] for q in i['more_info']['artistMap']['primary_artists']]) + data = { + 'id':i['id'], + 'title':i['title'], + 'image':images["150x150"], + 'images':images, + 'album':i['more_info']['album'], + 'description':f"{i['more_info']['album']} - {singers}" if singers else i['more_info']['album'], + 'has_lyrics':i['more_info']['has_lyrics'], + 'singers':singers.split(', '), + 'language':_helper.ucfirst(i['language']), + 'album_id':i['more_info']['album_id'], + 'url':{ + 'song':i['perma_url'], + 'album':i['more_info']['album_url'], + }, + } + result.append(data) + return result + +async def makeSongResponse(song,lyrics:bool=False): + media_urls = _helper.makeDifferentQualityMediaUrls(song['media_preview_url']) + images = _helper.makeDifferentQualityImages(song['image']) + return { + 'id': song['id'], + 'song': song['song'], + 'album': song['album'], + 'year': song['year'], + 'primary_artists': (song['primary_artists']).split(', '), + 'singers': (song['singers']).split(', '), + 'image': images["500x500"], + 'images':images, + 'duration': song['duration'], + 'label': song['label'], + 'albumid': song['albumid'], + 'language': _helper.ucfirst(song['language']), + 'copyright_text': song['copyright_text'], + 'has_lyrics': song['has_lyrics'], + 'lyrics': await _fetch.lyrics(song['id']) if song['has_lyrics'] == "true" and lyrics else None, + 'media_url': media_urls["160_KBPS"], + 'media_urls':media_urls, + 'release_date': song['release_date'], + 'url':{ + 'song': song['perma_url'], + 'album': song['album_url'], + }, + } + +async def makeAlbumSearchResponse(data): + result =[] + for i in data['albums']['data']: + images = _helper.makeDifferentQualityImages(i['image']) + _data = { + 'id': i['id'], + 'title': i['title'], + 'image': images["150x150"], + 'images':images, + 'music': i['music'], + 'description': i['description'], + 'year': i['more_info']['year'], + 'language': _helper.ucfirst(i['more_info']['language']), + 'url': i['url'], + 'song':i['more_info']['song_pids'], + } + result.append(_data) + return result + +async def makeAlbumResponse(data): + return { + 'albumid': data['albumid'], + 'title': data['title'], + 'name': data['name'], + 'year': data['year'], + 'primary_artists': (data['primary_artists']).split(', '), + 'image': data['image'], + 'songs':[await makeSongResponse(song=song) for song in data['songs']], + 'perma_url': data['perma_url'], + 'release_date': data['release_date'], + } diff --git a/JioSaavn/_requests.py b/JioSaavn/_requests.py new file mode 100644 index 0000000..3e15085 --- /dev/null +++ b/JioSaavn/_requests.py @@ -0,0 +1,17 @@ + +import aiohttp +import json + +from ._useragent import getRandomUserAgent + + +async def get(url:str): + async with aiohttp.ClientSession(headers=getRandomUserAgent()) as session: + async with session.get(url) as response: + if not response.status == 404: + return json.loads(await response.text()) + return None + + +# async def FetchHttpbin(): +# return await get(url='http://httpbin.org/headers') diff --git a/JioSaavn/_useragent.py b/JioSaavn/_useragent.py new file mode 100644 index 0000000..dfe6924 --- /dev/null +++ b/JioSaavn/_useragent.py @@ -0,0 +1,20 @@ +import random + +# data = open('core/user-agents.txt').read().splitlines() +data = ['Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36', + 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36', + 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36' + ] +def getRandomUserAgent(): + return { + 'Host': 'www.jiosaavn.com', + 'accept': 'application/json, text/plain, */*', + 'user-agent': random.choice(data), + 'sec-fetch-site': 'same-origin', + 'sec-fetch-mode': 'cors', + 'sec-fetch-dest': 'empty', + 'accept-encoding': 'gzip, deflate, br', + 'accept-language': 'en-US,en;q=0.9' + } \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8568e83 --- /dev/null +++ b/setup.py @@ -0,0 +1,11 @@ +import setuptools + +setuptools.setup(name='JioSaavn', + version='0.1', + description='JioSaavn Api', + url='#', + author='vidya sagar', + install_requires=['aiohttp'], + author_email='', + packages=setuptools.find_packages(), + zip_safe=False) \ No newline at end of file