コード例 #1
0
        public KarmaTrackInfo(KarmaLib.Song song, string mount)
        {
            string fidstr = String.Format("{0:x8}", song.Id);

            Uri = new SafeUri(String.Format("file://{0}/fids0/_{1}/{2}", mount,
                                            fidstr.Substring(0, 5), fidstr.Substring(5)));
            karma_id    = song.Id;
            AlbumTitle  = song.Album;
            ArtistName  = song.Artist;
            TrackTitle  = song.Title;
            Genre       = song.Genre;
            Duration    = new TimeSpan(song.Duration * 1000L);
            PlayCount   = (int)song.PlayCount;
            LastPlayed  = song.LastPlayed;
            TrackCount  = 0;
            TrackNumber = (int)song.TrackNumber;
            Year        = song.Year;
        }
コード例 #2
0
            public RssLoader(UriCollection collection, SafeUri uri)
            {
                XmlDocument doc = new XmlDocument();

                doc.Load(uri.ToString());
                XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);

                ns.AddNamespace("media", "http://search.yahoo.com/mrss/");
                ns.AddNamespace("pheed", "http://www.pheed.com/pheed/");
                ns.AddNamespace("apple", "http://www.apple.com/ilife/wallpapers");

                List <FilePhoto> items = new List <FilePhoto> ();
                XmlNodeList      list  = doc.SelectNodes("/rss/channel/item/media:content", ns);

                foreach (XmlNode item in list)
                {
                    SafeUri image_uri = new SafeUri(item.Attributes ["url"].Value);
                    Hyena.Log.DebugFormat("flickr uri = {0}", image_uri.ToString());
                    items.Add(new FilePhoto(image_uri));
                }

                if (list.Count < 1)
                {
                    list = doc.SelectNodes("/rss/channel/item/pheed:imgsrc", ns);
                    foreach (XmlNode item in list)
                    {
                        SafeUri image_uri = new SafeUri(item.InnerText.Trim());
                        Hyena.Log.DebugFormat("pheed uri = {0}", uri);
                        items.Add(new FilePhoto(image_uri));
                    }
                }

                if (list.Count < 1)
                {
                    list = doc.SelectNodes("/rss/channel/item/apple:image", ns);
                    foreach (XmlNode item in list)
                    {
                        SafeUri image_uri = new SafeUri(item.InnerText.Trim());
                        Hyena.Log.DebugFormat("apple uri = {0}", uri);
                        items.Add(new FilePhoto(image_uri));
                    }
                }
                collection.Add(items.ToArray());
            }
コード例 #3
0
        static Type GetLoaderType(SafeUri uri)
        {
            // check if GIO can find the file, which is not the case
            // with filenames with invalid encoding
            var file = GLib.FileFactory.NewForUri(uri);

            if (!file.Exists)
            {
                return(null);
            }

            string extension = uri.GetExtension().ToLower();

            // Ignore video thumbnails
            if (extension == ".thm")
            {
                return(null);
            }

            // Detect mime-type
            var    info = file.QueryInfo("standard::content-type,standard::size", FileQueryInfoFlags.None, null);
            string mime = info.ContentType;
            long   size = info.Size;

            // Empty file
            if (size == 0)
            {
                return(null);
            }

            Type t = null;

            if (NameTable.TryGetValue(mime, out t))
            {
                return(t);
            }

            if (NameTable.TryGetValue(extension, out t))
            {
                return(t);
            }

            return(null);
        }
コード例 #4
0
        public Pixbuf GetThumbnail(SafeUri fileUri, ThumbnailSize size)
        {
            var thumbnailUri = GetThumbnailPath(fileUri, size);
            var thumbnail    = LoadThumbnail(thumbnailUri);

            if (IsValid(fileUri, thumbnail))
            {
                return(thumbnail);
            }
            IThumbnailer thumbnailer = thumbnailerFactory.GetThumbnailerForUri(fileUri);

            if (thumbnailer == null)
            {
                return(null);
            }
            return(!thumbnailer.TryCreateThumbnail(thumbnailUri, size)
                                ? null
                                : LoadThumbnail(thumbnailUri));
        }
