diff --git a/lib/lyrics.dart b/lib/lyrics.dart index 2e797a5..608e1e1 100644 --- a/lib/lyrics.dart +++ b/lib/lyrics.dart @@ -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 { Future 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; + 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('
', '\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); } } diff --git a/lib/main.dart b/lib/main.dart index 3a12bde..de32afc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -44,14 +44,14 @@ class _HomePageState extends State 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(); } diff --git a/lib/search_result.dart b/lib/search_result.dart index 9e2af4b..ff48127 100644 --- a/lib/search_result.dart +++ b/lib/search_result.dart @@ -125,7 +125,7 @@ class _SearchResultState extends State { onLongPress: () => _showOptionsBottomSheet(), child: Ink( height: 75, - color: Colors.black, + color: Colors.white10, child: Row( children: [ Container( @@ -145,7 +145,7 @@ class _SearchResultState extends State { 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 { Text( widget.artist, style: const TextStyle( - color: Colors.white70, + color: Colors.black54, fontSize: 14, ), overflow: TextOverflow.ellipsis, diff --git a/pubspec.lock b/pubspec.lock index 45803da..a2e4052 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,7 +49,14 @@ packages: name: collection url: "https://pub.dartlang.org" 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: dependency: transitive description: @@ -63,7 +70,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" ffi: dependency: transitive description: @@ -121,6 +128,13 @@ packages: description: flutter source: sdk version: "0.0.0" + html: + dependency: transitive + description: + name: html + url: "https://pub.dartlang.org" + source: hosted + version: "0.15.0" http: dependency: "direct main" description: @@ -141,7 +155,7 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3" + version: "0.6.4" lints: dependency: transitive description: @@ -162,7 +176,7 @@ packages: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "0.1.4" meta: dependency: transitive description: @@ -176,7 +190,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" petitparser: dependency: transitive description: @@ -216,7 +230,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -251,7 +265,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" + version: "0.4.9" timezone: dependency: transitive description: @@ -328,7 +342,14 @@ packages: name: vector_math url: "https://pub.dartlang.org" 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: dependency: transitive description: @@ -344,5 +365,5 @@ packages: source: hosted version: "5.3.1" sdks: - dart: ">=2.16.1 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" flutter: ">=2.10.0" diff --git a/pubspec.yaml b/pubspec.yaml index b5d46f9..927e93a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,6 +33,7 @@ dependencies: http: ^0.13.4 flutter_local_notifications: ^9.3.2 url_launcher: ^6.0.20 + web_scraper: ^0.1.4 dev_dependencies: flutter_test: