Skip to content

Commit

Permalink
feat: album artists & composers
Browse files Browse the repository at this point in the history
closes: #21
  • Loading branch information
MSOB7YY committed Apr 7, 2024
1 parent 5203cb9 commit 9b8d27f
Show file tree
Hide file tree
Showing 19 changed files with 490 additions and 203 deletions.
12 changes: 12 additions & 0 deletions lib/class/library_item_map.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'dart:collection';

import 'package:get/get_rx/src/rx_types/rx_types.dart';

import 'package:namida/class/track.dart';

class LibraryItemMap {
LibraryItemMap() : _value = LinkedHashMap<String, List<Track>>(equals: (item1, item2) => item1.toLowerCase() == item2.toLowerCase()).obs;
final Rx<LinkedHashMap<String, List<Track>>> _value;
LinkedHashMap<String, List<Track>> get value => _value.value;
void refresh() => _value.refresh();
}
44 changes: 40 additions & 4 deletions lib/controller/indexer_controller.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ignore_for_file: depend_on_referenced_packages

import 'dart:async';
import 'dart:collection';
import 'dart:io';

import 'package:audio_service/audio_service.dart';
Expand All @@ -12,6 +11,7 @@ import 'package:on_audio_query/on_audio_query.dart';

import 'package:namida/class/faudiomodel.dart';
import 'package:namida/class/folder.dart';
import 'package:namida/class/library_item_map.dart';
import 'package:namida/class/split_config.dart';
import 'package:namida/class/track.dart';
import 'package:namida/class/video.dart';
Expand Down Expand Up @@ -51,9 +51,11 @@ class Indexer {
final RxInt artworksSizeInStorage = 0.obs;
final RxInt videosSizeInStorage = 0.obs;

final Rx<Map<String, List<Track>>> mainMapAlbums = LinkedHashMap<String, List<Track>>(equals: (p0, p1) => p0.toLowerCase() == p1.toLowerCase()).obs;
final Rx<Map<String, List<Track>>> mainMapArtists = LinkedHashMap<String, List<Track>>(equals: (p0, p1) => p0.toLowerCase() == p1.toLowerCase()).obs;
final Rx<Map<String, List<Track>>> mainMapGenres = LinkedHashMap<String, List<Track>>(equals: (p0, p1) => p0.toLowerCase() == p1.toLowerCase()).obs;
final mainMapAlbums = LibraryItemMap();
final mainMapArtists = LibraryItemMap();
final mainMapAlbumArtists = LibraryItemMap();
final mainMapComposer = LibraryItemMap();
final mainMapGenres = LibraryItemMap();
final RxMap<Folder, List<Track>> mainMapFolders = <Folder, List<Track>>{}.obs;

final RxList<Track> tracksInfoList = <Track>[].obs;
Expand Down Expand Up @@ -204,6 +206,8 @@ class Indexer {
void _afterIndexing() {
mainMapAlbums.value.clear();
mainMapArtists.value.clear();
mainMapAlbumArtists.value.clear();
mainMapComposer.value.clear();
mainMapGenres.value.clear();
mainMapFolders.clear();

Expand All @@ -219,6 +223,12 @@ class Indexer {
mainMapArtists.value.addForce(artist, tr);
});

// -- Assigning Album Artist
mainMapAlbumArtists.value.addForce(trExt.albumArtist, tr);

// -- Assigning Composer
mainMapComposer.value.addForce(trExt.composer, tr);

// -- Assigning Genres
trExt.genresList.loop((genre, i) {
mainMapGenres.value.addForce(genre, tr);
Expand Down Expand Up @@ -257,6 +267,14 @@ class Indexer {
sortPls(mainMapArtists.value.values, MediaType.artist);
mainMapArtists.refresh();
break;
case MediaType.albumArtist:
sortPls(mainMapAlbumArtists.value.values, MediaType.albumArtist);
mainMapAlbumArtists.refresh();
break;
case MediaType.composer:
sortPls(mainMapComposer.value.values, MediaType.composer);
mainMapComposer.refresh();
break;
case MediaType.genre:
sortPls(mainMapGenres.value.values, MediaType.genre);
mainMapGenres.refresh();
Expand All @@ -282,6 +300,8 @@ class Indexer {
trExt.artistsList.loop((artist, i) {
mainMapArtists.value[artist]?.remove(tr);
});
mainMapAlbumArtists.value[trExt.albumArtist]?.remove(tr);
mainMapComposer.value[trExt.composer]?.remove(tr);
trExt.genresList.loop((genre, i) {
mainMapGenres.value[genre]?.remove(tr);
});
Expand All @@ -294,6 +314,8 @@ class Indexer {
void _addTheseTracksToAlbumGenreArtistEtc(List<Track> tracks) {
final List<String> addedAlbums = [];
final List<String> addedArtists = [];
final List<String> addedAlbumArtists = [];
final List<String> addedComposers = [];
final List<String> addedGenres = [];
final List<Folder> addedFolders = [];

Expand All @@ -307,6 +329,8 @@ class Indexer {
trExt.artistsList.loop((artist, i) {
mainMapArtists.value.addNoDuplicatesForce(artist, tr);
});
mainMapAlbumArtists.value.addNoDuplicatesForce(trExt.albumArtist, tr);
mainMapComposer.value.addNoDuplicatesForce(trExt.composer, tr);

// -- Assigning Genres
trExt.genresList.loop((genre, i) {
Expand All @@ -319,6 +343,8 @@ class Indexer {
// --- Adding media that was affected
addedAlbums.add(trExt.albumIdentifier);
addedArtists.addAll(trExt.artistsList);
addedAlbumArtists.add(trExt.albumArtist);
addedComposers.add(trExt.composer);
addedGenres.addAll(trExt.artistsList);
addedFolders.add(tr.folder);
});
Expand All @@ -337,6 +363,16 @@ class Indexer {
..loop((e, index) {
mainMapArtists.value[e]?.sortByAlts(artistSorters);
});
addedAlbumArtists
..removeDuplicates()
..loop((e, index) {
mainMapAlbumArtists.value[e]?.sortByAlts(artistSorters);
});
addedComposers
..removeDuplicates()
..loop((e, index) {
mainMapComposer.value[e]?.sortByAlts(artistSorters);
});
addedGenres
..removeDuplicates()
..loop((e, index) {
Expand Down
Loading

0 comments on commit 9b8d27f

Please sign in to comment.