コード例 #5
0
ファイル: XdgThumbnailSpec.cs プロジェクト: cizma/f-spot
        private static Pixbuf CreateFrom(SafeUri uri, SafeUri thumb_uri, ThumbnailSize size, PixbufLoader loader)
        {
            var    pixels = size == ThumbnailSize.Normal ? 128 : 256;
            Pixbuf pixbuf;

            try {
                pixbuf = loader(uri);
            } catch (Exception e) {
                Log.DebugFormat("Failed loading image for thumbnailing: {0}", uri);
                Log.DebugException(e);
                return(null);
            }
            double scale_x  = (double)pixbuf.Width / pixels;
            double scale_y  = (double)pixbuf.Height / pixels;
            double scale    = Math.Max(1.0, Math.Max(scale_x, scale_y));
            int    target_x = (int)(pixbuf.Width / scale);
            int    target_y = (int)(pixbuf.Height / scale);

            // FIXME, This isn't correct, but for now it ensures that the minimum
            //        value is 1 so that pixbuf.ScaleSimple doesn't return null
            //        Seems to only happen in rare(?) cases
            if (target_x == 0)
            {
                target_x = 1;
            }
            if (target_y == 0)
            {
                target_y = 1;
            }
            var thumb_pixbuf = pixbuf.ScaleSimple(target_x, target_y, InterpType.Bilinear);

            pixbuf.Dispose();

            var file  = GLib.FileFactory.NewForUri(uri);
            var info  = file.QueryInfo("time::modified", GLib.FileQueryInfoFlags.None, null);
            var mtime = info.GetAttributeULong("time::modified").ToString();

            thumb_pixbuf.Savev(thumb_uri.LocalPath, "png",
                               new string [] { ThumbUriOpt, ThumbMTimeOpt, null },
                               new string [] { uri, mtime });

            return(thumb_pixbuf);
        }
コード例 #6
0
        static void SaveToSuitableFormat(SafeUri destination, Pixbuf pixbuf, uint jpeg_quality)
        {
            // FIXME: this needs to work on streams rather than filenames. Do that when we switch to
            // newer GDK.
            var extension = destination.GetExtension().ToLower();

            if (extension == ".png")
            {
                pixbuf.Save(destination.LocalPath, "png");
            }
            else if (extension == ".jpg" || extension == ".jpeg")
            {
                pixbuf.Save(destination.LocalPath, "jpeg", jpeg_quality);
            }
            else
            {
                throw new NotImplementedException("Saving this file format is not supported");
            }
        }
コード例 #7
0
        private void OnNativeFinished()
        {
            SafeUri uri = current_uri;

            int best_bpm = -1, best_bpm_count = 0;

            foreach (int bpm in bpm_histogram.Keys)
            {
                int count = bpm_histogram[bpm];
                if (count > best_bpm_count)
                {
                    best_bpm_count = count;
                    best_bpm       = bpm;
                }
            }

            Reset();
            OnFileFinished(uri, best_bpm);
        }
コード例 #8
0
ファイル: PhotoStore.cs プロジェクト: Yetangitu/f-spot
        private void GetAllVersions(string ids)
        {
            Hyena.Data.Sqlite.IDataReader reader = Database.Query("SELECT photo_id, version_id, name, base_uri, filename, import_md5, protected FROM photo_versions WHERE photo_id IN " + ids);

            while (reader.Read())
            {
                uint  id    = Convert.ToUInt32(reader ["photo_id"]);
                Photo photo = LookupInCache(id);

                if (photo == null)
                {
                    //Console.WriteLine ("Photo {0} not found", id);
                    continue;
                }

                if (photo.AllVersionsLoaded)
                {
                    //Console.WriteLine ("Photo {0} already Loaded", photo);
                    continue;
                }

                if (reader ["version_id"] != null)
                {
                    uint   version_id   = Convert.ToUInt32(reader ["version_id"]);
                    string name         = reader["name"].ToString();
                    var    base_uri     = new SafeUri(reader ["base_uri"].ToString(), true);
                    var    filename     = reader ["filename"].ToString();
                    string import_md5   = reader["import_md5"] != null ? reader ["import_md5"].ToString() : null;
                    bool   is_protected = Convert.ToBoolean(reader["protected"]);

                    photo.AddVersionUnsafely(version_id, base_uri, filename, import_md5, name, is_protected);
                }

                /*
                 * string directory_path = null;
                 * if (reader [3] != null)
                 *      directory_path = reader [3].ToString ();
                 * System.Console.WriteLine ("directory_path = {0}", directory_path);
                 */
            }
            reader.Dispose();
        }
