Skip to content

Commit

Permalink
Serving from appropriate CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberboysumanjay committed Aug 11, 2020
1 parent a2b84fd commit 3a18fa9
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions lib/API/saavn.dart
Original file line number Diff line number Diff line change
@@ -8,7 +8,10 @@ String key = "38346591";
String decrypt = "";

Future<List> fetchSongsList(searchQuery) async {
String searchUrl = "https://www.jiosaavn.com/api.php?app_version=5.18.3&api_version=4&readable_version=5.18.3&v=79&_format=json&query=" + searchQuery + "&__call=autocomplete.get";
String searchUrl =
"https://www.jiosaavn.com/api.php?app_version=5.18.3&api_version=4&readable_version=5.18.3&v=79&_format=json&query=" +
searchQuery +
"&__call=autocomplete.get";
var res = await http.get(searchUrl, headers: {"Accept": "application/json"});
var resEdited = (res.body).split("-->");
var getMain = json.decode(resEdited[1]);
@@ -19,29 +22,47 @@ Future<List> fetchSongsList(searchQuery) async {
}

Future fetchSongDetails(songId) async {
String songUrl = "https://www.jiosaavn.com/api.php?app_version=5.18.3&api_version=4&readable_version=5.18.3&v=79&_format=json&__call=song.getDetails&pids=" + songId;
String songUrl =
"https://www.jiosaavn.com/api.php?app_version=5.18.3&api_version=4&readable_version=5.18.3&v=79&_format=json&__call=song.getDetails&pids=" +
songId;
var res = await http.get(songUrl, headers: {"Accept": "application/json"});
var resEdited = (res.body).split("-->");
var getMain = json.decode(resEdited[1]);

title = (getMain[songId]["title"]).toString().split("(")[0].replaceAll("&amp;", "&");
title = (getMain[songId]["title"])
.toString()
.split("(")[0]
.replaceAll("&amp;", "&");
image = (getMain[songId]["image"]);
artist = (getMain[songId]["more_info"]["artistMap"]["primary_artists"][0]["name"]);
album = (getMain[songId]["more_info"]["album"]).toString().replaceAll("&quot;", "\"").replaceAll("&amp;", "&");
artist =
(getMain[songId]["more_info"]["artistMap"]["primary_artists"][0]["name"]);
album = (getMain[songId]["more_info"]["album"])
.toString()
.replaceAll("&quot;", "\"")
.replaceAll("&amp;", "&");

String lyricsUrl = "https://www.jiosaavn.com/api.php?__call=lyrics.getLyrics&lyrics_id=" + songId + "&ctx=web6dot0&api_version=4&_format=json";
var lyricsRes = await http.get(lyricsUrl, headers: {"Accept": "application/json"});
String lyricsUrl =
"https://www.jiosaavn.com/api.php?__call=lyrics.getLyrics&lyrics_id=" +
songId +
"&ctx=web6dot0&api_version=4&_format=json";
var lyricsRes =
await http.get(lyricsUrl, headers: {"Accept": "application/json"});
var lyricsEdited = (lyricsRes.body).split("-->");
var fetchedLyrics = json.decode(lyricsEdited[1]);

lyrics = fetchedLyrics["lyrics"].toString().replaceAll("<br>", "\n");

kUrl = await DesPlugin.decrypt(key, getMain[songId]["more_info"]["encrypted_media_url"]);
kUrl = await DesPlugin.decrypt(
key, getMain[songId]["more_info"]["encrypted_media_url"]);
kUrl = kUrl
.replaceAll("aac.saavncdn.com", "h.saavncdn.com")
.replaceAll("c.saavncdn.com", "h.saavncdn.com")
.replaceAll("_96.mp4", "_320.mp3")
.replaceAll("https://", "https://snoidcdnems01.cdnsrv.jio.com/");
.replaceAll("_96.mp4", "_320.mp3");

final client = http.Client();
final request = new http.Request('GET', Uri.parse(kUrl))
..followRedirects = false;
final response = await client.send(request);
kUrl = (response.headers['location']);
print(kUrl);
}

0 comments on commit 3a18fa9

Please sign in to comment.