Inheritance: ICloneable
コード例 #1
0
 private static string FromDaap(Database database, Track track)
 {
     return string.Format(
         ExternalIdFormat,
         database.Id,
         track.Id,
         track.Format);
 }
コード例 #2
0
        public string GetSongUrl(string externalId)
        {
            string format;
            int databaseId, trackId;

            ToDaap(externalId, out databaseId, out trackId, out format);

            var database = this._client.Databases.FirstOrDefault(d => d.Id == databaseId);

            var track = new Track();
            track.SetId(trackId);
            track.Format = format;

            database.DownloadTrack(track, _tempFilename);

            return _tempFilename;
        }
コード例 #3
0
ファイル: Playlist.cs プロジェクト: mono/daap-sharp
 public void AddTrack(Track track)
 {
     AddTrack (track, tracks.Count + 1);
 }
コード例 #4
0
ファイル: BeaglePlugin.cs プロジェクト: snorp/tangerine
        private void OnHitsAdded(HitsAddedResponse response)
        {
            foreach (Hit hit in response.Hits) {
                if (hit.Uri.Scheme != Uri.UriSchemeFile)
                    continue;

                Track track;

                if (hit.GetFirstProperty ("fixme:title") != null) {
                    track = new Track ();
                    track.TrackNumber = GetHitInteger (hit, "fixme:tracknumber");
                    track.TrackCount = GetHitInteger (hit, "fixme:trackcount");
                    track.Year = GetHitInteger (hit, "fixme:year");
                    track.Album = hit.GetFirstProperty ("fixme:album");
                    track.Artist = hit.GetFirstProperty ("fixme:artist");
                    track.Title = hit.GetFirstProperty ("fixme:title");
                    track.Genre = hit.GetFirstProperty ("fixme:genre");
                    track.FileName = hit.Uri.LocalPath;
                    track.Format = Path.GetExtension (track.FileName).Substring (1);
                } else {
                    track = GetTrackFromFile (hit.Uri.LocalPath);
                }

                if (track != null && track.Title != null && track.Title != String.Empty) {
                    db.AddTrack (track);
                    trackHash[track.FileName] = track;
                }
            }
        }
コード例 #5
0
ファイル: Database.cs プロジェクト: mono/daap-sharp
 public TrackArgs(Track track)
 {
     this.track = track;
 }
コード例 #6
0
ファイル: Database.cs プロジェクト: mono/daap-sharp
 public Stream StreamTrack(Track track, long offset, out long length)
 {
     HttpWebResponse response = FetchTrack (track, offset);
     length = response.ContentLength;
     return response.GetResponseStream ();
 }
コード例 #7
0
ファイル: Database.cs プロジェクト: mono/daap-sharp
        public void RemoveTrack(Track track)
        {
            tracks.Remove (track);
            basePlaylist.RemoveTrack (track);

            foreach (Playlist pl in playlists) {
                pl.RemoveTrack (track);
            }

            if (TrackRemoved != null)
                TrackRemoved (this, new TrackArgs (track));
        }
コード例 #8
0
ファイル: Database.cs プロジェクト: mono/daap-sharp
        public void AddTrack(Track track)
        {
            if (track.Id == 0)
                track.SetId (nextTrackId++);

            tracks.Add (track);
            basePlaylist.AddTrack (track);

            if (TrackAdded != null)
                TrackAdded (this, new TrackArgs (track));
        }
コード例 #9
0
ファイル: BansheePlugin.cs プロジェクト: snorp/tangerine
        private void RefreshTracks()
        {
            if (!OpenConnection ())
                return;

            IDbCommand cmd = conn.CreateCommand ();
            cmd.CommandText = "SELECT TrackID, Uri, Artist, AlbumTitle, ReleaseDate, Title, Genre, Year, " +
                "TrackNumber, TrackCount, Duration FROM Tracks";

            List<int> ids = new List<int> ();

            IDataReader reader = cmd.ExecuteReader ();
            int count = 0;

            while (reader.Read ()) {
                int id = (int) reader[0];
                ids.Add (id);

                if (tracks.ContainsKey (id))
                    continue;

                Uri uri = new Uri ((string) reader[1]);
                if (!uri.IsFile)
                    continue;

                Track track = new Track ();
                track.FileName = uri.LocalPath;
                track.Artist = (string) reader[2];
                track.Album = (string) reader[3];
                track.Title = (string) reader[5];
                track.Genre = (string) reader[6];
                track.Year = (int) reader[7];
                track.TrackNumber = (int) reader[8];
                track.TrackCount = (int) reader[9];
                track.Duration = TimeSpan.FromSeconds ((int) reader[10]);
                track.Format = Path.GetExtension (track.FileName).Substring (1);

                Daemon.DefaultDatabase.AddTrack (track);
                tracks[id] = track;
                count++;
            }

            reader.Close ();

            Daemon.Log.DebugFormat ("Added {0} tracks", count);
            count = 0;

            foreach (int id in new List<int> (tracks.Keys)) {
                if (!ids.Contains (id)) {
                    Daemon.DefaultDatabase.RemoveTrack (tracks[id]);
                    tracks.Remove (id);
                    count++;
                }
            }

            Daemon.Log.DebugFormat ("Removed {0} tracks", count);
        }
