Skip to content

Commit

Permalink
core: enhance extracted year tag
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed May 13, 2024
1 parent e4c4583 commit 6b27657
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
16 changes: 15 additions & 1 deletion lib/class/track.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,20 @@ class TrackExtended {
required this.lyrics,
});

static String _padInt(int val) => val.toString().padLeft(2, '0');

static int? enforceYearFormat(String? fromYearString) {
final intVal = fromYearString.getIntValue();
if (intVal != null) return intVal;
if (fromYearString != null) {
try {
final yearDate = DateTime.parse(fromYearString.replaceAll(RegExp(r'[\s]'), '-'));
return int.parse("${yearDate.year}${_padInt(yearDate.month)}${_padInt(yearDate.day)}");
} catch (_) {}
}
return null;
}

factory TrackExtended.fromJson(
Map<String, dynamic> json, {
required ArtistsSplitConfig artistsSplitConfig,
Expand Down Expand Up @@ -372,7 +386,7 @@ extension TrackExtUtils on TrackExtended {
moodList: tag.mood != null ? [tag.mood!] : moodList,
composer: tag.composer ?? composer,
trackNo: tag.trackNumber.getIntValue() ?? trackNo,
year: tag.year.getIntValue() ?? year,
year: TrackExtended.enforceYearFormat(tag.year) ?? year,
dateModified: dateModified ?? this.dateModified,
path: path ?? this.path,
comment: tag.comment ?? comment,
Expand Down
4 changes: 2 additions & 2 deletions lib/controller/indexer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ class Indexer {
);
final bitrate = map['bitrate'] as int?;
final disc = map['disc_number'] as int?;
final year = (map['year'] as String?).getIntValue();
final yearString = map['year'] as String?;
final trext = TrackExtended(
title: e.title,
originalArtist: e.artist ?? UnknownTags.ARTIST,
Expand All @@ -1184,7 +1184,7 @@ class Indexer {
composer: e.composer ?? '',
trackNo: e.track ?? 0,
duration: e.duration == null ? 0 : e.duration! ~/ 1000,
year: year ?? 0,
year: TrackExtended.enforceYearFormat(yearString) ?? 0,
size: e.size,
dateAdded: e.dateAdded ?? 0,
dateModified: e.dateModified ?? 0,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 2.2.6-beta+240513130
version: 2.2.7-beta+240513130

environment:
sdk: ">=3.1.4 <4.0.0"
Expand Down

0 comments on commit 6b27657

Please sign in to comment.