mirror of
https://github.com/IllusionMan1212/lyrics-grabbr.git
synced 2026-10-24 02:12:27 +00:00
fix: better looking result item, and client-side lyrics fetching
This commit is contained in:
+12
-12
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert' as convert;
|
||||
import 'package:web_scraper/web_scraper.dart';
|
||||
|
||||
class LyricsPage extends StatefulWidget {
|
||||
const LyricsPage({
|
||||
@@ -31,21 +31,21 @@ class _LyricsPageState extends State<LyricsPage> {
|
||||
Future<void> initPlatformState() async {
|
||||
setState(() => fetching = true);
|
||||
|
||||
final uri = Uri.https('api.illusionman1212.tech', '/lyrics', {
|
||||
'songUrl': widget.url,
|
||||
});
|
||||
|
||||
var response = await http.get(uri);
|
||||
if (response.statusCode == 200) {
|
||||
final jsonRes = convert.jsonDecode(response.body) as Map<String, dynamic>;
|
||||
final webScraper = WebScraper('https://genius.com');
|
||||
|
||||
String path = widget.url.split('genius.com/')[1];
|
||||
String fullLyrics = '';
|
||||
if (await webScraper.loadWebPage('/$path?react=1')) {
|
||||
webScraper.loadFromString(webScraper.getPageContent().replaceAll('<br>', '\n'));
|
||||
var element = webScraper.getElement("div[data-lyrics-container]", ['data-lyrics-container']);
|
||||
for (var section in element) {
|
||||
fullLyrics += section['title'] + '\n';
|
||||
}
|
||||
setState(() {
|
||||
lyrics = fullLyrics;
|
||||
fetching = false;
|
||||
lyrics = jsonRes['lyrics'];
|
||||
});
|
||||
} else {
|
||||
print('error while GETing lyrics');
|
||||
setState(() => fetching = false);
|
||||
// print(thing);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -44,14 +44,14 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
WidgetsBinding.instance?.addObserver(this);
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
super.initState();
|
||||
initPlatformState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance?.removeObserver(this);
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ class _SearchResultState extends State<SearchResult> {
|
||||
onLongPress: () => _showOptionsBottomSheet(),
|
||||
child: Ink(
|
||||
height: 75,
|
||||
color: Colors.black,
|
||||
color: Colors.white10,
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
@@ -145,7 +145,7 @@ class _SearchResultState extends State<SearchResult> {
|
||||
Text(
|
||||
widget.title,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
color: Colors.black,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
@@ -154,7 +154,7 @@ class _SearchResultState extends State<SearchResult> {
|
||||
Text(
|
||||
widget.artist,
|
||||
style: const TextStyle(
|
||||
color: Colors.white70,
|
||||
color: Colors.black54,
|
||||
fontSize: 14,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
|
||||
Reference in New Issue
Block a user