コード例 #10
0
ファイル: RhythmboxPlugin.cs プロジェクト: snorp/tangerine
        private void RefreshTracks()
        {
            ClearTracks ();

            if (!File.Exists (dbpath)) {
                return;
            }

            XmlTextReader reader = new XmlTextReader (dbpath);
            Track track = null;

            int count = 0;
            while (reader.Read ()) {
                switch (reader.LocalName) {
                case "entry":
                    if (reader.NodeType == XmlNodeType.EndElement && track != null && track.FileName != null) {
                        Daemon.DefaultDatabase.AddTrack (track);
                        tracks[track.FileName] = track;
                        count++;
                    } else if (reader.NodeType == XmlNodeType.Element) {
                        track = new Track ();
                    }
                    break;
                case "title":
                    track.Title = reader.ReadString ();
                    break;
                case "genre":
                    track.Genre = reader.ReadString ();
                    break;
                case "artist":
                    track.Artist = reader.ReadString ();
                    break;
                case "album":
                    track.Album = reader.ReadString ();
                    break;
                case "track-number":
                    track.TrackNumber = Int32.Parse (reader.ReadString ());
                    break;
                case "duration":
                    track.Duration = TimeSpan.FromSeconds (Int32.Parse (reader.ReadString ()));
                    break;
                case "location":
                    Uri uri = new Uri (reader.ReadString ());
                    if (uri.IsFile) {
                        track.FileName = uri.LocalPath;
                    }
                    break;
                case "bitrate":
                    track.BitRate = Int16.Parse (reader.ReadString ());
                    break;
                default:
                    break;
                }
            }

            reader.Close ();

            Daemon.Log.DebugFormat ("Added {0} tracks", count);
        }
コード例 #11
0
ファイル: GooglePlugin.cs プロジェクト: snorp/tangerine
        private void AddTrack(IGoogleDesktopQueryResultItem item)
        {
            Uri uri = new Uri ((string) item.GetProperty ("uri"));

            string artist = (string) GetResultProperty (item, "artist");
            string title = (string) GetResultProperty (item, "title");
            string album = (string) GetResultProperty (item, "album_title");

            ulong duration = 0;
            object o = GetResultProperty (item, "length");
            if (o != null)
                duration = (ulong) o;

            uint bitrate = 0;
            o = GetResultProperty (item, "bit_rate");
            if (o != null)
                bitrate = (uint) o;

            string genre = (string) GetResultProperty (item, "genre");

            uint trackNum = 0;
            o = GetResultProperty (item, "track_number");
            if (o != null)
                trackNum = (uint) o;

            if (artist == null || title == null)
                return;

            Track track = new Track ();
            track.Artist = artist;
            track.Album = album;
            track.Title = title;
            track.FileName = uri.LocalPath;
            track.Duration = TimeSpan.FromMilliseconds ((double) duration / (double) 10000);
            track.BitRate = (short) bitrate;
            track.Genre = genre;
            track.TrackNumber = (int) trackNum;

            Daemon.DefaultDatabase.AddTrack (track);
        }
コード例 #12
0
ファイル: Playlist.cs プロジェクト: mono/daap-sharp
        internal void InsertTrack(int index, Track track, int id)
        {
            tracks.Insert (index, track);
            containerIds.Insert (index, id);

            if (TrackAdded != null)
                TrackAdded (this, index, track);
        }
