Skip to content

Commit

Permalink
Revert "now more song lyrics should be available"
Browse files Browse the repository at this point in the history
This reverts commit d11c3b8.
  • Loading branch information
gokadzev committed Aug 22, 2022
1 parent 86f953c commit d1b66a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
32 changes: 5 additions & 27 deletions lib/API/musify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ List<SongModel> localSongs = [];

final lyrics = ValueNotifier<String>('null');
String _lastLyricsUrl = '';
String _alternateApiUrl = '';

int id = 0;

Expand Down Expand Up @@ -307,33 +306,12 @@ Future<List<Map<String, int>>> getSkipSegments(String id) async {
}
}

Future<void> getAlternateApiUrl() async {
final response = await http.get(
Uri.parse('https://jsapi.apiary.io/apis/lyricsovh'),
headers: {'Accept': 'application/json'},
).timeout(const Duration(seconds: 10));

if (response.statusCode == 200) {
final proxyResponse = await json.decode(response.body);
if (proxyResponse['urls']['proxy'] != null) {
_alternateApiUrl = proxyResponse['urls']['proxy'];
}
}
}

Future getSongLyrics(String artist, String title) async {
String currentApiUrl;
if (_alternateApiUrl != '') {
currentApiUrl =
'$_alternateApiUrl${artist.replaceAll(RegExp(r'[^\w\s]+'), '')}/${title.split(" (")[0].split("|")[0].trim().replaceAll(RegExp(r'[^\w\s]+'), '')}';
} else {
currentApiUrl =
'https://api.lyrics.ovh/v1/${artist.replaceAll(RegExp(r'[^\w\s]+'), '')}/${title.split(" (")[0].split("|")[0].trim().replaceAll(RegExp(r'[^\w\s]+'), '')}';
}

final currentApiUrl =
'https://api.lyrics.ovh/v1/$artist/${title.split(" (")[0].split("|")[0].trim()}';
if (_lastLyricsUrl != currentApiUrl) {
if (await getData('cache', 'lyrics-$artist-$title') != null) {
lyrics.value = await getData('cache', 'lyrics-$artist-$title');
if (await getData('cache', 'lyrics-$currentApiUrl') != null) {
lyrics.value = await getData('cache', 'lyrics-$currentApiUrl');
} else {
lyrics.value = 'null';
_lastLyricsUrl = currentApiUrl;
Expand All @@ -348,7 +326,7 @@ Future getSongLyrics(String artist, String title) async {
lyrics.value = lyricsResponse['lyrics'].toString();
addOrUpdateData(
'cache',
'lyrics-$artist-$title',
'lyrics-$_lastLyricsUrl',
lyricsResponse['lyrics'].toString(),
);
} else {
Expand Down
1 change: 0 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ void main() async {
await Hive.openBox('user');
await Hive.openBox('cache');
await initialisation();
await getAlternateApiUrl();
runApp(const MyApp());
}

Expand Down

0 comments on commit d1b66a1

Please sign in to comment.