mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-08 00:17:29 +00:00
Compare commits
6 Commits
645386ae31
...
53da163a36
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53da163a36 | ||
|
|
e986baa0aa | ||
|
|
42e954428b | ||
|
|
8c1337d1fc | ||
|
|
94e704087f | ||
|
|
8e287ab1e5 |
@ -9,7 +9,7 @@ import 'package:spotube/provider/history/recent.dart';
|
|||||||
|
|
||||||
class HomeRecentlyPlayedSection extends HookConsumerWidget {
|
class HomeRecentlyPlayedSection extends HookConsumerWidget {
|
||||||
const HomeRecentlyPlayedSection({super.key});
|
const HomeRecentlyPlayedSection({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, ref) {
|
Widget build(BuildContext context, ref) {
|
||||||
final history = ref.watch(recentlyPlayedItems);
|
final history = ref.watch(recentlyPlayedItems);
|
||||||
@ -20,17 +20,20 @@ class HomeRecentlyPlayedSection extends HookConsumerWidget {
|
|||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final uniqueItems = <dynamic>{};
|
||||||
|
final filteredItems = [
|
||||||
|
for (final item in historyData)
|
||||||
|
if (item.playlist != null && item.playlist?.id != null && uniqueItems.add(item.playlist!.id!))
|
||||||
|
item.playlist
|
||||||
|
else if (item.album != null && item.album?.id != null && uniqueItems.add(item.album?.id))
|
||||||
|
item.album
|
||||||
|
];
|
||||||
|
|
||||||
return Skeletonizer(
|
return Skeletonizer(
|
||||||
enabled: history.isLoading,
|
enabled: history.isLoading,
|
||||||
child: HorizontalPlaybuttonCardView(
|
child: HorizontalPlaybuttonCardView(
|
||||||
title: Text(context.l10n.recently_played),
|
title: Text(context.l10n.recently_played),
|
||||||
items: [
|
items: filteredItems,
|
||||||
for (final item in historyData)
|
|
||||||
if (item.playlist != null)
|
|
||||||
item.playlist
|
|
||||||
else if (item.album != null)
|
|
||||||
item.album
|
|
||||||
],
|
|
||||||
hasNextPage: false,
|
hasNextPage: false,
|
||||||
isLoadingNextPage: false,
|
isLoadingNextPage: false,
|
||||||
onFetchMore: () {},
|
onFetchMore: () {},
|
||||||
|
|||||||
@ -251,19 +251,18 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
|||||||
.map((YoutubeVideoInfo videoInfo) {
|
.map((YoutubeVideoInfo videoInfo) {
|
||||||
final ytWords = videoInfo.title
|
final ytWords = videoInfo.title
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
|
.replaceAll(RegExp(r'[^\p{L}\p{N}\p{Z}]+', unicode: true), '')
|
||||||
.split(RegExp(r'\s+'))
|
.split(RegExp(r'\p{Z}+', unicode: true))
|
||||||
.where((item) => item.isNotEmpty);
|
.where((item) => item.isNotEmpty);
|
||||||
final spWords = track.name!
|
final spWords = track.name!
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replaceAll(RegExp(r'\((.*)\)'), '')
|
.replaceAll(RegExp(r'[^\p{L}\p{N}\p{Z}]+', unicode: true), '')
|
||||||
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
|
.split(RegExp(r'\p{Z}+', unicode: true))
|
||||||
.split(RegExp(r'\s+'))
|
|
||||||
.where((item) => item.isNotEmpty);
|
.where((item) => item.isNotEmpty);
|
||||||
// Word match to filter out unrelated results
|
// Single word and duration match with 3 second tolerance
|
||||||
final matchCount =
|
if (ytWords.any((word) => spWords.contains(word)) &&
|
||||||
ytWords.where((word) => spWords.contains(word)).length;
|
(videoInfo.duration - track.duration!)
|
||||||
if (matchCount > spWords.length ~/ 2) {
|
.abs().inMilliseconds <= 3000) {
|
||||||
return videoInfo;
|
return videoInfo;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user