Example #1
0
        private void PerformSyncThreadCycle()
        {
            Hyena.Log.Debug("Starting AppleDevice sync thread cycle");

            var progressUpdater = new UserJob(Catalog.GetString("Syncing iPod"),
                                              Catalog.GetString("Preparing to synchronize..."), GetIconNames());

            progressUpdater.Register();
            MediaDatabase.StartSync();

            SyncTracksToAdd(progressUpdater);

            SyncTracksToUpdate(progressUpdater);

            SyncTracksToRemove(progressUpdater);

            SyncTracksToPlaylists();

            SyncDatabase(progressUpdater);

            MediaDatabase.StopSync();
            progressUpdater.Finish();

            Hyena.Log.Debug("Ending AppleDevice sync thread cycle");
        }
Example #2
0
        private void OnIpodDatabaseSaveStarted(object o, EventArgs args)
        {
            DisposeSyncUserJob();

            sync_user_job = new UserJob(Catalog.GetString("Syncing iPod"),
                                        Catalog.GetString("Preparing to synchronize..."), GetIconNames());
            sync_user_job.Register();
        }
        public DatabaseRebuilder(IpodSource source)
        {
            this.source = source;

            user_job = new UserJob(Catalog.GetString("Rebuilding Database"));
            user_job.PriorityHints = PriorityHints.SpeedSensitive | PriorityHints.DataLossIfStopped;
            user_job.SetResources(Resource.Disk, Resource.Cpu);
            user_job.Title     = Catalog.GetString("Rebuilding Database");
            user_job.Status    = Catalog.GetString("Scanning iPod...");
            user_job.IconNames = source._GetIconNames();
            user_job.CanCancel = true;
            user_job.Register();

            ThreadPool.QueueUserWorkItem(RebuildDatabase);
        }
Example #4
0
        private void OnReadyToScrobble(object source, ScrobblingBatchEventArgs args)
        {
            var scrobble_job = new UserJob(Catalog.GetString("Scrobbling from device"),
                                           Catalog.GetString("Scrobbling from device..."));

            scrobble_job.PriorityHints = PriorityHints.DataLossIfStopped;
            scrobble_job.Register();

            try {
                if (!connection.Started)
                {
                    connection.Start();
                }

                int    added_track_count = 0, processed_track_count = 0;
                string message    = Catalog.GetString("Processing track {0} of {1} ...");
                var    batchCount = args.ScrobblingBatch.Count;

                foreach (var track_entry in args.ScrobblingBatch)
                {
                    TrackInfo track = track_entry.Key;

                    if (IsValidForSubmission(track))
                    {
                        IList <DateTime> playtimes = track_entry.Value;

                        foreach (DateTime playtime in playtimes)
                        {
                            queue.Add(track, playtime);
                            added_track_count++;
                        }
                        Log.DebugFormat("Added to Last.fm queue: {0} - Number of plays: {1}", track, playtimes.Count);
                    }
                    else
                    {
                        Log.DebugFormat("Track {0} failed validation check for Last.fm submission, skipping...",
                                        track);
                    }

                    scrobble_job.Status   = String.Format(message, ++processed_track_count, batchCount);
                    scrobble_job.Progress = processed_track_count / (double)batchCount;
                }

                Log.InformationFormat("Number of played tracks from device added to Last.fm queue: {0}", added_track_count);
            } finally {
                scrobble_job.Finish();
            }
        }
Example #5
0
        private void CreateUserJob()
        {
            lock (user_job_mutex) {
                if (user_job != null)
                {
                    return;
                }

                user_job = new UserJob(UserJobTitle, UserJobTitle, Catalog.GetString("Importing Songs"));
                user_job.SetResources(Resource.Cpu, Resource.Disk, Resource.Database);
                user_job.PriorityHints = PriorityHints.SpeedSensitive | PriorityHints.DataLossIfStopped;
                user_job.IconNames     = IconNames;
                user_job.CancelMessage = CancelMessage;
                user_job.CanCancel     = CanCancel;
                user_job.Register();
            }
        }
