Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use flutter_media_metadata instead of metadata_god #58

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 43 additions & 34 deletions lib/app/local_audio/local_audio_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:typed_data';

import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:metadata_god/metadata_god.dart';
import 'package:flutter_media_metadata/flutter_media_metadata.dart';
import 'package:mime_type/mime_type.dart';
import 'package:musicpod/app/common/audio_filter.dart';
import 'package:musicpod/app/common/constants.dart';
Expand Down Expand Up @@ -229,38 +229,47 @@ class LocalAudioModel extends SafeChangeNotifier {
}

int failures = 0;
int total = 0;
audios = {};
for (var e in onlyFiles) {
total++;
try {
final metadata = await MetadataGod.readMetadata(file: e.path);

final audio = Audio(
path: e.path,
audioType: AudioType.local,
artist: metadata.artist ?? '',
title: metadata.title ?? e.path,
album: metadata.album == null
? ''
: '${metadata.album} ${metadata.discTotal != null && metadata.discTotal! > 1 ? metadata.discNumber : ''}',
albumArtist: metadata.albumArtist,
discNumber: metadata.discNumber,
discTotal: metadata.discTotal,
durationMs: metadata.durationMs,
fileSize: metadata.fileSize,
genre: metadata.genre,
pictureData: metadata.picture?.data,
pictureMimeType: metadata.picture?.mimeType,
trackNumber: metadata.trackNumber,
year: metadata.year,
);

audios?.add(audio);
} catch (e) {
failures++;
}
}
showSnackBar?.call(const SnackBar(content: Text('Importing...')));

audios = Set.from((await Future.wait(
onlyFiles.map(
(e) => Future(() async {
if (e is File) {
try {
final metadata = await MetadataRetriever.fromFile(e);
final audio = Audio(
path: e.path,
audioType: AudioType.local,
artist: metadata.trackArtistNames?.join(', ') ??
metadata.authorName ??
metadata.albumArtistName ??
'',
title: metadata.trackName ?? e.path,
album: metadata.albumName == null
? ''
: '${metadata.albumName} ${metadata.discNumber ?? ''}',
albumArtist: metadata.albumArtistName,
discNumber: metadata.discNumber,
discTotal: metadata.discNumber,
durationMs: metadata.trackDuration,
fileSize: e.lengthSync(),
genre: metadata.genre,
pictureData: metadata.albumArt,
pictureMimeType: metadata.mimeType,
trackNumber: metadata.trackNumber,
year: metadata.year,
);

return audio;
} catch (e) {
failures++;
}
}
}),
),
))
.where((element) => element != null)
.map((e) => e!));
if (failures > 0) {
showSnackBar?.call(
SnackBar(
Expand All @@ -271,7 +280,7 @@ class LocalAudioModel extends SafeChangeNotifier {
color: warningColor,
),
Text(
'Failed to import $failures of $total audio files.',
'Failed to import $failures of ${onlyFiles.length} audio files.',
selectionColor: warningColor,
),
const SizedBox(
Expand Down
6 changes: 3 additions & 3 deletions lib/data/audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Audio {
final String? title;

/// The ID3-Tag duration of the audio file. It can be null if was not set
final double? durationMs;
final int? durationMs;

/// The ID3-Tag artist(s) of the audio file.
final String? artist;
Expand Down Expand Up @@ -95,7 +95,7 @@ class Audio {
String? description,
String? website,
String? title,
double? durationMs,
int? durationMs,
String? artist,
String? album,
String? albumArtist,
Expand Down Expand Up @@ -211,7 +211,7 @@ class Audio {
description: map['description'],
website: map['website'],
title: map['title'],
durationMs: map['durationMs']?.toDouble(),
durationMs: map['durationMs']?.toInt(),
artist: map['artist'],
album: map['album'],
albumArtist: map['albumArtist'],
Expand Down
2 changes: 0 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:desktop_notifications/desktop_notifications.dart';
import 'package:flutter/material.dart';
import 'package:media_kit/media_kit.dart';
import 'package:metadata_god/metadata_god.dart';
import 'package:mpris_service/mpris_service.dart';
import 'package:musicpod/app/common/constants.dart';
import 'package:musicpod/service/library_service.dart';
Expand Down Expand Up @@ -37,7 +36,6 @@ Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
MediaKit.ensureInitialized();
await YaruWindowTitleBar.ensureInitialized();
MetadataGod.initialize();

libraryService.init();
runApp(const MusicPod());
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "generated_plugin_registrant.h"

#include <file_selector_linux/file_selector_plugin.h>
#include <flutter_media_metadata/flutter_media_metadata_plugin.h>
#include <gtk/gtk_plugin.h>
#include <handy_window/handy_window_plugin.h>
#include <media_kit_libs_linux/media_kit_libs_linux_plugin.h>
Expand All @@ -19,6 +20,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
g_autoptr(FlPluginRegistrar) flutter_media_metadata_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterMediaMetadataPlugin");
flutter_media_metadata_plugin_register_with_registrar(flutter_media_metadata_registrar);
g_autoptr(FlPluginRegistrar) gtk_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "GtkPlugin");
gtk_plugin_register_with_registrar(gtk_registrar);
Expand Down
2 changes: 1 addition & 1 deletion linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
flutter_media_metadata
gtk
handy_window
media_kit_libs_linux
Expand All @@ -14,7 +15,6 @@ list(APPEND FLUTTER_PLUGIN_LIST
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
metadata_god
)

set(PLUGIN_BUNDLED_LIBRARIES)
Expand Down
4 changes: 3 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ dependencies:
intl: ^0.18.0
media_kit: ^0.0.11
media_kit_libs_linux: ^1.0.2
metadata_god: ^0.4.1
flutter_media_metadata:
git:
url: https://github.com/aleksrutins/flutter_media_metadata
mime_type: ^1.0.0
mpris_service:
git:
Expand Down
7 changes: 7 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ parts:

deps:
plugin: nil
build-packages:
- libmediainfo-dev
stage-packages:
- libaom3
- libass9
Expand Down Expand Up @@ -111,6 +113,7 @@ parts:
- libpostproc55
- libswscale5
- libsrt1.4-gnutls
- libmediainfo0v5
- ocl-icd-libopencl1
- on amd64:
- libmfx1
Expand Down Expand Up @@ -174,6 +177,10 @@ parts:
- usr/lib/*/libavcodec.so*
- usr/lib/*/libavutil.so*
- usr/lib/*/libswresample.so*
- usr/lib/*/libmediainfo.so*
- usr/lib/*/libmms.so*
- usr/lib/*/libtinyxml2.so*
- usr/lib/*/libzen.so*

# Find files provided by the base and platform snap and ensure they aren't
# duplicated in this snap
Expand Down