elementary-dev-community team mailing list archive
-
elementary-dev-community team
-
Mailing list archive
-
Message #00809
[Merge] lp:~elementary-dev-community/beat-box/refactor into lp:beat-box
xapantu has proposed merging lp:~elementary-dev-community/beat-box/refactor into lp:beat-box.
Requested reviews:
BeatBox Team (beatbox-team)
For more details, see:
https://code.launchpad.net/~elementary-dev-community/beat-box/refactor/+merge/113865
* Don't use a LibraryManager in GStreamerTagger.
* Tie all the covers related things in one class. The code is easier to understand for a newcomer this way.
--
https://code.launchpad.net/~elementary-dev-community/beat-box/refactor/+merge/113865
Your team elementary Developer Community is subscribed to branch lp:~elementary-dev-community/beat-box/refactor.
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2012-07-04 18:34:08 +0000
+++ CMakeLists.txt 2012-07-08 17:27:20 +0000
@@ -4,6 +4,7 @@
cmake_policy(VERSION 2.6)
project(BeatBox)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake )
+enable_testing()
find_package(PkgConfig)
pkg_check_modules(DEPS
=== modified file 'core/CMakeLists.txt'
--- core/CMakeLists.txt 2012-07-04 00:35:02 +0000
+++ core/CMakeLists.txt 2012-07-08 17:27:20 +0000
@@ -3,6 +3,9 @@
Settings.vala
EqualizerPreset.vala
LibraryWindowInterface.vala
+ Library/Library.vala
+ Library/ComputerLibrary.vala
+ Library/DeviceLibrary.vala
PACKAGES
gtk+-3.0
# libpeas-1.0
@@ -22,3 +25,21 @@
add_library(beatbox-core SHARED ${VALA_C})
target_link_libraries(beatbox-core ${DEPS_LIBRARIES})
install (TARGETS beatbox-core DESTINATION lib)
+
+vala_precompile(VALA_C_TESTS
+ tests/main.vala
+PACKAGES
+ gtk+-3.0
+ gee-1.0
+ granite
+ beatbox-core
+OPTIONS
+ --thread
+ --vapidir=${CMAKE_SOURCE_DIR}/vapi
+ --vapidir=${CMAKE_CURRENT_BINARY_DIR}
+)
+include(Tests)
+add_executable(beatbox-core-test ${VALA_C_TESTS})
+target_link_libraries(beatbox-core-test ${DEPS_LIBRARIES})
+target_link_libraries(beatbox-core-test beatbox-core)
+add_test_executable(beatbox-core-test)
=== added directory 'core/Library'
=== added file 'core/Library/ComputerLibrary.vala'
--- core/Library/ComputerLibrary.vala 1970-01-01 00:00:00 +0000
+++ core/Library/ComputerLibrary.vala 2012-07-08 17:27:20 +0000
@@ -0,0 +1,2 @@
+public class BeatBox.ComputerLibrary : BeatBox.Library {
+}
=== added file 'core/Library/DeviceLibrary.vala'
--- core/Library/DeviceLibrary.vala 1970-01-01 00:00:00 +0000
+++ core/Library/DeviceLibrary.vala 2012-07-08 17:27:20 +0000
@@ -0,0 +1,2 @@
+public class BeatBox.DeviceLibrary : BeatBox.Library {
+}
=== added file 'core/Library/Library.vala'
--- core/Library/Library.vala 1970-01-01 00:00:00 +0000
+++ core/Library/Library.vala 2012-07-08 17:27:20 +0000
@@ -0,0 +1,2 @@
+public class BeatBox.Library : Object {
+}
=== added directory 'core/tests'
=== added file 'core/tests/main.vala'
--- core/tests/main.vala 1970-01-01 00:00:00 +0000
+++ core/tests/main.vala 2012-07-08 17:27:20 +0000
@@ -0,0 +1,8 @@
+public int main(string[] args) {
+ Test.init(ref args);
+ Gtk.init(ref args);
+
+ Test.run();
+
+ return 0;
+}
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2012-07-04 02:32:46 +0000
+++ src/CMakeLists.txt 2012-07-08 17:27:20 +0000
@@ -160,6 +160,7 @@
Dialogs/SetMusicFolderConfirmation.vala
Dialogs/TransferFromDeviceDialog.vala
Dialogs/SyncWarningDialog.vala
+ Core/CoverManager.vala
PACKAGES
glib-2.0
gtk+-3.0
=== added file 'src/Core/CoverManager.vala'
--- src/Core/CoverManager.vala 1970-01-01 00:00:00 +0000
+++ src/Core/CoverManager.vala 2012-07-08 17:27:20 +0000
@@ -0,0 +1,243 @@
+/*-
+ * Copyright (c) 2011-2012 Scott Ringwelski <sgringwe@xxxxxxx>
+ *
+ * Originally Written by Scott Ringwelski for BeatBox Music Player
+ * BeatBox Music Player: http://www.launchpad.net/beat-box
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+public class BeatBox.CoverManager : Object {
+
+ /**
+ * Contains all covers. The id has the form "album - artist".
+ **/
+ Gee.HashMap<string, Gdk.Pixbuf> m_covers;
+ /**
+ * Used to cache cover location, so we don't have to re-browse every directory to check
+ * that wether is a cover or not.
+ **/
+ Gee.HashMap<string, string> art_locations = new Gee.HashMap<string, string>();
+
+ /**
+ * Emitted when a cover is changed for an artist and an album.
+ **/
+ public signal void cover_changed(string artist, string album);
+
+ /**
+ * Emitted when a new cover is saved in the cache. Used to set the cover of every media
+ * which belong to this album.
+ **/
+ public signal void new_cover_in_cache(string artist, string album, Gdk.Pixbuf pix);
+
+ public CoverManager() {
+ m_covers = new Gee.HashMap<string, Gdk.Pixbuf>();
+ }
+
+
+ public Gdk.Pixbuf? get_cover_album_art_from_key(string album_artist, string album) {
+ return m_covers.get(album_artist + " - " + album);
+ }
+ public void set_album_art(Media s, Gdk.Pixbuf? pix, bool emit) {
+ if(pix != null) {
+ string key = get_media_coverart_key (s);
+
+ if(key != null) {
+ m_covers.set(key, Icons.get_pixbuf_shadow(pix));
+
+ // We need to let views know of this update
+ if(emit) {
+ cover_changed(s.album_artist, s.album);
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns a key to get a coverart from the cover_album_art hashmap.
+ **/
+ string get_media_coverart_key (Media s) {
+ /* FIXME: what happens if I have Album/ and Album_ as album names? */
+ return (s.album_artist + " - " + s.album).replace("/", "_");
+ }
+
+ string get_cached_album_art_path (string key) {
+ return GLib.Path.build_filename (settings.get_album_art_cache_dir (), key + ".jpg");
+ }
+
+ Gdk.Pixbuf? get_cached_album_art (string key, out string uri) {
+ Gdk.Pixbuf? rv = null;
+ uri = get_cached_album_art_path (key);
+
+ try {
+ rv = new Gdk.Pixbuf.from_file (uri);
+ debug("neww pixbuf for: %s", uri);
+ } catch (Error err) {
+ //debug (err.message);
+ }
+
+ if (rv == null)
+ uri = "";
+
+ debug ("Requested cached album-art for %s: %s, path: %s", key, rv != null ? " FOUND." : " NOT FOUND.", uri);
+
+ return rv;
+ }
+
+ public void save_album_art_in_cache (Media m, Gdk.Pixbuf? pixbuf) {
+ if (m == null || pixbuf == null)
+ return;
+
+ string key = get_media_coverart_key (m);
+ if(key == "")
+ return;
+
+ string uri = get_cached_album_art_path (key);
+
+ debug ("Saving cached album-art for %s", key);
+
+ bool success = false;
+ try {
+ success = pixbuf.save (uri, "jpeg", null);
+ } catch (Error err) {
+ warning (err.message);
+ }
+
+ /*if(success) {
+ foreach(int i in media_ids()) {
+ if(media_from_id(i).album_artist == m.album_artist && lm.media_from_id(i).album == m.album) {
+ debug("setting album art for %s by %s", lm.media_from_id(i).title, lm.media_from_id(i).artist);
+ media_from_id(i).setAlbumArtPath(uri);
+ }
+ }
+ }*/
+ }
+
+ public Gdk.Pixbuf? get_cover_album_art_from_media(Media? s) {
+ if(s == null)
+ return null;
+
+ return m_covers.get(get_media_coverart_key (s));
+ }
+
+ static bool is_valid_image_type(string type) {
+ var typeDown = type.down();
+
+ return (typeDown.has_suffix(".jpg") || typeDown.has_suffix(".jpeg") ||
+ typeDown.has_suffix(".png"));
+ }
+
+ public void fetch_cover_of_media(Media s) {
+ string key = get_media_coverart_key(s);
+ string path = "";
+ Gdk.Pixbuf? pix = null;
+
+ if(key == null || s.mediatype == MediaType.STATION) { /* There is either a problem with the names,
+ * or it is not a valid media file. */
+ s.setAlbumArtPath (Icons.DEFAULT_ALBUM_ART.backup_filename);
+ }
+ else if(!m_covers.has_key (key)) { /* This album - artist cover hasn't yet been looked for. */
+ Gdk.Pixbuf? coverart_pixbuf = get_cached_album_art (key, out path);
+
+ // try to get image from the cache folder (faster)
+ if (coverart_pixbuf != null) {
+ pix = Icons.get_pixbuf_shadow (coverart_pixbuf);
+ }
+ else {
+ /* TODO: Get image from the tagger object (i.e. song metadata) */
+ //coverart_pixbuf = tagger.get_embedded_art(s);
+
+ if ((path = get_best_album_art_file(s)) != null) {
+ try {
+ coverart_pixbuf = new Gdk.Pixbuf.from_file (path);
+ debug(path);
+ //coverart_pixbuf = _pix.scale_simple (200, 200, Gdk.InterpType.BILINEAR);
+ pix = Icons.get_pixbuf_shadow (coverart_pixbuf);
+
+ // Add image to cache
+ save_album_art_in_cache (s, coverart_pixbuf);
+ }
+ catch(GLib.Error err) {
+ warning (err.message);
+ }
+ }
+ }
+
+ m_covers[key] = pix;
+ }
+ else { /* The cover of this album/artist has already been investigated. */
+ /* We choose the cover path: either it has already been loaded, or it is not loadable (i.e. == null)
+ * and we put a default. */
+ string cover_path = get_cached_album_art_path (key) ?? Icons.DEFAULT_ALBUM_ART.backup_filename;
+ s.setAlbumArtPath(cover_path);
+ }
+ }
+
+ string? get_best_album_art_file(Media m) {
+ GLib.File media_file = GLib.File.new_for_uri(m.uri);
+
+ if(!media_file.query_exists())
+ return null;
+
+ string artPath = "";
+ GLib.FileInfo file_info = null;
+ var album_folder = media_file.get_parent();
+
+ if(!album_folder.query_exists() || album_folder.get_path() == null)
+ return null;
+
+ if( (artPath = art_locations.get(album_folder.get_path())) != null)
+ return artPath;
+
+ artPath = "";
+
+ /* get a list of all images in folder as potential album art choices */
+ var image_list = new Gee.LinkedList<string>();
+
+ try {
+ var enumerator = album_folder.enumerate_children(FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE, 0);
+ while ((file_info = enumerator.next_file ()) != null) {
+ if(file_info.get_file_type() == GLib.FileType.REGULAR && is_valid_image_type(file_info.get_name())) {
+ image_list.add(file_info.get_name());
+ }
+ }
+ }
+ catch (Error e) {
+ warning ("Error while looking for covers: %s", e.message);
+ }
+
+ /* now choose one based on priorities */
+ foreach(string sU in image_list) {
+ var sD = sU.down();
+ if(sD.contains("folder.")) {
+ artPath = album_folder.get_path() + "/" + sU;
+ break;
+ }
+ else if(sD.contains("cover."))
+ artPath = album_folder.get_path() + "/" + sU;
+ else if(!artPath.contains("cover.") && sD.contains("album."))
+ artPath = album_folder.get_path() + "/" + sU;
+ else if(artPath == "")
+ artPath = album_folder.get_path() + "/" + sU;
+ }
+
+ art_locations.set(album_folder.get_path(), artPath);
+ return artPath;
+ }
+
+
+}
=== modified file 'src/Core/FileOperator.vala'
--- src/Core/FileOperator.vala 2012-07-04 00:35:02 +0000
+++ src/Core/FileOperator.vala 2012-07-08 17:27:20 +0000
@@ -50,7 +50,6 @@
LinkedList<string> import_errors;
bool _all_files_queued;
- HashMap<string, string> art_locations = new HashMap<string, string>();
public enum ImportType {
SET,
@@ -68,8 +67,9 @@
cancelSent = false;
new_imports = new LinkedList<Media>();
import_errors = new LinkedList<string>();
- tagger = new GStreamerTagger(lm);
- art_tagger = new GStreamerTagger(lm);
+ tagger = new GStreamerTagger(lm.cover_album_art);
+ assert(lm.cover_album_art != null);
+ art_tagger = new GStreamerTagger(lm.cover_album_art);
tagger.media_imported.connect(media_imported);
tagger.import_error.connect(import_error);
@@ -108,13 +108,6 @@
typeDown.has_suffix(".aac") || typeDown.has_suffix(".alac"));
}
- private static bool is_valid_image_type(string type) {
- var typeDown = type.down();
-
- return (typeDown.has_suffix(".jpg") || typeDown.has_suffix(".jpeg") ||
- typeDown.has_suffix(".png"));
- }
-
public int count_music_files(GLib.File music_folder, ref LinkedList<string> files) {
GLib.FileInfo file_info = null;
@@ -189,109 +182,6 @@
}
}
- public string get_best_album_art_file(Media m) {
- GLib.File media_file = GLib.File.new_for_uri(m.uri);
-
- if(!media_file.query_exists())
- return "";
-
- string artPath = "";
- GLib.FileInfo file_info = null;
- var album_folder = media_file.get_parent();
-
- if(!album_folder.query_exists() || album_folder.get_path() == null)
- return "";
-
- if( (artPath = art_locations.get(album_folder.get_path())) != null)
- return artPath;
-
- artPath = "";
-
- /* get a list of all images in folder as potential album art choices */
- var image_list = new LinkedList<string>();
-
- try {
- var enumerator = album_folder.enumerate_children(FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE, 0);
- while ((file_info = enumerator.next_file ()) != null) {
- if(file_info.get_file_type() == GLib.FileType.REGULAR && is_valid_image_type(file_info.get_name())) {
- image_list.add(file_info.get_name());
- }
- }
- }
- catch (Error e) {
- warning ("Error while looking for covers: %s", e.message);
- }
-
- /* now choose one based on priorities */
- foreach(string sU in image_list) {
- var sD = sU.down();
- if(sD.contains("folder.")) {
- artPath = album_folder.get_path() + "/" + sU;
- break;
- }
- else if(sD.contains("cover."))
- artPath = album_folder.get_path() + "/" + sU;
- else if(!artPath.contains("cover.") && sD.contains("album."))
- artPath = album_folder.get_path() + "/" + sU;
- else if(artPath == "")
- artPath = album_folder.get_path() + "/" + sU;
- }
-
- art_locations.set(album_folder.get_path(), artPath);
- return artPath;
- }
-
- public void save_album_art_in_cache (Media m, Gdk.Pixbuf? pixbuf) {
- if (m == null || pixbuf == null)
- return;
-
- string key = lm.get_media_coverart_key (m);
- if(key == "")
- return;
-
- string uri = get_cached_album_art_path (key);
-
- debug ("Saving cached album-art for %s", key);
-
- bool success = false;
- try {
- success = pixbuf.save (uri, "jpeg", null);
- } catch (Error err) {
- warning (err.message);
- }
-
- if(success) {
- foreach(int i in lm.media_ids()) {
- if(lm.media_from_id(i).album_artist == m.album_artist && lm.media_from_id(i).album == m.album) {
- debug("setting album art for %s by %s", lm.media_from_id(i).title, lm.media_from_id(i).artist);
- lm.media_from_id(i).setAlbumArtPath(uri);
- }
- }
- }
- }
-
- public Gdk.Pixbuf? get_cached_album_art (string key, out string uri) {
- Gdk.Pixbuf? rv = null;
- uri = get_cached_album_art_path (key);
-
- try {
- rv = new Gdk.Pixbuf.from_file (uri);
- } catch (Error err) {
- //debug (err.message);
- }
-
- if (rv == null)
- uri = "";
-
- debug ("Requested cached album-art for %s: %s", key, rv != null ? " FOUND." : " NOT FOUND.");
-
- return rv;
- }
-
- public string get_cached_album_art_path (string key) {
- return GLib.Path.build_filename (settings.get_album_art_cache_dir (), key + ".jpg");
- }
-
public void save_medias(Collection<Media> to_save) {
// Only save permanent files who are songs or podcasts
foreach(Media s in to_save) {
=== modified file 'src/Core/LibraryManager.vala'
--- src/Core/LibraryManager.vala 2012-07-06 21:40:14 +0000
+++ src/Core/LibraryManager.vala 2012-07-08 17:27:20 +0000
@@ -57,7 +57,7 @@
private HashMap<int, int> _current_view; // id, media of currently showing medias
private LinkedList<Media> _queue; // rowid, Media of queue
private LinkedList<Media> _already_played; // Media of already played
- private HashMap<string, Gdk.Pixbuf> cover_album_art; // All album art
+ public CoverManager cover_album_art; // All album art
public LastFM.Core lfm;
@@ -135,8 +135,9 @@
this.dbm = new DataBaseManager(this);
this.dbu = new DataBaseUpdater(this, dbm);
- this.fo = new BeatBox.FileOperator(this, settings);
- this.pm = new PodcastManager(this, lw);
+ cover_album_art = new CoverManager();
+ fo = new BeatBox.FileOperator(this, settings);
+ pm = new PodcastManager(this, lw);
fo.fo_progress.connect(dbProgress);
dbm.db_progress.connect(dbProgress);
@@ -154,7 +155,18 @@
_current_view = new HashMap<int, int>();
_queue = new LinkedList<Media>();
_already_played = new LinkedList<Media>();
- cover_album_art = new HashMap<string, Gdk.Pixbuf>();
+
+ cover_album_art.cover_changed.connect((artist, album) => {
+ Gee.LinkedList<Media> updated_medias = new Gee.LinkedList<Media>();
+
+ foreach(int i in media_ids()) {
+ if(media_from_id(i).album_artist == artist && media_from_id(i).album == album) {
+ updated_medias.add(media_from_id(i));
+ }
+ }
+
+ update_medias(updated_medias, false, false, true);
+ });
lfm = new LastFM.Core(this);
@@ -1637,7 +1649,7 @@
}
if(pix != null) {
- fo.save_album_art_in_cache(_media.get(id), pix);
+ cover_album_art.save_album_art_in_cache(_media.get(id), pix);
set_album_art(_media.get(id), pix, emit);
}
}
@@ -1656,62 +1668,16 @@
return null;
in_fetch_thread = true;
- //GStreamerTagger tagger = new GStreamerTagger(this);
- LinkedList<Media> medias = new LinkedList<Media>();
+
+ LinkedList<Media> medias = new LinkedList<Media>();
- foreach(var m in _media.values)
- medias.add(m);
+ medias.add_all(_media.values);
// first get from file
foreach(var s in medias) {
- string key = get_media_coverart_key(s), path = "";
- Gdk.Pixbuf? pix = null;
-
- if(key != null && !cover_album_art.has_key (key) && s.mediatype != MediaType.STATION) { // songs and podcasts only
- Gdk.Pixbuf? coverart_pixbuf = fo.get_cached_album_art (key, out path);
-
- // try to get image from cache (faster)
- if (coverart_pixbuf != null) {
- pix = Icons.get_pixbuf_shadow (coverart_pixbuf);
- }
- else {
- /* TODO: Get image from the tagger object (i.e. song metadata) */
- //coverart_pixbuf = tagger.get_embedded_art(s);
-
- if ((path = fo.get_best_album_art_file(s)) != null && path != "") {
- try {
- coverart_pixbuf = new Gdk.Pixbuf.from_file (path);
- //coverart_pixbuf = _pix.scale_simple (200, 200, Gdk.InterpType.BILINEAR);
- pix = Icons.get_pixbuf_shadow (coverart_pixbuf);
-
- // Add image to cache
- fo.save_album_art_in_cache (s, coverart_pixbuf);
- }
- catch(GLib.Error err) {
- warning (err.message);
- }
- }
- }
-
- cover_album_art.set(key, pix);
- }
-
- if (key != null && cover_album_art.get (key) != null)
- s.setAlbumArtPath (fo.get_cached_album_art_path (key));
- else
- s.setAlbumArtPath (Icons.DEFAULT_ALBUM_ART.backup_filename);
- }
-
- // now queue failures to fetch from embedded art
- /*previousAlbum = "";
- var to_check_art = new LinkedList<int>();
- foreach(Media s in toShowS) {
- if(_album_art.get(s.artist+s.album) == null)
- to_check_art.add(s.rowid);
- }
- tagger.fetch_art(to_check_art);*/
-
- //_album_art.set_all(to_set);
+ cover_album_art.fetch_cover_of_media(s);
+ }
+
message("Album art cached in memory.\n");
in_fetch_thread = false;
return null;
@@ -1729,7 +1695,8 @@
}
public Gdk.Pixbuf? get_album_art_from_file(int id) {
- Media s = _media.get(id);
+ error("Not Implemented");
+ /*Media s = _media.get(id);
if(s == null)
return null;
@@ -1746,50 +1713,29 @@
}
catch(GLib.Error err) {}
- return pix;
+ return pix;*/
+ return null;
}
+
+
public Gdk.Pixbuf? get_cover_album_art(int id) {
Media s = _media.get(id);
-
- if(s == null)
- return null;
-
- return cover_album_art.get(get_media_coverart_key (s));
- }
-
- // Returns a key to get a coverart from the cover_album_art hashmap
- public string get_media_coverart_key (Media s) {
- return (s.album_artist + " - " + s.album).replace("/", "_");
- }
-
+ return cover_album_art.get_cover_album_art_from_media(s);
+ }
+
+ /**
+ * @deprecated: Use BeatBox.CoverManager directly.
+ **/
public Gdk.Pixbuf? get_cover_album_art_from_key(string album_artist, string album) {
- return cover_album_art.get(album_artist + " - " + album);
- }
+ return cover_album_art.get_cover_album_art_from_key(album_artist, album);
+ }
- public void set_album_art(Media s, Gdk.Pixbuf? pix, bool emit) {
- if(pix == null)
- return;
-
- string key = get_media_coverart_key (s);
-
- if(key != null) {
- cover_album_art.set(key, Icons.get_pixbuf_shadow(pix));
-
- // We need to let views know of this update
- if(emit) {
- Gee.LinkedList<Media> updated_medias = new Gee.LinkedList<Media>();
-
-
- foreach(int i in media_ids()) {
- if(media_from_id(i).album_artist == s.album_artist && media_from_id(i).album == s.album) {
- updated_medias.add(media_from_id(i));
- }
- }
-
- update_medias(updated_medias, false, false, true);
- }
- }
+ /**
+ * @deprecated: Use BeatBox.CoverManager directly.
+ **/
+ public void set_album_art(Media s, Gdk.Pixbuf? pix, bool emit) {
+ cover_album_art.set_album_art(s, pix, emit);
}
public bool start_file_operations(string? message) {
=== modified file 'src/GStreamer/GStreamerTagger.vala'
--- src/GStreamer/GStreamerTagger.vala 2012-06-13 23:54:06 +0000
+++ src/GStreamer/GStreamerTagger.vala 2012-07-08 17:27:20 +0000
@@ -20,17 +20,17 @@
* Boston, MA 02111-1307, USA.
*/
-using Gst;
-using Gee;
-
+/**
+ * This class uses GStreamer functions to discover all media from a folder.
+ **/
public class BeatBox.GStreamerTagger : GLib.Object {
- LibraryManager lm;
+ CoverManager cover_art;
int size;
static int DISCOVER_SET_SIZE = 50;
Gst.Discoverer d;
Gst.Discoverer art_d;
- HashMap<string, int> uri_to_id;
- LinkedList<string> uri_queue;
+ Gee.HashMap<string, int> uri_to_id;
+ Gee.LinkedList<string> uri_queue;
public signal void media_imported(Media m);
public signal void import_error(string file);
@@ -38,10 +38,10 @@
bool cancelled;
- public GStreamerTagger(LibraryManager lm) {
- this.lm = lm;
+ public GStreamerTagger(CoverManager cover_art) {
+ this.cover_art = cover_art;
try {
- d = new Discoverer((ClockTime)(10*Gst.SECOND));
+ d = new Gst.Discoverer((Gst.ClockTime)(10*Gst.SECOND));
}
catch(Error err) {
critical("Metadata reader could not create discoverer object: %s\n", err.message);
@@ -50,22 +50,20 @@
d.finished.connect(finished);
try {
- art_d = new Discoverer((ClockTime)(10*Gst.SECOND));
+ art_d = new Gst.Discoverer((Gst.ClockTime)(10*Gst.SECOND));
}
catch(Error err) {
critical("Metadata reader could not create discoverer object: %s\n", err.message);
}
- //art_d.discovered.connect(import_art);
- //art_d.finished.connect(art_finished);
- uri_to_id = new HashMap<string, int>();
- uri_queue = new LinkedList<string>();
+ uri_to_id = new Gee.HashMap<string, int>();
+ uri_queue = new Gee.LinkedList<string>();
}
void finished() {
if(!cancelled && uri_queue.size > 0) {
try {
- d = new Discoverer((ClockTime)(10*Gst.SECOND));
+ d = new Gst.Discoverer((Gst.ClockTime)(10*Gst.SECOND));
}
catch(Error err) {
critical("Metadata reader could not create discoverer object: %s\n", err.message);
@@ -89,13 +87,12 @@
debug("art finished %d %s\n", uri_queue.size, cancelled ? "true":"False");
if(!cancelled && uri_queue.size > 0) {
try {
- art_d = new Discoverer((ClockTime)(10*Gst.SECOND));
+ art_d = new Gst.Discoverer((Gst.ClockTime)(10*Gst.SECOND));
}
catch(Error err) {
critical("Metadata reader could not create discoverer object: %s\n", err.message);
+ return;
}
- //art_d.discovered.connect(import_art);
- //art_d.finished.connect(art_finished);
art_d.start();
for(int i = 0; i < DISCOVER_SET_SIZE && i < uri_queue.size; ++i) {
@@ -108,8 +105,6 @@
}
public void cancel_operations() {
- //d.stop();
- //queue_finished();
cancelled = true;
}
@@ -129,7 +124,7 @@
}
// This is the concurrent way of importing
- public void discoverer_import_medias(LinkedList<string> files) {
+ public void discoverer_import_medias(Gee.LinkedList<string> files) {
size = 0;
cancelled = false;
uri_queue.clear();
@@ -145,7 +140,7 @@
}
}
- public void fetch_art(LinkedList<Media> files) {
+ public void fetch_art(Gee.LinkedList<Media> files) {
size = 0;
cancelled = false;
uri_queue.clear();
@@ -165,11 +160,7 @@
}
}
- /*public bool discoverer_get_art(Media s) {
- return d.discover_uri_async("file://" + s.file);
- }*/
-
- void import_media(DiscovererInfo info, Error err) {
+ void import_media(Gst.DiscovererInfo info, Error err) {
uri_queue.remove(info.get_uri());
--size;
@@ -184,61 +175,55 @@
GLib.Date? date = GLib.Date();
// get title, artist, album artist, album, genre, comment, lyrics strings
- if(info.get_tags().get_string(TAG_TITLE, out title))
+ if(info.get_tags().get_string(Gst.TAG_TITLE, out title))
s.title = title;
- if(info.get_tags().get_string(TAG_ARTIST, out artist))
+ if(info.get_tags().get_string(Gst.TAG_ARTIST, out artist))
s.artist = artist;
- if(info.get_tags().get_string(TAG_COMPOSER, out composer))
+ if(info.get_tags().get_string(Gst.TAG_COMPOSER, out composer))
s.composer = composer;
- if(info.get_tags().get_string(TAG_ALBUM_ARTIST, out album_artist))
+ if(info.get_tags().get_string(Gst.TAG_ALBUM_ARTIST, out album_artist))
s.album_artist = album_artist;
else
s.album_artist = s.artist;
- if(info.get_tags().get_string(TAG_ALBUM, out album))
+ if(info.get_tags().get_string(Gst.TAG_ALBUM, out album))
s.album = album;
- if(info.get_tags().get_string(TAG_GROUPING, out grouping))
+ if(info.get_tags().get_string(Gst.TAG_GROUPING, out grouping))
s.grouping = grouping;
- if(info.get_tags().get_string(TAG_GENRE, out genre))
+ if(info.get_tags().get_string(Gst.TAG_GENRE, out genre))
s.genre = genre;
- if(info.get_tags().get_string(TAG_COMMENT, out comment))
+ if(info.get_tags().get_string(Gst.TAG_COMMENT, out comment))
s.comment = comment;
- if(info.get_tags().get_string(TAG_LYRICS, out lyrics))
+ if(info.get_tags().get_string(Gst.TAG_LYRICS, out lyrics))
s.lyrics = lyrics;
// get the year
- if(info.get_tags().get_date(TAG_DATE, out date)) {
+ if(info.get_tags().get_date(Gst.TAG_DATE, out date)) {
if(date != null)
s.year = (int)date.get_year();
}
// get track/album number/count, bitrating, rating, bpm
- if(info.get_tags().get_uint(TAG_TRACK_NUMBER, out track))
+ if(info.get_tags().get_uint(Gst.TAG_TRACK_NUMBER, out track))
s.track = (int)track;
- if(info.get_tags().get_uint(TAG_TRACK_COUNT, out track_count))
+ if(info.get_tags().get_uint(Gst.TAG_TRACK_COUNT, out track_count))
s.track_count = track_count;
- if(info.get_tags().get_uint(TAG_ALBUM_VOLUME_NUMBER, out album_number))
+ if(info.get_tags().get_uint(Gst.TAG_ALBUM_VOLUME_NUMBER, out album_number))
s.album_number = album_number;
- if(info.get_tags().get_uint(TAG_ALBUM_VOLUME_COUNT, out album_count))
+ if(info.get_tags().get_uint(Gst.TAG_ALBUM_VOLUME_COUNT, out album_count))
s.album_count = album_count;
- if(info.get_tags().get_uint(TAG_BITRATE, out bitrate))
+ if(info.get_tags().get_uint(Gst.TAG_BITRATE, out bitrate))
s.bitrate = (int)(bitrate/1000);
- if(info.get_tags().get_uint(TAG_USER_RATING, out rating))
+ if(info.get_tags().get_uint(Gst.TAG_USER_RATING, out rating))
s.rating = (int)((rating > 0 && rating <= 5) ? rating : 0);
- if(info.get_tags().get_double(TAG_BEATS_PER_MINUTE, out bpm))
+ if(info.get_tags().get_double(Gst.TAG_BEATS_PER_MINUTE, out bpm))
s.bpm = (int)bpm;
if(info.get_audio_streams().length() > 0)
s.samplerate = info.get_audio_streams().nth_data(0).get_sample_rate();
- // get length
- //if(info.get_tags().get_uint64(TAG_DURATION, out duration)) {
- // s.length = (uint)(duration/10000000);
- //}
- //else {
- s.length = get_length(s.uri);
- //}
+ s.length = get_length(s.uri);
// load embedded art
if(s.artist == null || s.artist == "") s.artist = "Unknown Artist";
@@ -337,9 +322,9 @@
return s;
}
- void import_art(DiscovererInfo info, Media s) {
+ void import_art(Gst.DiscovererInfo info, Media s) {
int id = uri_to_id.get(info.get_uri());
- if(lm.get_cover_album_art_from_key(s.album_artist, s.album) != null) {
+ if(cover_art.get_cover_album_art_from_key(s.album_artist, s.album) != null) {
debug("not loading embedded art since album already has art (%s)\n", s.album);
return;
}
@@ -358,7 +343,7 @@
Gst.Structure caps_struct;
int imgtype;
- value = info.get_tags().get_value_index(TAG_IMAGE, i);
+ value = info.get_tags().get_value_index(Gst.TAG_IMAGE, i);
if(value == null)
break;
@@ -413,11 +398,10 @@
catch(Error err) {}
rv = loader.get_pixbuf();
- //Thread.create<void*>(() => {
- lm.fo.save_album_art_in_cache(s, rv);
- // return null;
- //}, false);
- lm.set_album_art(s, rv, false);
+
+ //lm.fo.save_album_art_in_cache(s, rv);
+
+ cover_art.set_album_art(s, rv, false);
message("Loaded embedded art from %s\n", info.get_uri());
}
catch(Error err) {
@@ -428,98 +412,6 @@
public bool save_media(Media s) {
return false;
-
- /*Gst.Pipeline pipe = new Pipeline("pipe");
- Element src = Element.make_from_uri(URIType.SRC, "file://" + s.file, null);
- Element decoder = ElementFactory.make("decodebin", "decoder");
-
- GLib.Signal.connect(decoder, "new-decoded-pad", (GLib.Callback)newDecodedPad, this);
-
- if(!((Gst.Bin)pipe).add_many(src, decoder)) {
- stdout.printf("Could not add src and decoder to pipeline to save metadata\n");
- return false;
- }
-
- if(!src.link_many(decoder)) {
- stdout.printf("Could not link src to decoder to save metadata\n");
- return false;
- }
-
-
- Gst.Element queue = ElementFactory.make("queue", "queue");
- Gst.Element queue2 = ElementFactory.make("queue", "queue2");
-
- if(queue == null || queue2 == null) {
- stdout.printf("could not add create queues to save metadata\n");
- return false;
- }
-
- if(!((Gst.Bin)pipe).add_many(queue, queue2)) {
- stdout.printf("Could not add queue's to save metadata\n");
- return false;
- }
-
- queue.set("max-size-time", 120 * Gst.SECOND);
-
-
-
-
-
-
-
-
- //Element encoder = new_element_from_uri(URIType.SINK, "file://" + s.file, null);
-
- Gst.TagList tags;
- bool rv = true;
- //long day;
-
- tags = new TagList();
- tags.add(TagMergeMode.REPLACE, TAG_TITLE, s.title,
- TAG_ARTIST, s.artist,
- TAG_COMPOSER, s.composer,
- TAG_ALBUM_ARTIST, s.album_artist,
- TAG_ALBUM, s.album,
- TAG_GROUPING, s.grouping,
- TAG_GENRE, s.genre,
- TAG_COMMENT, s.comment,
- TAG_LYRICS, s.lyrics,
- TAG_TRACK_NUMBER, s.track,
- TAG_TRACK_COUNT, s.track_count,
- TAG_ALBUM_VOLUME_NUMBER, s.album_number,
- TAG_ALBUM_VOLUME_COUNT, s.album_count,
- TAG_USER_RATING, s.rating);
-
- /* fetch date, set new year to s.year, set date */
-
- // now find a tag setter interface and use it
- /*Gst.Iterator iter;
- bool done;
-
- iter = ((Gst.Bin)pipeline).iterate_all_by_interface(typeof(Gst.TagSetter));
- done = false;
- while (!done) {
- Gst.TagSetter tagger = null;
-
- switch (iter.next(out tagger) {
- case GST_ITERATOR_OK:
- tagger.merge_tags (tags, GST_TAG_MERGE_REPLACE_ALL);
- break;
- case GST_ITERATOR_RESYNC:
- iter.resync();
- break;
- case GST_ITERATOR_ERROR:
- stdout.printf("Could not update metadata on media\n");
- rv = false;
- done = true;
- break;
- case GST_ITERATOR_DONE:
- done = true;
- break;
- }
- }
-
- return rv; */
}
public bool save_embeddeart_d(Gdk.Pixbuf pix) {
Follow ups