Example #6
0
        protected void CreateUserJob()
        {
            lock (sync) {
                if (user_job != null)
                {
                    return;
                }

                user_job = new UserJob(Title, AddinManager.CurrentLocalizer.GetString("Initializing"));
                user_job.SetResources(Resource.Cpu, Resource.Disk);
                user_job.PriorityHints    = PriorityHints.SpeedSensitive | PriorityHints.DataLossIfStopped;
                user_job.IconNames        = new string [] { Gtk.Stock.Network };
                user_job.CancelMessage    = CancelMessage;
                user_job.CanCancel        = true;
                user_job.CancelRequested += OnCancelRequested;
                user_job.Register();
            }
        }
Example #7
0
        public void Start()
        {
            ResetState();

            foreach (AudioCdTrackInfo track in source.Model)
            {
                if (track.RipEnabled)
                {
                    total_duration += track.Duration;
                    queue.Enqueue(track);
                }
            }

            if (queue.Count == 0)
            {
                return;
            }

            source.LockAllTracks();

            user_job = new UserJob(Catalog.GetString("Importing Audio CD"),
                                   Catalog.GetString("Initializing Drive"), "media-import-audio-cd");
            user_job.CancelMessage = String.Format(Catalog.GetString(
                                                       "<i>{0}</i> is still being imported into the music library. Would you like to stop it?"
                                                       ), GLib.Markup.EscapeText(source.Model.Title));
            user_job.SetResources(Resource.Cpu);
            user_job.PriorityHints    = PriorityHints.SpeedSensitive | PriorityHints.DataLossIfStopped;
            user_job.CanCancel        = true;
            user_job.CancelRequested += OnCancelRequested;
            user_job.Finished        += OnFinished;
            user_job.Register();

            if (source != null && source.Model != null)
            {
                if (!source.Model.LockDoor())
                {
                    Hyena.Log.Warning("Could not lock CD-ROM door", false);
                }
            }

            ripper.Begin(source.Model.Volume.DeviceNode, AudioCdService.ErrorCorrection.Get());

            RipNextTrack();
        }
Example #8
0
        private void OnSubmissionStart(object source, SubmissionStartEventArgs args)
        {
            // We only want to display something if more than one track is being submitted
            if (args.TotalCount <= 1)
            {
                return;
            }

            if (scrobble_job == null)
            {
                scrobble_job = new UserJob(Catalog.GetString("Scrobbling to Last.FM"),
                                           Catalog.GetString("Scrobbling to Last.FM..."));

                scrobble_job.PriorityHints    = PriorityHints.None;
                scrobble_job.CanCancel        = true;
                scrobble_job.CancelRequested += OnScrobbleJobCancelRequest;
                scrobble_job.Register();

                job_tracks_count = 0;
                job_tracks_total = args.TotalCount;
            }
            UpdateJob();
        }
        private void CreateUserJob()
        {
            lock (user_job_mutex) {
                if (user_job != null || KeepUserJobHidden)
                {
                    return;
                }

                timer_id = Log.DebugTimerStart();

                user_job = new UserJob(Title, Catalog.GetString("Scanning for media"));
                user_job.SetResources(Resource.Cpu, Resource.Disk, Resource.Database);
                user_job.PriorityHints    = PriorityHints.SpeedSensitive | PriorityHints.DataLossIfStopped;
                user_job.IconNames        = new string [] { "system-search", "gtk-find" };
                user_job.CancelMessage    = CancelMessage;
                user_job.CanCancel        = true;
                user_job.CancelRequested += OnCancelRequested;

                if (!KeepUserJobHidden)
                {
                    user_job.Register();
                }
            }
        }