コード例 #13
0
ファイル: Playlist.cs プロジェクト: mono/daap-sharp
        internal void AddTrack(Track track, int id)
        {
            tracks.Add (track);
            containerIds.Add (id);

            if (TrackAdded != null)
                TrackAdded (this, tracks.Count - 1, track);
        }
コード例 #14
0
ファイル: Playlist.cs プロジェクト: mono/daap-sharp
        public bool RemoveTrack(Track track)
        {
            int index;
            bool ret = false;

            while ((index = IndexOf (track)) >= 0) {
                ret = true;
                RemoveAt (index);
            }

            return ret;
        }
コード例 #15
0
ファイル: Playlist.cs プロジェクト: mono/daap-sharp
 public void InsertTrack(int index, Track track)
 {
     InsertTrack (index, track, tracks.Count + 1);
 }
コード例 #16
0
ファイル: Playlist.cs プロジェクト: mono/daap-sharp
 public int IndexOf(Track track)
 {
     return tracks.IndexOf (track);
 }
コード例 #17
0
ファイル: SpotlightPlugin.cs プロジェクト: snorp/tangerine
        private void OnSpotlightCallback(IntPtr item)
        {
            if (item == IntPtr.Zero) {
                // that's all for now, commit the changes

                foreach (string key in tracks.Keys) {
                    if (!updatedTracks.ContainsKey (key)) {
                        lock (Daemon.DefaultDatabase) {
                            Daemon.DefaultDatabase.RemoveTrack (tracks[key]);
                        }
                    }
                }

                if (updatedTracks.Values.Count == tracks.Values.Count) {
                    updatedTracks.Clear ();
                    return;
                }

                Daemon.Log.DebugFormat ("Committing {0} total tracks", updatedTracks.Count);

                tracks = updatedTracks;
                updatedTracks = new Dictionary<string, Track> ();

                // that's all for now
                lock (Daemon.Server) {
                    Daemon.Server.Commit ();
                }

                return;
            }

            string path = tangerine_item_get_path (item);
            if (path == null || path == String.Empty) {
                return;
            }

            Track track;
            if (tracks.ContainsKey (path)) {
                track = tracks[path];
            } else {
                track = new Track ();

                track.FileName = path;
                track.Title = tangerine_item_get_title (item);
                track.Album = tangerine_item_get_album (item);
                track.Artist = tangerine_item_get_artist (item);
                track.Duration = TimeSpan.FromSeconds (tangerine_item_get_duration(item));
                track.BitRate = tangerine_item_get_bitrate (item);

                lock (Daemon.DefaultDatabase) {
                    Daemon.DefaultDatabase.AddTrack (track);
                }
            }

            updatedTracks[path] = track;
        }
コード例 #18
0
ファイル: Track.cs プロジェクト: mono/daap-sharp
        public object Clone()
        {
            Track track = new Track ();
            track.artist = artist;
            track.album = album;
            track.title = title;
            track.year = year;
            track.format = format;
            track.duration = duration;
            track.id = id;
            track.size = size;
            track.genre = genre;
            track.trackNumber = trackNumber;
            track.trackCount = trackCount;
            track.fileName = fileName;
            track.dateAdded = dateAdded;
            track.dateModified = dateModified;
            track.bitrate = bitrate;

            return track;
        }
コード例 #19
0
ファイル: AmarokPlugin.cs プロジェクト: snorp/tangerine
        private void RefreshTracks()
        {
            if (!OpenConnection ()) {
                return;
            }

            Dictionary<int, string> albums = FetchStrings ("album");
            Dictionary<int, string> artists = FetchStrings ("artist");
            Dictionary<int, string> genres = FetchStrings ("genre");
            Dictionary<int, string> years = FetchStrings ("year");

            IDbCommand cmd = conn.CreateCommand ();
            cmd.CommandText = "SELECT url, album, artist, genre, title, year, track, bitrate, length FROM tags";

            List<string> paths = new List<string> ();

            IDataReader reader = cmd.ExecuteReader ();
            int count = 0;

            while (reader.Read ()) {
                string path = (string) reader[0];
                if (path.StartsWith (".")) {
                    path = path.Substring (1);
                }

                paths.Add (path);

                if (tracks.ContainsKey (path))
                    continue;

                Track track = new Track ();
                track.FileName = path;
                track.Artist = artists[(int) reader[2]];
                track.Album = albums[(int) reader[1]];
                track.Title = (string) reader[4];
                track.Genre = genres[(int) reader[3]];
                track.Year = Int32.Parse (years[(int) reader[5]]);
                track.TrackNumber = Convert.ToInt32 ((long) reader[6]);
                track.BitRate = Convert.ToInt16 ((int) reader[7]);
                track.Duration = TimeSpan.FromSeconds ((int) reader[8]);

                Daemon.DefaultDatabase.AddTrack (track);
                tracks[path] = track;
                count++;
            }

            reader.Close ();

            Daemon.Log.DebugFormat ("Added {0} tracks", count);
            count = 0;

            foreach (string path in new List<string> (tracks.Keys)) {
                if (!paths.Contains (path)) {
                    Daemon.DefaultDatabase.RemoveTrack (tracks[path]);
                    tracks.Remove (path);
                    count++;
                }
            }

            Daemon.Log.DebugFormat ("Removed {0} tracks", count);
        }