コード例 #9
0
        public ThumbnailService(IXdgDirectoryService xdgDirectoryService, IThumbnailerFactory thumbnailerFactory, IFileSystem fileSystem)
        {
            this.xdgDirectoryService = xdgDirectoryService;
            this.thumbnailerFactory  = thumbnailerFactory;
            this.fileSystem          = fileSystem;

            var large = new SafeUri(Path.Combine(xdgDirectoryService.GetThumbnailsDir(ThumbnailSize.Large)));

            if (!fileSystem.Directory.Exists(large))
            {
                fileSystem.Directory.CreateDirectory(large);
            }

            var normal = new SafeUri(Path.Combine(xdgDirectoryService.GetThumbnailsDir(ThumbnailSize.Normal)));

            if (!fileSystem.Directory.Exists(normal))
            {
                fileSystem.Directory.CreateDirectory(normal);
            }
        }
コード例 #10
0
 public void DeleteThumbnails(SafeUri fileUri)
 {
     Enum.GetValues(typeof(ThumbnailSize))
     .OfType <ThumbnailSize> ()
     .Select(size => GetThumbnailPath(fileUri, size))
     .ToList()
     .ForEach(thumbnailUri => {
         if (fileSystem.File.Exists(thumbnailUri))
         {
             try {
                 fileSystem.File.Delete(thumbnailUri);
             }
             // Analysis disable once EmptyGeneralCatchClause
             catch {
                 // catch and ignore any errors on deleting thumbnails
                 // e.g., unauthorized access, read-only filesystem
             }
         }
     });
 }
コード例 #11
0
ファイル: AppleDeviceSource.cs プロジェクト: shaw1337/banshee
        protected override void AddTrackToDevice(DatabaseTrackInfo track, SafeUri fromUri)
        {
            lock (sync_mutex) {
                if (track.PrimarySourceId == DbId)
                {
                    return;
                }

                if (track.Duration.Equals(TimeSpan.Zero))
                {
                    throw new Exception(Catalog.GetString("Track duration is zero"));
                }

                AppleDeviceTrackInfo ipod_track = new AppleDeviceTrackInfo(track);
                ipod_track.Uri           = fromUri;
                ipod_track.PrimarySource = this;

                tracks_to_add.Enqueue(ipod_track);
            }
        }
コード例 #12
0
ファイル: SourceWatcher.cs プロジェクト: thoja21/banshee-1
        private void RenameTrack(string oldFullPath, string fullPath)
        {
            if (oldFullPath == fullPath)
            {
                // FIXME: bug in Mono, see bnc#322330
                return;
            }
            string old_uri        = new SafeUri(oldFullPath).AbsoluteUri;
            string new_uri        = new SafeUri(fullPath).AbsoluteUri;
            string pattern        = StringUtil.EscapeLike(old_uri) + "%";
            var    rename_command = new HyenaSqliteCommand(String.Format(@"
                UPDATE CoreTracks
                SET Uri = REPLACE ({0}, ?, ?),
                    DateUpdatedStamp = ?
                WHERE {0} LIKE ? ESCAPE '\'",
                                                                         BansheeQuery.UriField.Column),
                                                           old_uri, new_uri, DateTime.Now, pattern);

            ServiceManager.DbConnection.Execute(rename_command);
        }
