mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
Full Lyrics support
This commit is contained in:
parent
50b835e122
commit
d647d5ed1f
@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
|
|||||||
import 'package:spotube/helpers/artist-to-string.dart';
|
import 'package:spotube/helpers/artist-to-string.dart';
|
||||||
import 'package:spotube/helpers/getLyrics.dart';
|
import 'package:spotube/helpers/getLyrics.dart';
|
||||||
import 'package:spotube/provider/Playback.dart';
|
import 'package:spotube/provider/Playback.dart';
|
||||||
|
import 'package:spotube/provider/UserPreferences.dart';
|
||||||
|
|
||||||
class Lyrics extends StatefulWidget {
|
class Lyrics extends StatefulWidget {
|
||||||
const Lyrics({Key? key}) : super(key: key);
|
const Lyrics({Key? key}) : super(key: key);
|
||||||
@ -12,19 +13,20 @@ class Lyrics extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _LyricsState extends State<Lyrics> {
|
class _LyricsState extends State<Lyrics> {
|
||||||
Map<String, String>? _lyrics;
|
Map<String, String> _lyrics = {};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Playback playback = context.watch<Playback>();
|
Playback playback = context.watch<Playback>();
|
||||||
|
UserPreferences userPreferences = context.watch<UserPreferences>();
|
||||||
|
|
||||||
if (playback.currentTrack != null &&
|
if (playback.currentTrack != null &&
|
||||||
playback.currentTrack!.id != _lyrics?["id"]) {
|
userPreferences.geniusAccessToken != null &&
|
||||||
|
playback.currentTrack!.id != _lyrics["id"]) {
|
||||||
getLyrics(
|
getLyrics(
|
||||||
playback.currentTrack!.name!,
|
playback.currentTrack!.name!,
|
||||||
artistsToString(playback.currentTrack!.artists ?? []),
|
artistsToString(playback.currentTrack!.artists ?? []),
|
||||||
apiKey:
|
apiKey: userPreferences.geniusAccessToken,
|
||||||
"O6K9JcMNsVD36lRJM6wvl0YsfjrtHFFfAwYHZqxxTNg2xBuMxcaJXrYbpR6kVipN",
|
|
||||||
optimizeQuery: true,
|
optimizeQuery: true,
|
||||||
).then((lyrics) {
|
).then((lyrics) {
|
||||||
if (lyrics != null) {
|
if (lyrics != null) {
|
||||||
@ -35,7 +37,7 @@ class _LyricsState extends State<Lyrics> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_lyrics == null && playback.currentTrack != null) {
|
if (_lyrics["lyrics"] == null && playback.currentTrack != null) {
|
||||||
return const Expanded(
|
return const Expanded(
|
||||||
child: Center(
|
child: Center(
|
||||||
child: CircularProgressIndicator.adaptive(),
|
child: CircularProgressIndicator.adaptive(),
|
||||||
@ -48,13 +50,13 @@ class _LyricsState extends State<Lyrics> {
|
|||||||
children: [
|
children: [
|
||||||
Center(
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
playback.currentTrack!.name!,
|
playback.currentTrack?.name ?? "",
|
||||||
style: Theme.of(context).textTheme.headline3,
|
style: Theme.of(context).textTheme.headline3,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
artistsToString(playback.currentTrack!.artists ?? []),
|
artistsToString(playback.currentTrack?.artists ?? []),
|
||||||
style: Theme.of(context).textTheme.headline5,
|
style: Theme.of(context).textTheme.headline5,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -62,9 +64,9 @@ class _LyricsState extends State<Lyrics> {
|
|||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
_lyrics == null && playback.currentTrack == null
|
_lyrics["lyrics"] == null && playback.currentTrack == null
|
||||||
? "No Track being played currently"
|
? "No Track being played currently"
|
||||||
: _lyrics!["lyrics"]!,
|
: _lyrics["lyrics"]!,
|
||||||
style: Theme.of(context).textTheme.headline6,
|
style: Theme.of(context).textTheme.headline6,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -2,7 +2,9 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:spotube/components/PageWindowTitleBar.dart';
|
import 'package:spotube/components/PageWindowTitleBar.dart';
|
||||||
|
import 'package:spotube/models/LocalStorageKeys.dart';
|
||||||
import 'package:spotube/provider/Auth.dart';
|
import 'package:spotube/provider/Auth.dart';
|
||||||
|
import 'package:spotube/provider/UserPreferences.dart';
|
||||||
|
|
||||||
class Settings extends StatefulWidget {
|
class Settings extends StatefulWidget {
|
||||||
const Settings({Key? key}) : super(key: key);
|
const Settings({Key? key}) : super(key: key);
|
||||||
@ -12,8 +14,30 @@ class Settings extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SettingsState extends State<Settings> {
|
class _SettingsState extends State<Settings> {
|
||||||
|
TextEditingController? _textEditingController;
|
||||||
|
String? _geniusAccessToken;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_textEditingController = TextEditingController();
|
||||||
|
_textEditingController?.addListener(() {
|
||||||
|
setState(() {
|
||||||
|
_geniusAccessToken = _textEditingController?.value.text;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_textEditingController?.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
UserPreferences preferences = context.watch<UserPreferences>();
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
@ -25,6 +49,51 @@ class _SettingsState extends State<Settings> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(10),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
flex: 2,
|
||||||
|
child: Text(
|
||||||
|
"Genius Access Token",
|
||||||
|
style: Theme.of(context).textTheme.subtitle1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
flex: 1,
|
||||||
|
child: TextField(
|
||||||
|
controller: _textEditingController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: preferences.geniusAccessToken,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: _geniusAccessToken != null
|
||||||
|
? () async {
|
||||||
|
SharedPreferences localStorage =
|
||||||
|
await SharedPreferences.getInstance();
|
||||||
|
preferences
|
||||||
|
.setGeniusAccessToken(_geniusAccessToken);
|
||||||
|
localStorage.setString(
|
||||||
|
LocalStorageKeys.geniusAccessToken,
|
||||||
|
_geniusAccessToken!);
|
||||||
|
setState(() {
|
||||||
|
_geniusAccessToken = null;
|
||||||
|
});
|
||||||
|
_textEditingController?.text = "";
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
child: const Text("Save"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
Builder(builder: (context) {
|
Builder(builder: (context) {
|
||||||
var auth = context.read<Auth>();
|
var auth = context.read<Auth>();
|
||||||
return ElevatedButton(
|
return ElevatedButton(
|
||||||
|
@ -10,6 +10,7 @@ import 'package:spotube/provider/Auth.dart';
|
|||||||
import 'package:spotube/provider/Playback.dart';
|
import 'package:spotube/provider/Playback.dart';
|
||||||
import 'package:spotube/provider/PlayerDI.dart';
|
import 'package:spotube/provider/PlayerDI.dart';
|
||||||
import 'package:spotube/provider/SpotifyDI.dart';
|
import 'package:spotube/provider/SpotifyDI.dart';
|
||||||
|
import 'package:spotube/provider/UserPreferences.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MyApp());
|
runApp(MyApp());
|
||||||
@ -69,7 +70,12 @@ class MyApp extends StatelessWidget {
|
|||||||
"--script-opts=ytdl_hook-ytdl_path=yt-dlp",
|
"--script-opts=ytdl_hook-ytdl_path=yt-dlp",
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
)
|
),
|
||||||
|
ChangeNotifierProvider<UserPreferences>(
|
||||||
|
create: (context) {
|
||||||
|
return UserPreferences();
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
|
@ -3,5 +3,6 @@ abstract class LocalStorageKeys {
|
|||||||
static String clientSecret = 'client_secret';
|
static String clientSecret = 'client_secret';
|
||||||
static String accessToken = 'access_token';
|
static String accessToken = 'access_token';
|
||||||
static String refreshToken = 'refresh_token';
|
static String refreshToken = 'refresh_token';
|
||||||
static String expiration = " expiration";
|
static String expiration = "expiration";
|
||||||
|
static String geniusAccessToken = "genius_access_token";
|
||||||
}
|
}
|
||||||
|
25
lib/provider/UserPreferences.dart
Normal file
25
lib/provider/UserPreferences.dart
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:spotube/models/LocalStorageKeys.dart';
|
||||||
|
|
||||||
|
class UserPreferences extends ChangeNotifier {
|
||||||
|
String? _geniusAccessToken;
|
||||||
|
UserPreferences({String? geniusAccessToken}) {
|
||||||
|
if (geniusAccessToken == null) {
|
||||||
|
SharedPreferences.getInstance().then((localStorage) {
|
||||||
|
String? accessToken =
|
||||||
|
localStorage.getString(LocalStorageKeys.geniusAccessToken);
|
||||||
|
_geniusAccessToken ??= accessToken;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
_geniusAccessToken = geniusAccessToken;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get geniusAccessToken => _geniusAccessToken;
|
||||||
|
|
||||||
|
setGeniusAccessToken(String? token) {
|
||||||
|
_geniusAccessToken = token;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user