コード例 #20
0
ファイル: Track.cs プロジェクト: mono/daap-sharp
        internal static Track FromNode(ContentNode node)
        {
            Track track = new Track ();

            foreach (ContentNode field in (ContentNode[]) node.Value) {
                switch (field.Name) {
                case "dmap.itemid":
                    track.id = (int) field.Value;
                    break;
                case "daap.songartist":
                    track.artist = (string) field.Value;
                    break;
                case "dmap.itemname":
                    track.title = (string) field.Value;
                    break;
                case "daap.songalbum":
                    track.album = (string) field.Value;
                    break;
                case "daap.songtime":
                    track.duration = TimeSpan.FromMilliseconds ((int) field.Value);
                    break;
                case "daap.songformat":
                    track.format = (string) field.Value;
                    break;
                case "daap.songgenre":
                    track.genre = (string) field.Value;
                    break;
                case "daap.songsize":
                    track.size = (int) field.Value;
                    break;
                case "daap.songtrackcount":
                    track.trackCount = (short) field.Value;
                    break;
                case "daap.songtracknumber":
                    track.trackNumber = (short) field.Value;
                    break;
                case "daap.bitrate":
                    track.bitrate = (short) field.Value;
                    break;
                case "daap.songdateadded":
                    track.dateAdded = (DateTime) field.Value;
                    break;
                case "daap.songdatemodified":
                    track.dateModified = (DateTime) field.Value;
                    break;
                default:
                    break;
                }
            }

            return track;
        }
コード例 #21
0
ファイル: Database.cs プロジェクト: mono/daap-sharp
        public void DownloadTrack(Track track, string dest)
        {
            BinaryWriter writer = new BinaryWriter (File.Open (dest, FileMode.Create));

            try {
                long len;
                using (BinaryReader reader = new BinaryReader (StreamTrack (track, out len))) {
                    int count = 0;
                    byte[] buf = new byte[ChunkLength];

                    do {
                        count = reader.Read (buf, 0, ChunkLength);
                        writer.Write (buf, 0, count);
                    } while (count != 0);
                }
            } finally {
                writer.Close ();
            }
        }
コード例 #22
0
ファイル: Track.cs プロジェクト: mono/daap-sharp
        internal static void FromPlaylistNode(Database db, ContentNode node, out Track track, out int containerId)
        {
            track = null;
            containerId = 0;

            foreach (ContentNode field in (ContentNode[]) node.Value) {
                switch (field.Name) {
                case "dmap.itemid":
                    track = db.LookupTrackById ((int) field.Value);
                    break;
                case "dmap.containeritemid":
                    containerId = (int) field.Value;
                    break;
                default:
                    break;
                }
            }
        }
コード例 #23
0
ファイル: Database.cs プロジェクト: mono/daap-sharp
 public Stream StreamTrack(Track track, out long length)
 {
     return StreamTrack (track, -1, out length);
 }
コード例 #24
0
ファイル: Track.cs プロジェクト: mono/daap-sharp
        internal void Update(Track track)
        {
            if (Equals (track))
                return;

            artist = track.Artist;
            album = track.Album;
            title = track.Title;
            year = track.Year;
            format = track.Format;
            duration = track.Duration;
            size = track.Size;
            genre = track.Genre;
            trackNumber = track.TrackNumber;
            trackCount = track.TrackCount;
            dateAdded = track.DateAdded;
            dateModified = track.DateModified;
            bitrate = track.BitRate;

            EmitUpdated ();
        }
