fix: better looking result item, and client-side lyrics fetching

This commit is contained in:
2022-08-03 23:06:20 +03:00
parent 386d169304
commit 3bf7750e51
5 changed files with 48 additions and 26 deletions
+12 -12
View File
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert' as convert; import 'dart:convert' as convert;
import 'package:web_scraper/web_scraper.dart';
class LyricsPage extends StatefulWidget { class LyricsPage extends StatefulWidget {
const LyricsPage({ const LyricsPage({
@@ -31,21 +31,21 @@ class _LyricsPageState extends State<LyricsPage> {
Future<void> initPlatformState() async { Future<void> initPlatformState() async {
setState(() => fetching = true); setState(() => fetching = true);
final uri = Uri.https('api.illusionman1212.tech', '/lyrics', { final webScraper = WebScraper('https://genius.com');
'songUrl': widget.url,
});
var response = await http.get(uri);
if (response.statusCode == 200) {
final jsonRes = convert.jsonDecode(response.body) as Map<String, dynamic>;
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(() { setState(() {
lyrics = fullLyrics;
fetching = false; fetching = false;
lyrics = jsonRes['lyrics'];
}); });
} else { // print(thing);
print('error while GETing lyrics');
setState(() => fetching = false);
} }
} }
+2 -2
View File
@@ -44,14 +44,14 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
@override @override
void initState() { void initState() {
WidgetsBinding.instance?.addObserver(this); WidgetsBinding.instance.addObserver(this);
super.initState(); super.initState();
initPlatformState(); initPlatformState();
} }
@override @override
void dispose() { void dispose() {
WidgetsBinding.instance?.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
super.dispose(); super.dispose();
} }
+3 -3
View File
@@ -125,7 +125,7 @@ class _SearchResultState extends State<SearchResult> {
onLongPress: () => _showOptionsBottomSheet(), onLongPress: () => _showOptionsBottomSheet(),
child: Ink( child: Ink(
height: 75, height: 75,
color: Colors.black, color: Colors.white10,
child: Row( child: Row(
children: [ children: [
Container( Container(
@@ -145,7 +145,7 @@ class _SearchResultState extends State<SearchResult> {
Text( Text(
widget.title, widget.title,
style: const TextStyle( style: const TextStyle(
color: Colors.white, color: Colors.black,
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
@@ -154,7 +154,7 @@ class _SearchResultState extends State<SearchResult> {
Text( Text(
widget.artist, widget.artist,
style: const TextStyle( style: const TextStyle(
color: Colors.white70, color: Colors.black54,
fontSize: 14, fontSize: 14,
), ),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
+30 -9
View File
@@ -49,7 +49,14 @@ packages:
name: collection name: collection
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.15.0" version: "1.16.0"
csslib:
dependency: transitive
description:
name: csslib
url: "https://pub.dartlang.org"
source: hosted
version: "0.17.2"
dbus: dbus:
dependency: transitive dependency: transitive
description: description:
@@ -63,7 +70,7 @@ packages:
name: fake_async name: fake_async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.3.0"
ffi: ffi:
dependency: transitive dependency: transitive
description: description:
@@ -121,6 +128,13 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
html:
dependency: transitive
description:
name: html
url: "https://pub.dartlang.org"
source: hosted
version: "0.15.0"
http: http:
dependency: "direct main" dependency: "direct main"
description: description:
@@ -141,7 +155,7 @@ packages:
name: js name: js
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.6.3" version: "0.6.4"
lints: lints:
dependency: transitive dependency: transitive
description: description:
@@ -162,7 +176,7 @@ packages:
name: material_color_utilities name: material_color_utilities
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.3" version: "0.1.4"
meta: meta:
dependency: transitive dependency: transitive
description: description:
@@ -176,7 +190,7 @@ packages:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0" version: "1.8.1"
petitparser: petitparser:
dependency: transitive dependency: transitive
description: description:
@@ -216,7 +230,7 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.1" version: "1.8.2"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
@@ -251,7 +265,7 @@ packages:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.8" version: "0.4.9"
timezone: timezone:
dependency: transitive dependency: transitive
description: description:
@@ -328,7 +342,14 @@ packages:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "2.1.2"
web_scraper:
dependency: "direct main"
description:
name: web_scraper
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
xdg_directories: xdg_directories:
dependency: transitive dependency: transitive
description: description:
@@ -344,5 +365,5 @@ packages:
source: hosted source: hosted
version: "5.3.1" version: "5.3.1"
sdks: sdks:
dart: ">=2.16.1 <3.0.0" dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.10.0" flutter: ">=2.10.0"
+1
View File
@@ -33,6 +33,7 @@ dependencies:
http: ^0.13.4 http: ^0.13.4
flutter_local_notifications: ^9.3.2 flutter_local_notifications: ^9.3.2
url_launcher: ^6.0.20 url_launcher: ^6.0.20
web_scraper: ^0.1.4
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: