Skip to content

Commit

Permalink
jiosaavn download script
Browse files Browse the repository at this point in the history
  • Loading branch information
rpakishore committed Aug 17, 2023
1 parent 215d5f5 commit 1ddbc8e
Show file tree
Hide file tree
Showing 15 changed files with 499 additions and 39 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<!--- Heading --->
<div align="center">
<img src="assets/banner.png" alt="banner" width="auto" height="auto" />
<h1>Template README</h1>
<h1>Jiosaavn Music Download</h1>
<p>
An awesome README template for your projects!
</p>
<h4>
<a href="https://github.com/rpakishore/Template-Python/">View Demo</a>
<a href="https://github.com/rpakishore/Jiosaavn/">View Demo</a>
<span> · </span>
<a href="https://github.com/rpakishore/Template-Python">Documentation</a>
<a href="https://github.com/rpakishore/Jiosaavn">Documentation</a>
<span> · </span>
<a href="https://github.com/rpakishore/Template-Python/issues/">Report Bug</a>
<a href="https://github.com/rpakishore/Jiosaavn/issues/">Report Bug</a>
<span> · </span>
<a href="https://github.com/rpakishore/Template-Python/issues/">Request Feature</a>
<a href="https://github.com/rpakishore/Jiosaavn/issues/">Request Feature</a>
</h4>
</div>
<br />

