2022-03-04 23:16:29 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-03 23:06:20 +03:00
|
|
|
import 'package:web_scraper/web_scraper.dart';
|
2022-03-04 23:16:29 +02:00
|
|
|
|
|
|
|
|
class LyricsPage extends StatefulWidget {
|
|
|
|
|
const LyricsPage({
|
|
|
|
|
Key? key,
|
|
|
|
|
required this.title,
|
|
|
|
|
required this.artist,
|
|
|
|
|
required this.url,
|
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
|
final String artist;
|
|
|
|
|
final String url;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<StatefulWidget> createState() => _LyricsPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _LyricsPageState extends State<LyricsPage> {
|
|
|
|
|
bool fetching = false;
|
|
|
|
|
String? lyrics;
|
2023-07-24 20:57:01 +03:00
|
|
|
bool instrumental = false;
|
2022-03-04 23:16:29 +02:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
initPlatformState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> initPlatformState() async {
|
|
|
|
|
setState(() => fetching = true);
|
|
|
|
|
|
2022-08-03 23:06:20 +03:00
|
|
|
final webScraper = WebScraper('https://genius.com');
|
2022-03-04 23:16:29 +02:00
|
|
|
|
2022-08-03 23:06:20 +03:00
|
|
|
String path = widget.url.split('genius.com/')[1];
|
|
|
|
|
String fullLyrics = '';
|
|
|
|
|
if (await webScraper.loadWebPage('/$path?react=1')) {
|
2023-07-24 20:57:01 +03:00
|
|
|
webScraper
|
|
|
|
|
.loadFromString(webScraper.getPageContent().replaceAll('<br>', '\n'));
|
|
|
|
|
var element = webScraper
|
|
|
|
|
.getElement("div[data-lyrics-container]", ['data-lyrics-container']);
|
2022-08-03 23:06:20 +03:00
|
|
|
for (var section in element) {
|
|
|
|
|
fullLyrics += section['title'] + '\n';
|
|
|
|
|
}
|
2022-03-04 23:16:29 +02:00
|
|
|
setState(() {
|
2022-08-03 23:06:20 +03:00
|
|
|
lyrics = fullLyrics;
|
2023-07-24 20:57:01 +03:00
|
|
|
instrumental = fullLyrics.isEmpty;
|
2022-03-04 23:16:29 +02:00
|
|
|
fetching = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
title: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
widget.title,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
widget.artist,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 13,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
body: Center(
|
|
|
|
|
child: fetching
|
2023-07-17 01:41:00 +03:00
|
|
|
? const Column(
|
2022-03-04 23:16:29 +02:00
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
2023-07-17 01:41:00 +03:00
|
|
|
children: [CircularProgressIndicator(value: null)],
|
2022-03-04 23:16:29 +02:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)
|
2023-07-24 20:57:01 +03:00
|
|
|
: instrumental
|
|
|
|
|
? const Center(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(Icons.music_note, size: 50),
|
|
|
|
|
SizedBox(width: 20, height: 20),
|
|
|
|
|
Text(
|
|
|
|
|
'This Song is an Instrumental',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
fontStyle: FontStyle.italic,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: SizedBox(
|
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.all(30),
|
|
|
|
|
child: SelectableText(
|
|
|
|
|
lyrics ?? '',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
),
|
|
|
|
|
),
|
2022-03-04 23:16:29 +02:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|