コード例 #13
0
ファイル: PhotoStore.cs プロジェクト: ermshiperete/f-spot
        void GetVersions(Photo photo)
        {
            using (var reader = Database.Query(new HyenaSqliteCommand(
                                                   "SELECT version_id, name, base_uri, filename, import_md5, protected " +
                                                   "FROM photo_versions " +
                                                   "WHERE photo_id = ?",
                                                   photo.Id))) {
                while (reader.Read())
                {
                    uint   version_id   = Convert.ToUInt32(reader ["version_id"]);
                    string name         = reader ["name"].ToString();
                    var    base_uri     = new SafeUri(reader ["base_uri"].ToString(), true);
                    var    filename     = reader ["filename"].ToString();
                    string import_md5   = reader ["import_md5"] != null ? reader ["import_md5"].ToString() : null;
                    bool   is_protected = Convert.ToBoolean(reader ["protected"]);

                    photo.AddVersionUnsafely(version_id, base_uri, filename, import_md5, name, is_protected);
                }
            }
        }
コード例 #14
0
        public void RipTrack(int trackIndex, TrackInfo track, SafeUri outputUri, out bool taggingSupported)
        {
            TrackReset();
            current_track = track;

            using (TagList tags = new TagList(track)) {
                output_path = String.Format("{0}.{1}", outputUri.LocalPath, output_extension);

                // Avoid overwriting an existing file
                int i = 1;
                while (Banshee.IO.File.Exists(new SafeUri(output_path)))
                {
                    output_path = String.Format("{0} ({1}).{2}", outputUri.LocalPath, i++, output_extension);
                }

                Log.DebugFormat("GStreamer ripping track {0} to {1}", trackIndex, output_path);

                br_rip_track(handle, trackIndex + 1, output_path, tags.Handle, out taggingSupported);
            }
        }
コード例 #15
0
        /// <summary>
        /// Adds a station track to this source.
        /// </summary>
        /// <param name="track">
        /// A <see cref="DatabaseTrackInfo"/> -- the track to be added to this source
        /// </param>
        private void AddStation(DatabaseTrackInfo track)
        {
            DatabaseTrackInfo station = track ?? new DatabaseTrackInfo();

            if (track.Copyright != null)
            {
                SafeUri url = plugin.RetrieveUrl(track.Copyright);
                if (url != null)
                {
                    track.Uri = url;
                }
                track.Copyright = null;
            }
            station.IsLive        = true;
            station.PrimarySource = this;
            if (!String.IsNullOrEmpty(station.TrackTitle) && station.Uri != null && station.Uri is SafeUri)
            {
                this.AddTrack(station);
            }
        }
コード例 #16
0
ファイル: MtpTrackInfo.cs プロジェクト: gaodeng/banshee-osx
        public MtpTrackInfo(MtpDevice device, Track file) : base()
        {
            this.file  = file;
            ExternalId = file.FileId;

            AlbumTitle  = file.Album;
            ArtistName  = file.Artist;
            Duration    = TimeSpan.FromMilliseconds(file.Duration);
            Genre       = file.Genre;
            PlayCount   = file.UseCount < 0 ? 0 : (int)file.UseCount;
            Rating      = file.Rating < 0 ? 0 : (file.Rating / 20);
            TrackTitle  = file.Title;
            TrackNumber = file.TrackNumber < 0 ? 0 : (int)file.TrackNumber;
            Year        = file.Year;
            BitRate     = (int)file.Bitrate;
            SampleRate  = (int)file.SampleRate;
            FileSize    = (long)file.FileSize;

            MediaAttributes = TrackMediaAttributes.AudioStream;
            if (device != null)
            {
                SetAttributeIf(file.InFolder(device.PodcastFolder) || Genre == "Podcast", TrackMediaAttributes.Podcast);
                SetAttributeIf(file.InFolder(device.MusicFolder), TrackMediaAttributes.Music);
                SetAttributeIf(file.InFolder(device.VideoFolder), TrackMediaAttributes.VideoStream);
            }

            // This can be implemented if there's enough people requesting it
            CanPlay           = false;
            CanSaveToDatabase = true;
            //NeedSync = false;

            // TODO detect if this is a video file and set the MediaAttributes appropriately?

            /*Profile profile = ServiceManager.Get<MediaProfileManager> ().GetProfileForExtension (System.IO.Path.GetExtension (file.FileName));
             * if (profile != null) {
             *  profile.
             * }*/

            // Set a URI even though it's not actually accessible through normal API's.
            Uri = new SafeUri(GetPathFromMtpTrack(file));
        }
