Skip to content

Commit

Permalink
feat: init with support for models and album endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 11, 2023
0 parents commit f5acede
Show file tree
Hide file tree
Showing 30 changed files with 2,996 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/
10 changes: 10 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a"
channel: "stable"

project_type: package
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Add your license here.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.

## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.

## Getting started

TODO: List prerequisites and provide or point to information on how to
start using the package.

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.

```dart
const like = 'sample';
```

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
4 changes: 4 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
3 changes: 3 additions & 0 deletions lib/jiosaavn.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library jiosaavn;

export 'src/jiosaavn.dart';
46 changes: 46 additions & 0 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'dart:convert';

import 'package:dio/dio.dart';

abstract class BaseClient {
final BaseOptions? options;
final Dio dio;
BaseClient([this.options])
: dio = Dio(
options ??
BaseOptions(
baseUrl: 'https://www.jiosaavn.com/api.php',
queryParameters: {
'_format': 'json',
'_marker': '0',
'ctx': 'wap6dot0',
},
responseType: ResponseType.json,
),
);

Future<Map<String, dynamic>> request({
/// Use [endpoints] from [lib/collection/endpoints.dart]
required String call,
bool isAPIv4 = false,
String language = 'english',
Map<String, dynamic>? queryParameters,
}) async {
final res = await dio.get(
"/",
queryParameters: {
if (isAPIv4) 'api_version': 4,
'__call': call,
...?queryParameters,
},
options: Options(
headers: {
"cookie":
'L=${Uri.encodeComponent(language)}; gdpr_acceptance=true; DL=english',
},
),
);

return jsonDecode(res.data) as Map<String, dynamic>;
}
}
20 changes: 20 additions & 0 deletions lib/src/collection/endpoints.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const endpoints = (
modules: 'content.getBrowseModules',
search: (
all: 'autocomplete.get',
songs: 'search.getResults',
albums: 'search.getAlbumResults',
artists: 'search.getArtistResults',
playlists: 'search.getPlaylistResults',
),
songs: (id: 'song.getDetails',),
albums: (id: 'content.getAlbumDetails',),
playlists: (id: 'playlist.getDetails',),
artists: (
id: 'artist.getArtistPageDetails',
songs: 'artist.getArtistMoreSong',
albums: 'artist.getArtistMoreAlbum',
topSongs: 'search.artistOtherTopSongs',
),
lyrics: 'lyrics.getLyrics',
);
19 changes: 19 additions & 0 deletions lib/src/endpoints/album.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:jiosaavn/src/client.dart';
import 'package:jiosaavn/src/collection/endpoints.dart';
import 'package:jiosaavn/src/models/album.dart';

class AlbumEndpoint extends BaseClient {
AlbumEndpoint([super.options]);

Future<AlbumResponse> detailsById(String id) async {
// api v4 does not contain media_preview_url
final response = await request(call: endpoints.albums.id, queryParameters: {
'albumid': id,
});

final albumResults =
AlbumResponse.fromAlbumRequest(AlbumRequest.fromJson(response));

return albumResults;
}
}
5 changes: 5 additions & 0 deletions lib/src/endpoints/search.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:jiosaavn/src/client.dart';

class SearchEndpoint extends BaseClient {
SearchEndpoint([super.options]);
}
8 changes: 8 additions & 0 deletions lib/src/jiosaavn.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:dio/dio.dart';
import 'package:jiosaavn/src/endpoints/album.dart';

class JioSaavnClient {
final AlbumEndpoint albums;

JioSaavnClient([BaseOptions? options]) : albums = AlbumEndpoint(options);
}
Loading

0 comments on commit f5acede

Please sign in to comment.