상속: ImportManager
예제 #1
0
 public ImportPlaylistWorker(string name, string [] uris, PrimarySource source, DatabaseImportManager importer)
 {
     this.name = name;
     this.uris = uris;
     this.source = source;
     this.importer = importer;
 }
예제 #2
0
 public void Import()
 {
     try {
         if (importer == null) {
             importer = new Banshee.Library.LibraryImportManager ();
         }
         finished = false;
         importer.Finished += CreatePlaylist;
         importer.Enqueue (uris);
     } catch (PlaylistImportCanceledException e) {
         Hyena.Log.Exception (e);
     }
 }
        // WARNING: This will be called from a thread!
        protected override void LoadFromDevice ()
        {
            import_reset_event = new System.Threading.ManualResetEvent (false);

            importer = new DatabaseImportManager (this) {
                KeepUserJobHidden = true,
                SkipHiddenChildren = false
            };
            importer.Finished += OnImportFinished;

            foreach (string audio_folder in BaseDirectories) {
                importer.Enqueue (audio_folder);
            }

            import_reset_event.WaitOne ();
        }
예제 #4
0
        public static void ImportPlaylistToLibrary (string path, PrimarySource source, DatabaseImportManager importer)
        {
            try {
                SafeUri uri = new SafeUri (path);
                PlaylistParser parser = new PlaylistParser ();
                string relative_dir = System.IO.Path.GetDirectoryName (uri.LocalPath);
                if (relative_dir[relative_dir.Length - 1] != System.IO.Path.DirectorySeparatorChar) {
                    relative_dir = relative_dir + System.IO.Path.DirectorySeparatorChar;
                }
                parser.BaseUri = new Uri (relative_dir);
                if (parser.Parse (uri)) {
                    List<string> uris = new List<string> ();
                    foreach (PlaylistElement element in parser.Elements) {
                        uris.Add (element.Uri.LocalPath);
                    }

                    if (source == null) {
                        if (uris.Count > 0) {
                            // Get the media attribute of the 1st Uri in Playlist 
                            // and then determine whether the playlist belongs to Video or Music
                            SafeUri uri1 = new SafeUri (uris[0]);
                            var track = new TrackInfo ();
                            StreamTagger.TrackInfoMerge (track, uri1);

                            if (track.HasAttribute (TrackMediaAttributes.VideoStream))
                                source = ServiceManager.SourceManager.VideoLibrary;
                            else
                                source = ServiceManager.SourceManager.MusicLibrary;
                        }
                    }

                    // Give source a fallback value - MusicLibrary when it's null
                    if (source == null)
                        source = ServiceManager.SourceManager.MusicLibrary;
                    
                    // Only import an non-empty playlist
                    if (uris.Count > 0) {
                        ImportPlaylistWorker worker = new ImportPlaylistWorker (
                            parser.Title,
                            uris.ToArray (), source, importer);
                        worker.Import ();
                    }
                }
            } catch (Exception e) {
                Hyena.Log.Exception (e);
            }
        }
예제 #5
0
        public void Enqueue(string path)
        {
            try {
                SafeUri uri = new SafeUri (path);
                if (uri.IsLocalPath && !String.IsNullOrEmpty (uri.LocalPath)) {
                    path = uri.LocalPath;
                }
            } catch {
            }

            lock (this) {
                if (importer == null) {
                    importer = new DatabaseImportManager (this);
                    importer.KeepUserJobHidden = true;
                    importer.ImportResult += delegate (object o, DatabaseImportResultArgs args) {
                        Banshee.ServiceStack.Application.Invoke (delegate {
                            if (args.Error != null || path_to_play != null) {
                                return;
                            }

                            path_to_play = args.Path;
                            if (args.Track == null) {
                                // Play immediately if the track is already in the source,
                                // otherwise the call will be deferred until the track has
                                // been imported and loaded into the cache
                                PlayEnqueued ();
                            }
                        });
                    };

                    importer.Finished += delegate {
                        if (visible) {
                            ThreadAssist.ProxyToMain (delegate {
                                TrackInfo current_track = ServiceManager.PlaybackController.CurrentTrack;
                                // Don't switch to FSQ if the current item is a video
                                if (current_track == null || !current_track.HasAttribute (TrackMediaAttributes.VideoStream)) {
                                    ServiceManager.SourceManager.SetActiveSource (this);
                                }
                            });
                        }
                    };
                }

                if (PlaylistFileUtil.PathHasPlaylistExtension (path)) {
                    Banshee.Kernel.Scheduler.Schedule (new DelegateJob (delegate {
                        // If it's in /tmp it probably came from Firefox - just play it
                        if (path.StartsWith (Paths.SystemTempDir)) {
                            Banshee.Streaming.RadioTrackInfo.OpenPlay (path);
                        } else {
                            PlaylistFileUtil.ImportPlaylistToLibrary (path, this, importer);
                        }
                    }));
                } else {
                    importer.Enqueue (path);
                }
            }
        }
        public static void ImportPlaylistToLibrary (string path, PrimarySource source, DatabaseImportManager importer)
        {
            try {
                SafeUri uri = new SafeUri (path);
                PlaylistParser parser = new PlaylistParser ();
                string relative_dir = System.IO.Path.GetDirectoryName (uri.LocalPath);
                if (relative_dir[relative_dir.Length - 1] != System.IO.Path.DirectorySeparatorChar) {
                    relative_dir = relative_dir + System.IO.Path.DirectorySeparatorChar;
                }
                parser.BaseUri = new Uri (relative_dir);
                if (parser.Parse (uri)) {
                    List<string> uris = new List<string> ();
                    foreach (Dictionary<string, object> element in parser.Elements) {
                        uris.Add (((Uri)element["uri"]).LocalPath);
                    }

                    ImportPlaylistWorker worker = new ImportPlaylistWorker (
                        parser.Title,
                        uris.ToArray (), source, importer);
                    worker.Import ();
                }
            } catch (Exception e) {
                Hyena.Log.Exception (e);
            }
        }