コード例 #17
0
        // internal for unit testing with Moq
        internal bool IsValid(SafeUri uri, Pixbuf pixbuf)
        {
            if (pixbuf == null)
            {
                return(false);
            }

            if (pixbuf.GetOption(ThumbUriOpt) != uri.ToString())
            {
                return(false);
            }

            if (!fileSystem.File.Exists(uri))
            {
                return(false);
            }

            var mTime = fileSystem.File.GetMTime(uri);

            return(pixbuf.GetOption(ThumbMTimeOpt) == mTime.ToString());
        }
コード例 #18
0
        public FileImportSource(SafeUri root, string name, string icon_name)
        {
            Root = root;
            Name = name;

            if (root != null)
            {
                if (IsIPodPhoto)
                {
                    IconName = "multimedia-player";
                }
                else if (IsCamera)
                {
                    IconName = "media-flash";
                }
                else
                {
                    IconName = icon_name;
                }
            }
        }
コード例 #19
0
        protected override void OnImportRequested(string path)
        {
            try {
                DatabaseTrackInfo track = ImportTrack(path);
                if (track != null && track.TrackId > 0)
                {
                    UpdateProgress(String.Format("{0} - {1}",
                                                 track.DisplayArtistName, track.DisplayTrackTitle));
                }
                else
                {
                    UpdateProgress(null);
                }

                OnImportResult(track, path, null);
            } catch (Exception e) {
                LogError(SafeUri.UriToFilename(path), e);
                UpdateProgress(null);
                OnImportResult(null, path, e);
            }
        }
コード例 #20
0
        protected virtual string ExportUri(SafeUri uri)
        {
            if (BaseUri == null)
            {
                return(uri.IsLocalPath ? uri.LocalPath : uri.AbsoluteUri);
            }

            if (!uri.IsLocalPath)
            {
                return(uri.AbsoluteUri);
            }

            if (RootPath != null)
            {
                return(Paths.SwitchRoot(uri.LocalPath, BaseUri.LocalPath, RootPath.LocalPath));
            }

            var result = Paths.MakePathRelative(uri.LocalPath, new DirectoryInfo(BaseUri.LocalPath).FullName);

            return(result ?? uri.AbsoluteUri);
        }
コード例 #21
0
        public static IImageLoader Create(SafeUri uri)
        {
            string path      = uri.AbsolutePath;
            string extension = System.IO.Path.GetExtension(path).ToLower();

            System.Type  t;
            IImageLoader loader;

            if (!name_table.TryGetValue(extension, out t))
            {
                GLib.FileInfo info = GLib.FileFactory.NewForUri(uri).QueryInfo("standard::type,standard::content-type", GLib.FileQueryInfoFlags.None, null);
                if (!name_table.TryGetValue(info.ContentType, out t))
                {
                    throw new Exception("Loader requested for unknown file type: " + extension);
                }
            }

            loader = (IImageLoader)System.Activator.CreateInstance(t);

            return(loader);
        }
コード例 #22
0
        public static void SaveSafely(this TagLib.Image.File metadata, SafeUri photo_uri, bool always_sidecar)
        {
            if (always_sidecar || !metadata.Writeable || metadata.PossiblyCorrupt)
            {
                if (!always_sidecar && metadata.PossiblyCorrupt)
                {
                    Hyena.Log.WarningFormat($"Metadata of file {photo_uri} may be corrupt, refusing to write to it, falling back to XMP sidecar.");
                }

                var sidecar_res = new GIOTagLibFileAbstraction()
                {
                    Uri = GetSidecarUri(photo_uri)
                };

                metadata.SaveXmpSidecar(sidecar_res);
            }
            else
            {
                metadata.Save();
            }
        }
コード例 #23
0
        private void RipNextTrack()
        {
            if (queue.Count == 0)
            {
                OnFinished();
                Dispose();
                return;
            }

            AudioCdTrackInfo track = queue.Dequeue();

            user_job.Title = String.Format(Catalog.GetString("Importing {0} of {1}"),
                                           ++track_index, source.DiscModel.EnabledCount);
            status          = String.Format("{0} - {1}", track.ArtistName, track.TrackTitle);
            user_job.Status = status;

            SafeUri uri = new SafeUri(FileNamePattern.BuildFull(ServiceManager.SourceManager.MusicLibrary.BaseDirectory, track, null));
            bool    tagging_supported;

            ripper.RipTrack(track.IndexOnDisc, track, uri, out tagging_supported);
        }
