made the secret creating part easy & documented

This commit is contained in:
Kingkor Roy Tirtho 2022-03-26 10:02:29 +06:00
parent b157e389a9
commit 1d09eb451e
4 changed files with 55 additions and 11 deletions

View File

@ -158,13 +158,34 @@ Download the [Mac OS Disk Image (.dmg) file](https://github.com/KRTirtho/spotube
- Install Development dependencies in linux - Install Development dependencies in linux
- `libwebkit2gtk-4.0-dev`, `libkeybinder-3.0-0` & `libkeybinder-3.0-0-dev` (for Debian/Ubuntu) - `libwebkit2gtk-4.0-dev`, `libkeybinder-3.0-0` & `libkeybinder-3.0-0-dev` (for Debian/Ubuntu)
- `webkit2gtk` & `libkeybinder3` (for Arch/Manjaro) - `webkit2gtk` & `libkeybinder3` (for Arch/Manjaro)
- Clone the Repo - Clone the Repo & run
```bash ```bash
$ flutter pub get $ flutter pub get
$ flutter run -d <window|macos|linux>
``` ```
- Create a `.env` file containing 2 secrets `LYRICS_SECRET` & `SPOTIFY_SECRET`. These secrets should be a **base64 encoded JSON string**
- Structure of `LYRICS_SECRET` json string:
```jsonc
[
"<secret genius access tokens>",
// and so on...
]
```
- Structure of `SPOTIFY_SECRET` json string:
```jsonc
[
{"clientId": "<Spotify Client Id>", "clientSecret": "<Spotify Client Secret>"},
// and so on ....
]
```
> You can base64 encode the JSON [here](https://www.base64encode.org/)
- Run following in the terminal to generate secrets for your fork
```bash
$ dart bin/create-secrets.dart --loadEnv
```
Finally, to start the app run:
```bash
$ flutter run -d <window|macos|linux|(android-device-id)>
```
# Things that don't work # Things that don't work
- Shows & Podcasts aren't supported as it'd require premium anyway - Shows & Podcasts aren't supported as it'd require premium anyway

View File

@ -2,16 +2,31 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:dotenv/dotenv.dart';
void main(List<String> args) async { void main(List<String> args) async {
String lyricSecret;
String spotifySecret;
if (args.isEmpty) { if (args.isEmpty) {
throw ArgumentError( throw ArgumentError("Expected 2 arguments but passed none");
"Expected 2 arguments but passed ${args.length < 2 || args.length > 2 ? args.length : "none"}"); }
if (args.contains("--loadEnv")) {
load();
if (env["SPOTIFY_SECRET"] == null || env["LYRICS_SECRET"] == null) {
throw Exception(
"'LYRICS_SECRET' or 'SPOTIFY_SECRET' environmental variable aren't set correctly ");
}
lyricSecret = env["LYRICS_SECRET"]!;
spotifySecret = env["SPOTIFY_SECRET"]!;
} else {
lyricSecret = args.first;
spotifySecret = args.last;
} }
final decodedSecret = utf8.decode(base64Decode(args.first)); final decodedLyricSecret = utf8.decode(base64Decode(lyricSecret));
final decodedSpotifySecrete = utf8.decode(base64Decode(args.last)); final decodedSpotifySecrete = utf8.decode(base64Decode(spotifySecret));
final val = jsonDecode(decodedSecret); final val = jsonDecode(decodedLyricSecret);
final val2 = jsonDecode(decodedSpotifySecrete); final val2 = jsonDecode(decodedSpotifySecrete);
if (val is! List || (val2 is! List && (val2 as List).first is! Map)) { if (val is! List || (val2 is! List && (val2 as List).first is! Map)) {
throw Exception( throw Exception(
@ -21,6 +36,6 @@ void main(List<String> args) async {
await File(path.join( await File(path.join(
Directory.current.path, "lib/models/generated_secrets.dart")) Directory.current.path, "lib/models/generated_secrets.dart"))
.writeAsString( .writeAsString(
"final List<String> lyricsSecrets = $decodedSecret;\nfinal List<Map<String, dynamic>> spotifySecrets = $decodedSpotifySecrete;", "final List<String> lyricsSecrets = $decodedLyricSecret;\nfinal List<Map<String, dynamic>> spotifySecrets = $decodedSpotifySecrete;",
); );
} }

View File

@ -169,6 +169,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.4" version: "1.0.4"
dotenv:
dependency: "direct dev"
description:
name: dotenv
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:

View File

@ -70,6 +70,7 @@ dev_dependencies:
# rules and activating additional ones. # rules and activating additional ones.
flutter_lints: ^1.0.0 flutter_lints: ^1.0.0
flutter_launcher_icons: ^0.9.2 flutter_launcher_icons: ^0.9.2
dotenv: ^3.0.0
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec