Example #1
0
        public void BansheeToMtpTrack()
        {
            TrackInfo track_info = new TrackInfo ();
            track_info.ArtistName = "Banshee Artist";
            track_info.AlbumTitle = "Banshee Album";
            track_info.TrackTitle = "Banshee Title";
            track_info.Year = 2003;
            track_info.Duration = TimeSpan.FromSeconds (3600 * 1.32);
            track_info.Rating = 2;
            track_info.TrackNumber = 13;

            Track track = new Track ("foo.mp3", 1000);
            MtpTrackInfo.ToMtpTrack (track_info, track);

            Assert.AreEqual ("Banshee Artist", track.Artist);
            Assert.AreEqual ("Banshee Album", track.Album);
            Assert.AreEqual ("Banshee Title", track.Title);
            Assert.AreEqual (1000 * 3600 * 1.32, track.Duration);
            Assert.AreEqual (40, track.Rating);
            Assert.AreEqual (13, track.TrackNumber);
            Assert.AreEqual (2003, track.Year);

            //track.ReleaseDate = "00000101T0000.00";
            //track_info = new MtpTrackInfo (track);
            //Assert.AreEqual (0, track_info.Year);
        }
Example #2
0
        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, true) || Genre == "Podcast", TrackMediaAttributes.Podcast);
                SetAttributeIf (file.InFolder (device.MusicFolder, true), TrackMediaAttributes.Music);
                SetAttributeIf (file.InFolder (device.VideoFolder, true), 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));
        }
Example #3
0
        public void MtpToBansheeTrack()
        {
            Track track = new Track ("foo.mp3", 1000);
            track.Album = "Mtp Album";
            track.Artist = "Mtp Artist";
            track.Title = "Mtp Title";
            track.Duration = (uint) (1000 * 132.2);
            track.Rating = 80;
            track.TrackNumber = 3;

            TrackInfo track_info = new MtpTrackInfo (null, track);
            Assert.AreEqual ("Mtp Artist", track_info.ArtistName);
            Assert.AreEqual ("Mtp Album", track_info.AlbumTitle);
            Assert.AreEqual ("Mtp Title", track_info.TrackTitle);
            Assert.AreEqual (132.2, track_info.Duration.TotalSeconds);
            Assert.AreEqual (4, track_info.Rating);
            Assert.AreEqual (3, track_info.TrackNumber);
            Assert.AreEqual (0, track_info.Year);

            track.Year = 1983;
            track_info = new MtpTrackInfo (null, track);
            Assert.AreEqual (1983, track_info.Year);
        }
Example #4
0
 public Track TrackInfoToMtpTrack (TrackInfo track, SafeUri fromUri)
 {
     Track f = new Track (System.IO.Path.GetFileName (fromUri.LocalPath), (ulong) Banshee.IO.File.GetSize (fromUri), mtp_device);
     MtpTrackInfo.ToMtpTrack (track, f);
     return f;
 }
Example #5
0
        protected override void OnTracksDeleted ()
        {
            // Hack to get the disk usage indicate to be accurate, which seems to
            // only be updated when tracks are added, not removed.
            try {
                lock (mtp_device) {
                    using (System.IO.TextWriter writer = new System.IO.StreamWriter (Banshee.IO.File.OpenWrite (empty_file, true))) {
                        writer.Write ("foo");
                    }
                    Track mtp_track = new Track (System.IO.Path.GetFileName (empty_file.LocalPath), 3, mtp_device);

                    mtp_device.UploadTrack (empty_file.AbsolutePath, mtp_track, mtp_device.MusicFolder);
                    mtp_device.Remove (mtp_track);
                    Banshee.IO.File.Delete (empty_file);
                }
            } catch {}
            base.OnTracksDeleted ();
        }
Example #6
0
 internal static void ToMtpTrack(TrackInfo track, Track f)
 {
     f.Album = track.AlbumTitle;
     f.Artist = track.ArtistName;
     f.Duration = (uint)track.Duration.TotalMilliseconds;
     f.Genre = track.Genre;
     f.UseCount = (uint)track.PlayCount;
     f.Rating = (ushort)(track.Rating * 20);
     f.Title = track.TrackTitle;
     f.TrackNumber = (ushort)track.TrackNumber;
     f.Year = track.Year;
 }
Example #7
0
 public static string GetPathFromMtpTrack(Track track)
 {
     return String.Format ("mtp://{0}/{1}", track.FileId, track.FileName);
 }
Example #8
0
        private static FileType DetectFileType(Track track)
        {
            string ext = System.IO.Path.GetExtension (track.FileName);

            // Strip leading .
            if (ext.Length > 0)
                ext = ext.Substring (1, ext.Length - 1);

            // this is a hack; catch all m4(a|b|v|p)
            if (ext != null && ext.ToLower ().StartsWith ("m4"))
                ext = "mp4";

            FileType type = (FileType) Enum.Parse (typeof(FileType), ext, true);
            //if (type == null)
            //    return FileType.UNKNOWN;
            return type;
        }
Example #9
0
        public void UploadTrack (string path, Track track, Folder folder, ProgressFunction callback)
        {
            if (string.IsNullOrEmpty(path))
                throw new ArgumentNullException("path");
            if (track == null)
                throw new ArgumentNullException("track");

            folder = folder ?? MusicFolder;
            if (folder != null) {
                track.trackStruct.parent_id = folder.FolderId;
            }
            
            // We send the trackstruct by ref so that when the file_id gets filled in, our copy is updated
            Track.SendTrack (Handle, path, ref track.trackStruct, callback, IntPtr.Zero);
            // LibMtp.GetStorage (Handle, 0);
        }
Example #10
0
 public void UploadTrack (string path, Track track, Folder folder)
 {
     UploadTrack (path, track, folder, null);
 }
Example #11
0
 public void Remove (Track track)
 {
     DeleteObject(Handle, track.FileId);
 }
 public void RemoveTrack (Track track)
 {
     RemoveTrack ((int)track.FileId);
 }
 public void AddTrack (Track track)
 {
     AddTrack ((int)track.FileId);
 }
Example #14
0
 public void UploadTrack(string path, Track track, Folder folder)
 {
     UploadTrack(path, track, folder, null);
 }
Example #15
0
 public void Remove(Track track)
 {
     DeleteObject(Handle, track.FileId);
 }