コード例 #24
0
        public static bool IsRaw(SafeUri uri)
        {
            string [] raw_extensions =
            {
                ".arw",
                ".crw",
                ".cr2",
                ".dng",
                ".mrw",
                ".nef",
                ".orf",
                ".pef",
                ".raw",
                ".raf",
                ".rw2",
                ".srw",
            };
            var extension = uri.GetExtension().ToLower();

            return(raw_extensions.Any(x => x == extension));
        }
コード例 #25
0
        void ShowFolderSelector()
        {
            var file_chooser = new FileChooserDialog(
                Catalog.GetString("Import"), this,
                FileChooserAction.SelectFolder,
                Stock.Cancel, ResponseType.Cancel,
                Stock.Open, ResponseType.Ok);

            file_chooser.SelectMultiple = false;
            file_chooser.LocalOnly      = false;

            int response = file_chooser.Run();

            if ((ResponseType)response == ResponseType.Ok)
            {
                var uri = new SafeUri(file_chooser.Uri, true);
                SwitchToFolderSource(uri);
            }

            file_chooser.Destroy();
        }
コード例 #26
0
        static List <IImportSource> ScanSources()
        {
            var monitor = GLib.VolumeMonitor.Default;
            var sources = new List <IImportSource> ();

            foreach (var mount in monitor.Mounts)
            {
                var root = new SafeUri(mount.Root.Uri, true);

                var themed_icon = (mount.Icon as GLib.ThemedIcon);
                if (themed_icon != null && themed_icon.Names.Length > 0)
                {
                    sources.Add(new FileImportSource(root, mount.Name, themed_icon.Names [0]));
                }
                else
                {
                    sources.Add(new FileImportSource(root, mount.Name, null));
                }
            }
            return(sources);
        }
コード例 #27
0
 protected override void OpenUri(SafeUri uri)
 {
     _stream.Open (uri.AbsoluteUri);
 }
コード例 #28
0
        private static void OnDownloadCompletedHandler(object sender,
                DownloadCompletedEventArgs args)
        {
            DownloadInfo dif = args.DownloadInfo;
            SafeUri local_uri = new SafeUri (args.LocalUri);

            if (dif == null || local_uri == null)
            {
                return;
            }

            PodcastInfo pi = null;

            lock (downloads.SyncRoot)
            {
                if (downloads.Contains (dif))
                {
                    pi = downloads [args.DownloadInfo] as PodcastInfo;
                }
            }

            if (pi != null)
            {
                TrackInfo ti = null;

                try
                {
                    try
                    {
                        ti = new LibraryTrackInfo(local_uri.LocalPath);
                    }
                    catch (ApplicationException)
                    {
                        ti = Globals.Library.TracksFnKeyed
                             [PathUtil.MakeFileNameKey(local_uri)] as TrackInfo;
                    }
                }
                catch (Exception e)
                {
                    PodcastErrorsSource.Instance.AddError (
              			local_uri.ToString (),
                        Catalog.GetString ("Unable to add file to library"),
                        e
               			);
                }

                pi.IsDownloaded = true;

                if (ti != null)
                {
                    pi.Track = ti;
                }
                else
                {
                    pi.DownloadFailed = true;
                    PodcastDBManager.Commit (pi);
                    return;
                }

                pi.LocalPath = local_uri.ToString ();
                PodcastDBManager.Commit (pi);
                pi.Feed.UpdateCounts ();

                ThreadAssist.ProxyToMain (delegate {
                                              Library.AddTrack (ti, pi, true);
                                          });
            }

            source.Update ();
        }
