-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3d39ae8
Showing
8 changed files
with
591 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}' | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(', ')] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |