Skip to content

Commit

Permalink
made the secret creating part easy & documented
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Mar 26, 2022
1 parent b157e38 commit 1d09eb4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,34 @@ Download the [Mac OS Disk Image (.dmg) file](https://github.com/KRTirtho/spotube
- Install Development dependencies in linux
- `libwebkit2gtk-4.0-dev`, `libkeybinder-3.0-0` & `libkeybinder-3.0-0-dev` (for Debian/Ubuntu)
- `webkit2gtk` & `libkeybinder3` (for Arch/Manjaro)
- Clone the Repo

- Clone the Repo & run
```bash
$ flutter pub get
```
- 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 pub get
$ flutter run -d <window|macos|linux>
$ flutter run -d <window|macos|linux|(android-device-id)>
```

# Things that don't work

- Shows & Podcasts aren't supported as it'd require premium anyway
Expand Down
27 changes: 21 additions & 6 deletions bin/create-secrets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,31 @@ import 'dart:convert';
import 'dart:io';

import 'package:path/path.dart' as path;
import 'package:dotenv/dotenv.dart';

void main(List<String> args) async {
String lyricSecret;
String spotifySecret;

if (args.isEmpty) {
throw ArgumentError(
"Expected 2 arguments but passed ${args.length < 2 || args.length > 2 ? args.length : "none"}");
throw ArgumentError("Expected 2 arguments but passed 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 decodedSpotifySecrete = utf8.decode(base64Decode(args.last));
final val = jsonDecode(decodedSecret);
final decodedLyricSecret = utf8.decode(base64Decode(lyricSecret));
final decodedSpotifySecrete = utf8.decode(base64Decode(spotifySecret));
final val = jsonDecode(decodedLyricSecret);
final val2 = jsonDecode(decodedSpotifySecrete);
if (val is! List || (val2 is! List && (val2 as List).first is! Map)) {
throw Exception(
Expand All @@ -21,6 +36,6 @@ void main(List<String> args) async {
await File(path.join(
Directory.current.path, "lib/models/generated_secrets.dart"))
.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;",
);
}
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
dotenv:
dependency: "direct dev"
description:
name: dotenv
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
fake_async:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ dev_dependencies:
# rules and activating additional ones.
flutter_lints: ^1.0.0
flutter_launcher_icons: ^0.9.2
dotenv: ^3.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down

0 comments on commit 1d09eb4

Please sign in to comment.