mirror of
https://github.com/IllusionMan1212/lyrics-grabbr.git
synced 2026-10-24 02:12:27 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
197be6330b | ||
|
|
100157a8d4 | ||
|
|
3bf7750e51 |
+13
-14
@@ -56,21 +56,19 @@ class NotificationListener : NotificationListenerService() {
|
||||
}
|
||||
|
||||
override fun onNotificationPosted(sbn: StatusBarNotification) {
|
||||
if (sbn.packageName == SPOTIFY_PACKAGE) {
|
||||
sendNotificationBroadcast(sbn, applicationContext)
|
||||
}
|
||||
sendNotificationBroadcast(sbn, applicationContext)
|
||||
}
|
||||
|
||||
private fun getStopServiceNotificationAction(): PendingIntent {
|
||||
val intent = Intent(MainActivity.ACTION_NOTIFICATION_LISTENER_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
val pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
|
||||
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)
|
||||
return pendingIntent
|
||||
}
|
||||
|
||||
private fun startForegroundService() {
|
||||
val notification: Notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||
.setContentTitle("Service Running")
|
||||
.setContentText("Play some songs on spotify to get lyrics")
|
||||
.setContentText("Play some songs on a supported player to get lyrics")
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setShowWhen(false)
|
||||
.addAction(R.drawable.ic_notification, "Stop Service", getStopServiceNotificationAction())
|
||||
@@ -103,19 +101,21 @@ class NotificationListener : NotificationListenerService() {
|
||||
private fun getCurrentNotifications(context: Context) {
|
||||
val sbns = activeNotifications
|
||||
for (sbn in sbns) {
|
||||
if (sbn.packageName == SPOTIFY_PACKAGE) {
|
||||
sendNotificationBroadcast(sbn, context)
|
||||
}
|
||||
sendNotificationBroadcast(sbn, context)
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendNotificationBroadcast(sbn: StatusBarNotification, context: Context) {
|
||||
// get the media session stuff
|
||||
val mediaSessionToken = sbn.notification.extras.getParcelable<MediaSession.Token>(Notification.EXTRA_MEDIA_SESSION)
|
||||
val mediaCtrl = mediaSessionToken?.let { MediaController(context, it) }
|
||||
val duration = mediaCtrl?.metadata?.getLong(MediaMetadata.METADATA_KEY_DURATION)?.div(1000)
|
||||
val playbackState = mediaCtrl?.playbackState?.state
|
||||
val albumArt = mediaCtrl?.metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART)
|
||||
if (mediaSessionToken == null) {
|
||||
return
|
||||
}
|
||||
|
||||
val mediaCtrl = mediaSessionToken.let { MediaController(context, it) }
|
||||
val duration = mediaCtrl.metadata?.getLong(MediaMetadata.METADATA_KEY_DURATION)?.div(1000)
|
||||
val playbackState = mediaCtrl.playbackState?.state
|
||||
val albumArt = mediaCtrl.metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART)
|
||||
|
||||
// Retrieve package name to set as title.
|
||||
val packageName = sbn.packageName
|
||||
@@ -134,7 +134,7 @@ class NotificationListener : NotificationListenerService() {
|
||||
if (playbackState == PlaybackState.STATE_PAUSED) {
|
||||
val notification: Notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||
.setContentTitle("Service Running")
|
||||
.setContentText("Play some songs on spotify to get lyrics")
|
||||
.setContentText("Play some songs on a supported player to get lyrics")
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setShowWhen(false)
|
||||
.addAction(R.drawable.ic_notification, "Stop Service", getStopServiceNotificationAction())
|
||||
@@ -173,7 +173,6 @@ class NotificationListener : NotificationListenerService() {
|
||||
const val NOTIFICATION_PACKAGE_DURATION = "package_duration"
|
||||
const val NOTIFICATION_ID = 12251999
|
||||
const val NOTIFICATION_CHANNEL_ID = "Lyrics"
|
||||
const val SPOTIFY_PACKAGE = "com.spotify.music"
|
||||
const val START_FOREGROUND_SERVICE_ACTION = "START_SERVICE"
|
||||
}
|
||||
}
|
||||
|
||||
+11
-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,20 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+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();
|
||||
}
|
||||
|
||||
|
||||
+15
-3
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
|
||||
import 'lyrics.dart';
|
||||
|
||||
@@ -125,7 +126,7 @@ class _SearchResultState extends State<SearchResult> {
|
||||
onLongPress: () => _showOptionsBottomSheet(),
|
||||
child: Ink(
|
||||
height: 75,
|
||||
color: Colors.black,
|
||||
color: Colors.white10,
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
@@ -135,6 +136,17 @@ class _SearchResultState extends State<SearchResult> {
|
||||
width: 75,
|
||||
height: 75,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
Fluttertoast.showToast(
|
||||
msg: 'Failed to load album art for: ${widget.title}',
|
||||
toastLength: Toast.LENGTH_LONG);
|
||||
return const Center(
|
||||
child: SizedBox(
|
||||
width: 75,
|
||||
height: 75,
|
||||
child: Icon(Icons.broken_image, size: 40)),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
@@ -145,7 +157,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 +166,7 @@ class _SearchResultState extends State<SearchResult> {
|
||||
Text(
|
||||
widget.artist,
|
||||
style: const TextStyle(
|
||||
color: Colors.white70,
|
||||
color: Colors.black54,
|
||||
fontSize: 14,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
|
||||
+37
-9
@@ -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,20 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
fluttertoast:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: fluttertoast
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "8.0.9"
|
||||
html:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: html
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.15.0"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -141,7 +162,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 +183,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 +197,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 +237,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 +272,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 +349,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 +372,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"
|
||||
|
||||
+3
-1
@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
|
||||
# Read more about iOS versioning at
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
version: 0.1.1+1
|
||||
version: 0.2.1+1
|
||||
|
||||
environment:
|
||||
sdk: ">=2.16.1 <3.0.0"
|
||||
@@ -33,6 +33,8 @@ dependencies:
|
||||
http: ^0.13.4
|
||||
flutter_local_notifications: ^9.3.2
|
||||
url_launcher: ^6.0.20
|
||||
web_scraper: ^0.1.4
|
||||
fluttertoast: ^8.0.9
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user