From 5ebed57549926925620295fefede5ae2cfb7cf7f Mon Sep 17 00:00:00 2001 From: Aditya Kumar Das Date: Fri, 23 Feb 2024 00:11:28 +0530 Subject: [PATCH] Cleanup title for better AZLyrics search result --- lib/utils/service_utils.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/utils/service_utils.dart b/lib/utils/service_utils.dart index 84f38f6a..1e69c0a8 100644 --- a/lib/utils/service_utils.dart +++ b/lib/utils/service_utils.dart @@ -123,10 +123,10 @@ abstract class ServiceUtils { {required String title, required List artists}) async { const Map headers = { HttpHeaders.userAgentHeader: - "Mozilla/5.0 (Linux i656 ; en-US) AppleWebKit/601.49 (KHTML, like Gecko) Chrome/51.0.1145.334 Safari/600", + "Mozilla/5.0 (Linux i656 ; en-US) AppleWebKit/601.49 (KHTML, like Gecko) Chrome/51.0.1145.334 Safari/600" }; - //Will throw error 400 when you request the script with the host header + //Will throw error 400 when you request the script without the host header const Map headersForScript = { HttpHeaders.userAgentHeader: "Mozilla/5.0 (Linux i656 ; en-US) AppleWebKit/601.49 (KHTML, like Gecko) Chrome/51.0.1145.334 Safari/600", @@ -137,8 +137,8 @@ abstract class ServiceUtils { Uri.parse("https://www.azlyrics.com/geo.js"), headers: headersForScript); - RegExp scriptValueRegex = RegExp(r'ep\.setAttribute\("value", "(.*)"\);'); - RegExp scriptNameRegex = RegExp(r'ep\.setAttribute\("name", "(.*)"\);'); + RegExp scriptValueRegex = RegExp(r'\.setAttribute\("value", "(.*)"\);'); + RegExp scriptNameRegex = RegExp(r'\.setAttribute\("name", "(.*)"\);'); final String? v = scriptValueRegex.firstMatch(azLyricsGeoScript.body)?.group(1); final String? x = @@ -147,7 +147,7 @@ abstract class ServiceUtils { debugPrint("getAZLyrics -> Additional URL params: $x=$v"); final suggestionUrl = Uri.parse( - "https://search.azlyrics.com/suggest.php?q=$title ${artists[0]}&${x.toString()}=${v.toString()}"); + "https://search.azlyrics.com/suggest.php?q=${title.replaceAll(RegExp(r"(\(.*\))"), "")} ${artists[0]}&${x.toString()}=${v.toString()}"); final searchResponse = await http.get(suggestionUrl, headers: headers); if (searchResponse.statusCode != 200) {