![GitHub commit activity](https://img.shields.io/github/commit-activity/m/rpakishore/Template-Python)
![GitHub last commit](https://img.shields.io/github/last-commit/rpakishore/Template-Python)
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/rpakishore/Jiosaavn)
![GitHub last commit](https://img.shields.io/github/last-commit/rpakishore/Jiosaavn)
<!-- Table of Contents -->
<h2>Table of Contents</h2>

Expand Down Expand Up @@ -175,7 +175,7 @@ See LICENSE.txt for more information.

Arun Kishore - [@rpakishore](mailto:pypi@rpakishore.co.in)

Project Link: [https://github.com/rpakishore/Template-Python](https://github.com/rpakishore/Template-Python)
Project Link: [https://github.com/rpakishore/Jiosaavn](https://github.com/rpakishore/Jiosaavn)

<!-- Acknowledgments -->
## 9. Acknowledgements
Expand Down
132 changes: 131 additions & 1 deletion development.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,136 @@
"df = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6], 'c':[7,8,9]})\n",
"show(df)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'320kbps': 'true',\n",
" 'album': 'Chhichhore',\n",
" 'album_url': 'https://www.jiosaavn.com/album/chhichhore/V4F3M5,cNb4_',\n",
" 'albumid': '17132913',\n",
" 'artistMap': {'Amitabh Bhattacharya': '458681',\n",
" 'Arijit Singh': '459320',\n",
" 'Naveen Polishetty': '6531701',\n",
" 'Prateik Babbar': '457932',\n",
" 'Pritam': '456323',\n",
" 'Shraddha Kapoor': '477854',\n",
" 'Sushant Singh Rajput': '8190578',\n",
" 'Tahir Raj Bhasin': '2370737',\n",
" 'Tushar Pandey': '5860917',\n",
" 'Varun Sharma': '670950'},\n",
" 'cache_state': 'false',\n",
" 'copyright_text': '© 2019 Super Cassettes Industries Private Limited',\n",
" 'disabled': 'true',\n",
" 'disabled_text': 'Pro Only',\n",
" 'duration': '280',\n",
" 'encrypted_media_path': 'NMKyboFo/FiZnfntRvcNSgxBfKN/LJGe0TslqweHfFAeuHKuIiOIA1/8vqsn8+qW',\n",
" 'encrypted_media_url': 'ID2ieOjCrwfgWvL5sXl4B1ImC5QfbsDyYhe68adzBZAKJQK9qjdF4unN9Zgscia9R+nDZkn3d967D1djfXn5Vxw7tS9a8Gtq',\n",
" 'explicit_content': 0,\n",
" 'featured_artists': '',\n",
" 'featured_artists_id': '',\n",
" 'has_lyrics': 'true',\n",
" 'id': 'OhnxgY6_',\n",
" 'image': 'https://c.saavncdn.com/937/Chhichhore-Hindi-2019-20190904104023-500x500.jpg',\n",
" 'is_dolby_content': False,\n",
" 'label': '',\n",
" 'label_url': '/label/-albums/6DLuXO3VoTo_',\n",
" 'language': 'hindi',\n",
" 'lyrics_snippet': 'Tumhare bin deewane ka kya haal hai',\n",
" 'media_preview_url': 'https://preview.saavncdn.com/937/98dfd33cd388084fd76fadf65165a10e_96_p.mp4',\n",
" 'media_url': 'https://aac.saavncdn.com/937/98dfd33cd388084fd76fadf65165a10e_320.mp4',\n",
" 'music': 'Pritam',\n",
" 'music_id': '456323',\n",
" 'origin': 'none',\n",
" 'perma_url': 'https://www.jiosaavn.com/song/khairiyat/PwAFSRNpAWw',\n",
" 'play_count': 166751111,\n",
" 'primary_artists': 'Pritam, Arijit Singh',\n",
" 'primary_artists_id': '456323, 459320',\n",
" 'release_date': '2019-08-31',\n",
" 'rights': {'cacheable': True,\n",
" 'code': 1,\n",
" 'delete_cached_object': False,\n",
" 'reason': 'Pro Only'},\n",
" 'singers': 'Pritam, Arijit Singh',\n",
" 'song': 'Khairiyat',\n",
" 'starred': 'false',\n",
" 'starring': 'Sushant Singh Rajput, Shraddha Kapoor, Sushant Singh Rajput, Prateik Babbar, Shraddha Kapoor, Varun Sharma, Prateik Babbar, Tushar Pandey, Tahir Raj Bhasin, Naveen Polishetty',\n",
" 'triller_available': False,\n",
" 'type': '',\n",
" 'vcode': '010910091004952',\n",
" 'vlink': 'https://jiotunepreview.jio.com/content/Converted/010910090961459.mp3',\n",
" 'webp': True,\n",
" 'year': '2019'}"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from jiosaavn.request_package import req\n",
"requests = req()\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from dataclasses import dataclass\n",
"\n",
"@dataclass\n",
"class SongInfo:\n",
" name: str\n",
" album: str\n",
" artists: list[str]\n",
" duration: int\n",
" image: str\n",
" language: str\n",
" media_url: str\n",
" singers: list[str]\n",
" id: str\n",
" \n",
" def __contains__(self, value):\n",
" return value in self.id\n",
"\n",
"song_url = 'https://www.jiosaavn.com/song/khairiyat/PwAFSRNpAWw'\n",
"def song(song_url: str) -> SongInfo:\n",
" assert 'https://www.jiosaavn.com/song/' in song_url\n",
" url = f'http://192.168.107.10:9027/song/?query={song_url}'\n",
" res = requests.get(url).json()\n",
" \n",
" return SongInfo(\n",
" name = res.get('song'),\n",
" album=res.get('album'),\n",
" duration=int(res.get('duration')),\n",
" artists = [key for key in res.get('artistMap').keys()],\n",
" image=res.get('image'),\n",
" language=res.get('language'),\n",
" media_url=res.get('media_url'),\n",
" singers=res.get('singers').split(', '),\n",
" id= res.get('music_id')\n",
" )\n",
"'456323' in [song(song_url)]"
]
}
],
"metadata": {
Expand All @@ -31,7 +161,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.2"
"version": "3.10.11"
},
"orig_nbformat": 4
},
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

