Re: [Banshee-List] Rythmbox libary import



Thank you. It was a bit of work but worked great.

Based on the 0.13.2 Rhythmbox import code I tried to convert it to fit the trunk code. I appended the current code.
Howeversome questions popped up:

* Because Rhythmbox stores its database in a xml-file I'm using a stream to read the file. Banshees hacking-file says that I shouldn't use System.IO directly (there's also a use of Mono.Unix later). As far as I can see there's no stream object in Banshee.IO. What's the preferred way to handle this?

* The old (0.13.2) versions uses a LibraryTrackInfo to store information in the database. The trunk Amarok importer uses a DatabaseTrackInfo. Does this (through DatabaseTrackInfo track = import_manager.ImportTrack (uri);) load song-information (maybe via id3-tags) or should I define things like title, artist or album based on the Rhythmbox information?

* Through "UpdateUserJob (...)" I notify the UI about updates. Do I need to notify it when the job is done?

regards,
Paul


Gabriel Burt schrieb:
Not in recent versions.  You might be able to install an old version
of Banshee that has the migrator (0.13.2 does, I think) and then
install the new banshee (1.2.1 - wiping our your existing 1.2.1
database at ~/.config/banshee-1/banshee.db if you've already run it)
and it'll upgrade your 0.13.2 db to 1.2.1.

On Mon, Sep 29, 2008 at 5:11 AM, Paul Lange <palango gmx de> wrote:
Hi all,

I want to convert my Rythmbox libary to banshee (most important are my
ratings). Is there still a way to do this?

Thank you!
Paul

_______________________________________________
Banshee-list mailing list
Banshee-list gnome org
http://mail.gnome.org/mailman/listinfo/banshee-list

_______________________________________________
Banshee-list mailing list
Banshee-list gnome org
http://mail.gnome.org/mailman/listinfo/banshee-list


//
// RhythmboxPlayerImportSource.cs
//
// Author:
//   Sebastian Dröge <slomo circular-chaos org>
//   Paul Lange <palango gmx de>
//
// Copyright (C) 2006 Sebastian Dröge, Paul Lange
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System;
using System.Data;
using System.IO;
using System.Xml;

using Mono.Unix;

using Banshee.Base;
using Banshee.Collection.Database;
using Banshee.Library;
using Banshee.ServiceStack;

namespace Banshee.PlayerMigration
{
    public sealed class RhythmboxPlayerImportSource : ThreadPoolImportSource
    {
        private static readonly string rythmbox_db_path = Path.Combine (Path.Combine (Path.Combine (
                                                 Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                                                 ".gnome2"), "rhythmbox"), "rhythmdb.xml");

        protected override void ImportCore ()
        {
            LibraryImportManager import_manager = ServiceManager.Get<LibraryImportManager> ();

            StreamReader stream_reader = new StreamReader (library_path);
            XmlDocument xml_doc = new XmlDocument ();
            xml_doc.Load (stream_reader);
            XmlElement root = xml_doc.DocumentElement;

            if (root == null || !root.HasChildNodes || root.Name != "rhythmdb") {
                LogError (rhythmbox_db_path, String.Format ( "Unable to open Rhythmbox database: {0}", e.Message));
                return;
            }

            int count = root.ChildNodes.Count;
            int processed = 0;

            foreach (XmlElement entry in root.ChildNodes) {
                if (CheckForCanceled ())
                    break;

                processed++;

                if (entry == null || !entry.HasAttribute ("type") || entry.GetAttribute ("type") != "song")
                    continue;
                    
                string title = String.Empty,
                       genre = String.Empty,
                       artist = String.Empty,
                       album = String.Empty;
                uint track_number = 0,
                     rating = 0,
                     play_count = 0;
                int year = 0;
                TimeSpan duration = TimeSpan.Zero;
                DateTime date_added = DateTime.Now,
                         last_played = DateTime.MinValue;
                SafeUri uri = null;

                foreach (XmlElement child in song.ChildNodes) {
                    if (child == null || child.InnerText == null || child.InnerText == String.Empty)
                        continue;

                    try {
                        switch (child.Name) {
                            case "title":
                                title = child.InnerText;
                                break;
                            case "genre":
                                genre = child.InnerText;
                                break;
                            case "artist":
                                artist = child.InnerText;
                                break;
                            case "album":
                                album = child.InnerText;
                                break;
                            case "track-number":
                                track_number = UInt32.Parse (child.InnerText);
                                break;
                            case "duration":
                                duration = TimeSpan.FromSeconds (Int32.Parse (child.InnerText));
                                break;
                            case "location":
                                uri = new SafeUri (child.InnerText);
                                break;
                            case "date":
                                if (child.InnerText != "0")
                                    year = (new DateTime (1, 1, 1).AddDays (Double.Parse (child.InnerText))).Year;
                                break;
                            case "rating":
                                rating = UInt32.Parse (child.InnerText[0].ToString ());
                                break;
                            case "first-seen":
                                date_added = Mono.Unix.Native.NativeConvert.ToDateTime (Int64.Parse (child.InnerText));
                                break;
                            case "play-count":
                                play_count = UInt32.Parse (child.InnerText);
                                break;
                            case "last-played":
                                last_played = Mono.Unix.Native.NativeConvert.ToDateTime (Int64.Parse (child.InnerText));
                                break;
                        }
                    } catch (Exception) {
                        // parsing InnerText failed
                    }

                    if (uri == null)
                        continue;

                    UpdateUserJob (processed, count, artist, title);

                    try {
                        DatabaseTrackInfo track = import_manager.ImportTrack (uri);
                        
                        if (track == null) {
                            throw new Exception (String.Format (Catalog.GetString ("Unable to import track: {0}"), uri.AbsoluteUri));
                        }
                        
                        if (rating > 0 || play_count > 0 || created > 0 || accessed > 0) {
                            track.Rating = rating;
                            track.PlayCount = play_count;
                            if (created > 0)
                                track.DateAdded = Hyena.DateTimeUtil.FromTimeT (created);
                            if (accessed > 0)
                                track.LastPlayed = Hyena.DateTimeUtil.FromTimeT (accessed);

                            track.Save (false);
                        }
                    } catch (Exception e) {
                        LogError (SafeUri.UriToFilename (uri), e);
                    }
                }
            }
            stream_reader.Close();
            import_manager.NotifyAllSources();
        }
        
        public static new bool CanImport {
            get { return Banshee.IO.File.Exists (new SafeUri (rhythmbox_db_path)); }
        }
        
        public override string Name {
            get { return Catalog.GetString ("Rhythmbox Music Player"); }
        }

        public override string [] IconNames {
            get { return new string [] { "system-search" }; }
        }
        
        public override int SortOrder {
            get { return 39; }
        }
    }
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]