Example #10
0
        private void PerformSyncThreadCycle()
        {
            Hyena.Log.Debug("Starting AppleDevice sync thread cycle");

            string message;
            int    total, i = 0;
            var    progressUpdater = new UserJob(Catalog.GetString("Syncing iPod"),
                                                 Catalog.GetString("Preparing to synchronize..."), GetIconNames());

            progressUpdater.Register();
            MediaDatabase.StartSync();
            message = Catalog.GetString("Adding track {0} of {1}");
            total   = tracks_to_add.Count;
            while (tracks_to_add.Count > 0)
            {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    total = tracks_to_add.Count + i;
                    track = tracks_to_add.Dequeue();
                }

                try {
                    UpdateProgress(progressUpdater, message, ++i, total);
                    track.CommitToIpod(MediaDatabase);
                    track.Save(false);
                    tracks_map[track.TrackId] = track;
                } catch (Exception e) {
                    Log.Exception("Cannot save track to the Apple device", e);
                }
            }
            if (total > 0)
            {
                OnTracksAdded();
                OnUserNotifyUpdated();
            }

            while (tracks_to_update.Count > 0)
            {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    track = tracks_to_update.Dequeue();
                }

                try {
                    track.CommitToIpod(MediaDatabase);
                } catch (Exception e) {
                    Log.Exception("Cannot save track to iPod", e);
                }
            }

            message = Catalog.GetString("Removing track {0} of {1}");
            total   = tracks_to_remove.Count;
            while (tracks_to_remove.Count > 0)
            {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    track = tracks_to_remove.Dequeue();
                }

                if (tracks_map.ContainsKey(track.TrackId))
                {
                    tracks_map.Remove(track.TrackId);
                }

                try {
                    if (track.IpodTrack != null)
                    {
                        UpdateProgress(progressUpdater, message, total - tracks_to_remove.Count, total);

                        DeleteTrack(track.IpodTrack, true);
                    }
                    else
                    {
                        Log.Error("The ipod track was null");
                    }
                } catch (Exception e) {
                    Log.Exception("Cannot remove track from iPod", e);
                }
            }

            if (SupportsPlaylists)
            {
                // Remove playlists on the device
                var device_playlists = new List <GPod.Playlist> (MediaDatabase.Playlists);
                foreach (var playlist in device_playlists)
                {
                    if (!playlist.IsMaster && !playlist.IsPodcast)
                    {
                        MediaDatabase.Playlists.Remove(playlist);
                    }
                }

                // Add playlists from Banshee to the device
                foreach (Source child in Children)
                {
                    PlaylistSource from = child as PlaylistSource;
                    if (from != null && from.Count > 0)
                    {
                        var playlist = new GPod.Playlist(from.Name);
                        MediaDatabase.Playlists.Add(playlist);
                        foreach (int track_id in ServiceManager.DbConnection.QueryEnumerable <int> (String.Format(
                                                                                                        "SELECT CoreTracks.TrackID FROM {0} WHERE {1}",
                                                                                                        from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition)))
                        {
                            if (tracks_map.ContainsKey(track_id))
                            {
                                playlist.Tracks.Add(tracks_map[track_id].IpodTrack);
                            }
                        }
                    }
                }
            }

            try {
                message = Catalog.GetString("Writing media database");
                UpdateProgress(progressUpdater, message, 1, 1);

                lock (write_mutex) {
                    MediaDatabase.Write();
                }

                Log.Information("Wrote iPod database");
            } catch (Exception e) {
                Log.Exception("Failed to save iPod database", e);
            }
            MediaDatabase.StopSync();
            progressUpdater.Finish();

            Hyena.Log.Debug("Ending AppleDevice sync thread cycle");
        }