[project]
name = "template_python"
name = "jiosaavn"
authors = [{name = "Arun Kishore", email = "pypi@rpakishore.co.in"}]
readme = "README.md"
license = {file = "LICENSE"}
classifiers = ["License :: OSI Approved :: MIT License"]
dynamic = ["version", "description"]
dependencies = [
"pandas",
"ak_cache",
"typer[all]", #cli_app.py
"icecream",
"slack_sdk", #Slack.py
"requests", #request_package
"beautifulsoup4", #request_package
"keyring" #credentials.py
"ffmpy",
"eyed3"
]

[project.optional-dependencies]
Expand All @@ -30,4 +31,4 @@ test = [
Home = "https://github.com/rpakishore/Template-Python"

[project.scripts]
app="template_python.cli_app:app"
app="jiosaavn.cli_app:app"
40 changes: 40 additions & 0 deletions src/jiosaavn/Cacher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from pathlib import Path
import pickle
from jiosaavn.debugger import ic

class Cache:
def __init__(self, filepath: str) -> None:
self.filepath = Path(filepath)
self.cache_data = None

def __str__(self) -> str:
return f"Cache file for Jiosaavn downloaded from {self.filepath.name}\n\nData:\n{self.cache_data}"

def __repr__(self) -> str:
return f"Cache({self.filepath})"

@property
def data(self) -> list:
if self.cache_data is None:
if not self.filepath.is_file():
self.cache_data = self._write_to_pickle([])
else:
with open(self.filepath, 'rb') as f:
self.cache_data = pickle.load(f)
return self.cache_data

def write(self, data: list) -> list:
"""Write the `data` to cache file
Returns:
list: `data`
"""
self.cache_data = self._write_to_pickle(data)
return self.data

def _write_to_pickle(self, data: list) -> list:
with open(self.filepath, 'wb') as f:
pickle.dump(data, f)
ic('Cache Updated')
return data

2 changes: 1 addition & 1 deletion src/template_python/Slack.py → src/jiosaavn/Slack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Import WebClient from Python SDK (github.com/slackapi/python-slack-sdk)
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
from template_python.credentials import getpwd
from jiosaavn.credentials import getpwd

class Slack_instance:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"Placeholder module info"
__version__ = "0.0.1"

from template_python.debugger import *
from jiosaavn.debugger import *
43 changes: 43 additions & 0 deletions src/jiosaavn/api_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from dataclasses import dataclass
from jiosaavn.file_parser import Song
from jiosaavn.debugger import ic
from jiosaavn.request_package import Req

class SaavnAPI:
session = Req()
def __init__(self, baseurl: str, port: int = 80):
self.baseurl = baseurl
self.port = port
self.url = f"http://{baseurl}:{port}"

def __str__(self) -> str:
return f"SaavnAPI class for {self.url}"

def __repr__(self) -> str:
return f"SaavnAPI({self.baseurl}, {self.port})"

def song(self, url: str) -> Song:
data = self.session.get(f"{self.url}/song/?query={url}").json()
return _song_from_json(data)

def playlist(self, url: str) -> tuple[Song]:
data = self.session.get(f"{self.url}/result/?query={url}").json()
return (_song_from_json(song) for song in data.get('songs'))


def _song_from_json(data: dict) -> Song:
if type(data.get('artistMap')) == dict:
artists = list(data.get('artistMap').keys())
else:
artists = []

return Song(
song_id = data['id'],
name = data['song'],
album = data['album'],
media_url= data['media_url'],
primary_artists= data['primary_artists'].split(', '),
artists= artists,
year = int(data.get('year', 0)),
image_url= data.get('image')
)
2 changes: 1 addition & 1 deletion src/template_python/cli_app.py → src/jiosaavn/cli_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path

#Default import to globally enable/disable debugger
from template_python.debugger import *
from jiosaavn.debugger import *
ic.configureOutput(prefix=f'{Path(__file__).name} -> ')

app = typer.Typer()
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1ddbc8e

Please sign in to comment.