コード例 #29
0
        public void DetectMood(SafeUri audio_file_uri, Action<Moodbar> when_finished_closure)
        {
            if (audio_file_uri == null)
                throw new ArgumentNullException ("Uri cannot be null.");
            if (!audio_file_uri.IsLocalPath)
                throw new ArgumentException ("Uri must point to a local file.");

            if (!Banshee.IO.Directory.Exists (Moodbar.MoodFilesStorage))
                Banshee.IO.Directory.Create (Moodbar.MoodFilesStorage);

            // using a temp file - nothing will try to load it during it's generation'
            var mood_file_path = Moodbar.GetMoodFilePath (audio_file_uri.LocalPath);
            var rnd_int = rnd.Next ();
            var temp_mood_file_path = Moodbar.GetMoodFilePath (rnd_int.ToString () + ".tmp");

            var args = string.Format ("\"{0}\" -o \"{1}\"", audio_file_uri.LocalPath, temp_mood_file_path);
            var proc_info = new System.Diagnostics.ProcessStartInfo ("moodbar", args);
            var proc = new System.Diagnostics.Process ();
            proc.StartInfo = proc_info;
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.CreateNoWindow = true;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError = true;
            proc.EnableRaisingEvents = true;

            int track_id = DatabaseTrackInfo.GetTrackIdForUri (audio_file_uri.AbsoluteUri);

            proc.Exited += delegate {
                // add entry to DB
                string mood_file_name = Moodbar.GetMoodFileName (audio_file_uri.LocalPath);

                if (proc.ExitCode == 0) {
                    ServiceManager.DbConnection.Execute (
                        "INSERT OR REPLACE INTO MoodPaths (TrackID, FileName, LastAttempt) VALUES (?, ?, ?)",
                        track_id, mood_file_name, DateTime.Now);

                    // rename temp file to original name
                    Banshee.IO.File.Move (new SafeUri (SafeUri.FilenameToUri (temp_mood_file_path)),
                        new SafeUri (SafeUri.FilenameToUri (mood_file_path)));

                    var moodbar = Moodbar.LoadMoodbar (mood_file_name);
                    lock (sync) {
                        if (!loaded_moodbars.ContainsKey (audio_file_uri.LocalPath))
                            loaded_moodbars.Add (audio_file_uri.LocalPath, moodbar);
                    }

                    when_finished_closure (moodbar);
                } else {
                    // an error occurred

                    ServiceManager.DbConnection.Execute (
                        "INSERT OR REPLACE INTO MoodPaths (TrackID, FileName, LastAttempt) VALUES (?, ?, ?)",
                        track_id, null, DateTime.Now);

                    // when i used Banshe.IO.File.Delete it freezed - why ?!
                    System.IO.File.Delete (temp_mood_file_path);
                    Hyena.Log.ErrorFormat ("Error while detecting mood: program exited with exit code: {0}\n{1}", proc.ExitCode, proc.StandardOutput.ReadToEnd ());
                    when_finished_closure (null);
                }
            };

            try {
                proc.Start ();
            } catch (Exception e) {
                ServiceManager.DbConnection.Execute (
                    "INSERT OR REPLACE INTO MoodPaths (TrackID, FileName, LastAttempt) VALUES (?, ?, ?)",
                    track_id, null, DateTime.Now);

                Hyena.Log.ErrorFormat ("Error while detecting mood {0}", e);
                when_finished_closure (null);
            }
        }
コード例 #30
0
 public RadioTrackInfo(Station station, string uri)
     : base()
 {
     Title = station.Title;
     Uri = new SafeUri(uri);
 }
コード例 #31
0
        public Moodbar GetMoodbarQuick(SafeUri audio_file_uri)
        {
            if (audio_file_uri == null)
                throw new ArgumentNullException ("Uri cannot be null.");
            if (!audio_file_uri.IsLocalPath)
                throw new ArgumentException ("Uri must point to a local file.");

            return GetMoodbar (audio_file_uri.LocalPath);
        }
コード例 #32
0
        private PodcastInfo(int id, PodcastFeedInfo feed, string url)
        {
            treeIter = TreeIter.Zero;

            this.id = id;
            this.feed = feed;
            this.url = new SafeUri (url);
        }
コード例 #33
0
        private void Play(SafeUri uri)
        {
            PlayerEngineCore.Open (uri);

            ThreadAssist.Spawn ( delegate {
                                     PlayerEngineCore.Play ();
                                 });
        }