Example #11
0
        private void OnGetTagFromFingerprint(object sender, EventArgs args)
        {
            active = true;
            Source source = ServiceManager.SourceManager.ActiveSource;

            UserJob job = new UserJob(AddinManager.CurrentLocalizer.GetString("Getting sound fingerprint"));

            job.SetResources(Resource.Cpu, Resource.Disk, Resource.Database);
            job.PriorityHints    = PriorityHints.SpeedSensitive;
            job.Status           = AddinManager.CurrentLocalizer.GetString("Scanning...");
            job.IconNames        = new string [] { "system-search", "gtk-find" };
            job.CanCancel        = true;
            job.CancelRequested += HandleJobCancelRequested;
            job.Register();

            if (account == null)
            {
                account = new LastfmAccount();
                LoginDialog dialog = new LoginDialog(account, true);
                dialog.Run();
                dialog.Destroy();
            }

            //comment the timeout system for TOS because still have issue and not seems to be linked...
            //System.DateTime start = System.DateTime.MinValue;
            ThreadPool.QueueUserWorkItem(delegate {
                try {
                    var selection = ((ITrackModelSource)source).TrackModel.Selection;
                    int total     = selection.Count;
                    int count     = 0;

                    foreach (TrackInfo track in ((ITrackModelSource)source).TrackModel.SelectedItems)
                    {
                        if (!active)
                        {
                            break;
                        }
                        if (String.IsNullOrEmpty(track.Uri.AbsolutePath))
                        {
                            continue;
                        }
                        ad = new AudioDecoder((int)track.Duration.TotalSeconds);
                        //respect last fm term of service :
                        //You will not make more than 5 requests per originating IP address per second, averaged over a 5 minute period
                        // 2 requests are done on each loop ==> time allowed by loop : 400ms

                        /*if (start != System.DateTime.MinValue) {
                         *  TimeSpan span = System.DateTime.Now - start;
                         *  if (lastFmTOSMinTimeout > span)
                         *      Thread.Sleep (lastFmTOSMinTimeout - span);
                         * }
                         * start = DateTime.Now;
                         */
                        byte[] fingerprint         = ad.Decode(track.Uri.AbsolutePath);
                        FingerprintRequest request = new FingerprintRequest();
                        request.Send(track, fingerprint, account);

                        int fpid = request.GetFpId();
                        //force GC to dispose
                        ad = null;

                        Log.DebugFormat("Last.fm fingerprint id for {0} is {1}", track.TrackTitle, fpid);

                        if (fpid > 0)
                        {
                            FetchMetadata(track, fpid);
                        }
                        else
                        {
                            Log.WarningFormat("Could not find fingerprint id for the track {0} !", track.TrackTitle);
                        }

                        job.Progress = (double)++count / (double)total;
                    }
                } catch (Exception e) {
                    account = null;
                    Log.Exception(e);
                } finally {
                    job.Finish();
                }
            });
        }
        private void RefreshMetadataThread(object state)
        {
            int total = ServiceManager.DbConnection.Query <int> ("SELECT count(*) FROM CoreTracks");

            if (total <= 0)
            {
                return;
            }

            UserJob job = new UserJob(Catalog.GetString("Refreshing Metadata"));

            job.SetResources(Resource.Cpu, Resource.Disk, Resource.Database);
            job.PriorityHints = PriorityHints.SpeedSensitive;
            job.Status        = Catalog.GetString("Scanning...");
            job.IconNames     = new string [] { "system-search", "gtk-find" };
            job.Register();

            HyenaSqliteCommand select_command = new HyenaSqliteCommand(
                String.Format(
                    "SELECT {0} FROM {1} WHERE {2}",
                    DatabaseTrackInfo.Provider.Select,
                    DatabaseTrackInfo.Provider.From,
                    DatabaseTrackInfo.Provider.Where
                    )
                );

            int count = 0;

            using (System.Data.IDataReader reader = ServiceManager.DbConnection.Query(select_command)) {
                while (reader.Read())
                {
                    DatabaseTrackInfo track = null;
                    try {
                        track = DatabaseTrackInfo.Provider.Load(reader);

                        if (track != null && track.Uri != null && track.Uri.IsFile)
                        {
                            try {
                                TagLib.File file = StreamTagger.ProcessUri(track.Uri);
                                StreamTagger.TrackInfoMerge(track, file, true);
                            } catch (Exception e) {
                                Log.Warning(String.Format("Failed to update metadata for {0}", track),
                                            e.GetType().ToString(), false);
                            }

                            track.Save(false);
                            track.Artist.Save();
                            track.Album.Save();

                            job.Status = String.Format("{0} - {1}", track.DisplayArtistName, track.DisplayTrackTitle);
                        }
                    } catch (Exception e) {
                        Log.Warning(String.Format("Failed to update metadata for {0}", track), e.ToString(), false);
                    }

                    job.Progress = (double)++count / (double)total;
                }
            }

            if (ServiceManager.DbConnection.Query <int> ("SELECT count(*) FROM CoreConfiguration WHERE Key = 'MetadataVersion'") == 0)
            {
                Execute(String.Format("INSERT INTO CoreConfiguration (EntryID, Key, Value) VALUES (null, 'MetadataVersion', {0})", CURRENT_METADATA_VERSION));
            }
            else
            {
                Execute(String.Format("UPDATE CoreConfiguration SET Value = {0} WHERE Key = 'MetadataVersion'", CURRENT_METADATA_VERSION));
            }

            job.Finish();
            ServiceManager.SourceManager.MusicLibrary.NotifyTracksChanged();
        }