コード例 #25
0
ファイル: Database.cs プロジェクト: mono/daap-sharp
 private HttpWebResponse FetchTrack(Track track, long offset)
 {
     return client.Fetcher.FetchFile (String.Format ("/databases/{0}/items/{1}.{2}", id, track.Id, track.Format),
                                      offset);
 }
コード例 #26
0
ファイル: Track.cs プロジェクト: mono/daap-sharp
 private bool Equals(Track track)
 {
     return artist == track.Artist &&
         album == track.Album &&
         title == track.Title &&
         year == track.Year &&
         format == track.Format &&
         duration == track.Duration &&
         size == track.Size &&
         genre == track.Genre &&
         trackNumber == track.TrackNumber &&
         trackCount == track.TrackCount &&
         dateAdded == track.DateAdded &&
         dateModified == track.DateModified &&
         bitrate == track.BitRate;
 }
コード例 #27
0
ファイル: BeaglePlugin.cs プロジェクト: snorp/tangerine
 private Track GetTrackFromFile(string file)
 {
     try {
         Track track = new Track ();
         FilePlugin.UpdateTrack (track, file);
         return track;
     } catch {
         return null;
     }
 }
コード例 #28
0
ファイル: Server.cs プロジェクト: mono/daap-sharp
 public TrackRequestedArgs(string user, IPAddress host, Database db, Track track)
 {
     this.user = user;
     this.host = host;
     this.db = db;
     this.track = track;
 }
コード例 #29
0
ファイル: LsongsPlugin.cs プロジェクト: snorp/tangerine
        private void RefreshTracks()
        {
            ClearTracks ();

            if (!File.Exists (dbpath)) {
                return;
            }

            XmlTextReader reader = new XmlTextReader (dbpath);
            reader.WhitespaceHandling = WhitespaceHandling.None;

            int found_tracks = 0;
            int found_id = 0;
            int count = 0;

            Track track = new Track ();

            while (reader.Read()){
              if (found_tracks == 0){
            if (reader.LocalName == "key"){
              if (reader.ReadString() == "Tracks"){
            found_tracks = 1;
            continue;
              }
              else{
            continue;
              }
            }
            else{
              continue;
            }
              }

              if (reader.LocalName == "key") {
            if (found_id == 0){
              found_id = 1;
              continue;
            }
            else{
              string value = reader.ReadString();
              switch (value){
              case "Album":
            reader.Read();
            track.Album = reader.ReadString();
            break;
              case "Track Number":
            reader.Read();
            track.TrackNumber = Int32.Parse(reader.ReadString());
            break;
              case "Location":
            reader.Read();
                    track.FileName = reader.ReadString();
            break;
              case "Name":
            reader.Read();
            track.Title = reader.ReadString();
            break;
              case "Artist":
            reader.Read();
            track.Artist = reader.ReadString();
            break;
              case "Total Time":
            reader.Read();
            track.Duration = TimeSpan.FromMilliseconds(Int32.Parse(reader.ReadString()));
            break;
              default:
            break;
              }
            }
              }
              else if(reader.LocalName == "dict" && reader.NodeType == XmlNodeType.EndElement){
            found_id = 0;
            if (track.FileName != null){
              Daemon.DefaultDatabase.AddTrack (track);
              tracks[track.FileName] = track;
            }
                track = new Track ();
            count++;
            continue;
              }
              else{
            continue;
              }
            }
            reader.Close ();
        }
コード例 #30
0
ファイル: IPodPlugin.cs プロジェクト: snorp/tangerine
        private Track AddTrack(IPod.Track itrack)
        {
            if (LookupTrack (itrack) != null)
                return null;

            Track track = new Track ();
            db.AddTrack (track);

            track.Artist = itrack.Artist;
            track.Album = itrack.Album;
            track.Title = itrack.Title;
            track.Duration = itrack.Duration;
            track.FileName = itrack.FileName;
            track.Format = Path.GetExtension (itrack.FileName).Substring (1);
            track.Genre = itrack.Genre;

            FileInfo info = new FileInfo (itrack.FileName);
            track.Size = (int) info.Length;
            track.TrackCount = itrack.TotalTracks;
            track.TrackNumber = itrack.TrackNumber;
            track.Year = itrack.Year;
            track.BitRate = (short) itrack.BitRate;

            return track;
        }