示例#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);
        }
示例#2
0
 public RadioTrackInfo(TrackInfo parentTrack)
     : this(parentTrack.Uri)
 {
     ArtistName = parentTrack.ArtistName;
     TrackTitle = parentTrack.TrackTitle;
     AlbumTitle = parentTrack.AlbumTitle;
     ParentTrack = parentTrack;
 }
 public bool IsInCache(TrackInfo track)
 {
     if (track == null) {
         return false;
     }
     string filename = GetLyricsFilename (track.ArtistName, track.TrackTitle);
     return  File.Exists (filename);
 }
 public TranscodeContext (TrackInfo track, SafeUri out_uri, ProfileConfiguration config,
     TrackTranscodedHandler handler, TranscodeCancelledHandler cancelledHandler, TranscodeErrorHandler errorHandler)
 {
     Track = track;
     OutUri = out_uri;
     Config = config;
     Handler = handler;
     CancelledHandler = cancelledHandler;
     ErrorHandler = errorHandler;
 }
示例#5
0
        public IpodTrackInfo (TrackInfo track)
        {
            CanSaveToDatabase = true;

            if (track is IpodTrackInfo) {
                this.track = ((IpodTrackInfo)track).IpodTrack;
                LoadFromIpodTrack ();
            } else {
                UpdateInfo (track);
            }
        }
示例#6
0
        public AppleDeviceTrackInfo (TrackInfo track)
        {
            CanSaveToDatabase = true;

            if (track is AppleDeviceTrackInfo) {
                IpodTrack = ((AppleDeviceTrackInfo)track).IpodTrack;
                LoadFromIpodTrack ();
            } else {
                UpdateInfo (track);
            }
        }
        protected override int GetIconIndex(TrackInfo track)
        {
            ContactTrackInfo ci = ContactTrackInfo.From (track);
            if (track == null || ci == null) {
                return -1;
            }

            if (ci.IsDownloading || ci.IsDownloadPending) {
                return base.PixbufCount + 0;
            }
            else {
                return -1;
            }
        }
 public void ProcessEvent(PlayerEventArgs args, TrackInfo track, uint pos, uint len)
 {
     switch(args.Event) {
     case PlayerEvent.StateChange:
         StateChange((PlayerEventStateChangeArgs)args, track, pos, len);
         break;
     case PlayerEvent.TrackInfoUpdated:
         UpdateTrack(track, pos, len);
         break;
     case PlayerEvent.Iterate:
         UpdatePosition(pos, len);
         break;
     }
 }
示例#9
0
        public void UpdateInfo (TrackInfo track)
        {
            if (track is AppleDeviceTrackInfo) {
                throw new ArgumentException ("Shouldn't update an AppleDeviceTrackInfo from an AppleDeviceTrackInfo");
            }

            IsCompilation = track.IsCompilation ;
            AlbumArtist = track.AlbumArtist;
            AlbumTitle = track.AlbumTitle;
            ArtistName = track.ArtistName;
            BitRate = track.BitRate;
            SampleRate = track.SampleRate;
            Bpm = track.Bpm;
            Comment = track.Comment;
            Composer = track.Composer;
            Conductor = track.Conductor;
            Copyright = track.Copyright;
            DateAdded = track.DateAdded;
            DiscCount = track.DiscCount;
            DiscNumber = track.DiscNumber;
            Duration = track.Duration;
            FileSize = track.FileSize;
            Genre = track.Genre;
            Grouping = track.Grouping;
            LastPlayed = track.LastPlayed;
            LastSkipped = track.LastSkipped;
            PlayCount = track.PlayCount;
            Rating = track.Rating;
            ReleaseDate = track.ReleaseDate;
            SkipCount = track.SkipCount;
            TrackCount = track.TrackCount;
            TrackNumber = track.TrackNumber;
            TrackTitle = track.TrackTitle;
            Year = track.Year;
            MediaAttributes = track.MediaAttributes;

            ArtistNameSort = track.ArtistNameSort;
            AlbumTitleSort = track.AlbumTitleSort;
            AlbumArtistSort = track.AlbumArtistSort;
            TrackTitleSort = track.TrackTitleSort;

            var podcast_info = track.ExternalObject as IPodcastInfo;
            if (podcast_info != null) {
                description = podcast_info.Description;
                ReleaseDate = podcast_info.ReleaseDate;
            }

            mimetype = track.MimeType;
        }
        protected override int GetIconIndex (TrackInfo track)
        {
            PodcastTrackInfo podcast = PodcastTrackInfo.From (track);
            if (track == null) {
                return -1;
            }

            switch (podcast.Activity) {
                case PodcastItemActivity.Downloading:
                case PodcastItemActivity.DownloadPending:
                    return base.PixbufCount + 0;
                default:
                    return podcast.IsDownloaded ? base.PixbufCount + 1 : -1;
            }
        }
示例#11
0
        public Metadata(TrackInfo track)
        {
            data_store = new Dictionary<string, object> ();

            if (track == null) {
                // Managed dbus doesn't like null or empty dictionaries
                data_store["mpris:trackid"] = String.Concat (object_path, "Empty");
                return;
            }

            // The trackid must be formatted like a dbus object path
            data_store["mpris:trackid"] = new DBus.ObjectPath (String.Concat (object_path, track.CacheModelId, track.CacheEntryId));
            SetInfo ("mpris:length", (long)track.Duration.TotalMilliseconds * 1000);
            SetInfo ("xesam:url", track.Uri.ToString ());
            SetInfo ("xesam:title", track.TrackTitle);
            SetInfo ("xesam:album", track.AlbumTitle);
            if (!String.IsNullOrEmpty (track.ArtistName)) {
                SetInfo ("xesam:artist", new string [] {track.ArtistName});
            }
            if (!String.IsNullOrEmpty (track.AlbumArtist)) {
                SetInfo ("xesam:albumArtist", new string [] {track.AlbumArtist});
            }
            if (!String.IsNullOrEmpty (track.Genre)) {
                SetInfo ("xesam:genre", new string [] {track.Genre});
            }
            if (!String.IsNullOrEmpty (track.Comment)) {
                SetInfo ("xesam:comment", new string [] {track.Comment});
            }

            if (track.TrackNumber > 0) {
                data_store["xesam:trackNumber"] = track.TrackNumber;
            }

            if (track.ReleaseDate.Ticks > 0) {
                SetInfo ("xesam:contentCreated", track.ReleaseDate.ToString ("s"));
            }

            if (track.Rating > 0) {
                // Scale is 0.0 to 1.0
                SetInfo ("xesam:userRating", (double)track.Rating / 5);
            }

            string artid = track.ArtworkId;
            if (artid != null) {
                SetInfo ("mpris:artUrl", String.Concat ("file://", CoverArtSpec.GetPath (artid)));
            }
        }
        public AppleDeviceTrackInfo (TrackInfo track)
        {
            if (track is AppleDeviceTrackInfo) {
                IpodTrack = ((AppleDeviceTrackInfo)track).IpodTrack;
                LoadFromIpodTrack ();
            } else {
                IsCompilation = track.IsCompilation ;
                AlbumArtist = track.AlbumArtist;
                AlbumTitle = track.AlbumTitle;
                ArtistName = track.ArtistName;
                BitRate = track.BitRate;
                SampleRate = track.SampleRate;
                Bpm = track.Bpm;
                Comment = track.Comment;
                Composer = track.Composer;
                Conductor = track.Conductor;
                Copyright = track.Copyright;
                DateAdded = track.DateAdded;
                DiscCount = track.DiscCount;
                DiscNumber = track.DiscNumber;
                Duration = track.Duration;
                FileSize = track.FileSize;
                Genre = track.Genre;
                Grouping = track.Grouping;
                LastPlayed = track.LastPlayed;
                LastSkipped = track.LastSkipped;
                PlayCount = track.PlayCount;
                Rating = track.Rating;
                ReleaseDate = track.ReleaseDate;
                SkipCount = track.SkipCount;
                TrackCount = track.TrackCount;
                TrackNumber = track.TrackNumber;
                TrackTitle = track.TrackTitle;
                Year = track.Year;
                MediaAttributes = track.MediaAttributes;

                var podcast_info = track.ExternalObject as IPodcastInfo;
                if (podcast_info != null) {
                    //description = podcast_info.Description;
                    ReleaseDate = podcast_info.ReleaseDate;
                }
            }

            CanSaveToDatabase = true;
        }
        protected override int GetIconIndex (TrackInfo track)
        {
            int i = -1;
            PodcastTrackInfo podcast = PodcastTrackInfo.From (track);
            if (track != null) {
                switch (podcast.Activity) {
                    case PodcastItemActivity.Downloading:
                    case PodcastItemActivity.DownloadPending:
                        i = base.PixbufCount + 0;
                        break;
                    default:
                        i = podcast.IsDownloaded ? base.PixbufCount + 1 : -1;
                        break;
                }
            }

            return i;
        }
示例#14
0
            public QueuedTrack (TrackInfo track, DateTime start_time)
            {
                this.artist = track.ArtistName;
                this.album = track.AlbumTitle;
                this.title = track.TrackTitle;
                this.track_number = (int) track.TrackNumber;
                this.duration = (int) track.Duration.TotalSeconds;
                // Idealy would use Hyena's DateTimeUtil, but it is broken since the "unix epoch" it uses is
                // not UTC, so depending on whether jan 1 1970 was in day-light savings and whether the user's
                // current timezone is in DLS, we'll be an hour off.
                this.start_time = (long) (start_time.ToUniversalTime () - epoch).TotalSeconds;
                // TODO
                //this.musicbrainzid = track.MusicBrainzId;

                this.musicbrainzid = "";

                // set trackauth value, otherwise empty string is default
                if (track is ILastfmInfo) {
                    this.track_auth = (track as ILastfmInfo).TrackAuth;
                }
            }
示例#15
0
        public void Merge (TrackInfo track)
        {
            AddTag (CommonTags.Artist, track.ArtistName);
            AddTag (CommonTags.Album, track.AlbumTitle);
            AddTag (CommonTags.Title, track.TrackTitle);
            AddTag (CommonTags.Genre, track.Genre);

            AddTag (CommonTags.TrackNumber, (uint)track.TrackNumber);
            AddTag (CommonTags.TrackCount, (uint)track.TrackCount);
            AddTag (CommonTags.AlbumDiscNumber, (uint)track.DiscNumber);
            AddTag (CommonTags.AlbumDiscCount, (uint)track.DiscCount);

            AddYear (track.Year);
            AddDate (track.ReleaseDate);

            AddTag (CommonTags.Composer, track.Composer);
            AddTag (CommonTags.Copyright, track.Copyright);
            AddTag (CommonTags.Comment, track.Comment);

            AddTag (CommonTags.MusicBrainzTrackId, track.MusicBrainzId);
            AddTag (CommonTags.MusicBrainzArtistId, track.ArtistMusicBrainzId);
            AddTag (CommonTags.MusicBrainzAlbumId, track.AlbumMusicBrainzId);

        }
示例#16
0
 private bool LyricOutOfDate (TrackInfo track)
 {
     if (ServiceManager.PlayerEngine == null || ServiceManager.PlayerEngine.CurrentTrack == null) {
         return true;
     }
     string current_artist = ServiceManager.PlayerEngine.CurrentTrack.ArtistName;
     string current_title = ServiceManager.PlayerEngine.CurrentTrack.TrackTitle;
     return track.ArtistName != current_artist || track.TrackTitle != current_title;
 }
示例#17
0
        private string GetSuggestions (TrackInfo track)
        {
            string suggestions = null;
            foreach (var source in GetSources (SourceData.SuggestionsSelector)) {
                bool found = false;
                try {
                    suggestions = source.Source.GetSuggestions (track.ArtistName, track.TrackTitle);
                    found = !String.IsNullOrEmpty (suggestions);
                } catch (Exception e) {
                    Log.Exception (e);
                    continue;
                } finally {
                    source.IncrementSuggestions (found);
                }

                if (found) {
                    Log.DebugFormat ("Fetched suggestions from {0} for {1} - {2}",
                        source.Source.Name, track.ArtistName, track.TrackTitle);
                    return suggestions;
                }
            }
            Log.DebugFormat ("Couldn't find any suggestions for {0} - {1}", track.ArtistName, track.TrackTitle);
            return null;
        }
示例#18
0
 public void UpdateDB (TrackInfo track, string lyrics)
 {
     int track_id = ServiceManager.SourceManager.MusicLibrary.GetTrackIdForUri (track.Uri.AbsoluteUri);
     ServiceManager.DbConnection.Execute (
                 "INSERT OR REPLACE INTO LyricsDownloads (TrackID, Downloaded) VALUES (?, ?)",
                 track_id, IsLyricsOk(lyrics));
 }
示例#19
0
        public string DownloadLyrics (TrackInfo track)
        {
            if (track == null) {
                return null;
            }

            //check if the network is up
            if (!ServiceManager.Get<Banshee.Networking.Network> ().Connected) {
                throw new NetworkUnavailableException ("You don't seem to be connected to internet. Check your network connection.");
            }

            //download the lyrics
            string lyrics = null;
            foreach (var source in GetSources (SourceData.LyricsSelector)) {
                bool found = false;
                try {
                    lyrics = source.Source.GetLyrics (track.ArtistName, track.TrackTitle);
                    found = IsLyricsOk (lyrics);
                } catch (Exception e) {
                    Log.Exception (e);
                    continue;
                } finally {
                    source.IncrementLyrics (found);
                }

                if (found) {
                    lyrics = AttachFooter (Utils.ToNormalString(lyrics), source.Source.Credits);
                    Log.DebugFormat ("Fetched lyrics from {0} for {1} - {2}",
                        source.Source.Name, track.ArtistName, track.TrackTitle);
                    return lyrics;
                }
            }

            Log.DebugFormat ("Couldn't find lyrics for {0} - {1}", track.ArtistName, track.TrackTitle);
            return null;
        }
示例#20
0
        void OnSocketReceive(IAsyncResult ar)
        {
            Socket client = (Socket)ar.AsyncState;
            //client.SendBufferSize=10000000;
            int bytes = client.EndReceive(ar);

            client.BeginReceive(socketBuffer, 0, socketBuffer.Length, SocketFlags.None, OnSocketReceive, client);
            //IPAddress ipAd = IPAddress.Parse("127.0.0.1");
            //	myList=new TcpListener(IPAddress.Any,port);
            //	listenThread = new Thread(new ThreadStart(startListening));
            //	listenThread.Start();
            //}
            //private void startListening(){
            //if(myList!=null)
            //myList.Start();


            //Console.WriteLine("BansheRemoteListener will listen on port " + port.ToString());
            //while(true){
            //if(myList!=null)
            //client=myList.AcceptSocket();
            //client.Receive(socketBuffer,socketBuffer.Length,SocketFlags.None);
            string text = Encoding.UTF8.GetString(socketBuffer, 0, bytes);
            string sep  = "/";

            string[] remoteMessage = text.Split('/');
            string   action        = remoteMessage[0];
            string   variable      = remoteMessage[1];

            if (action.Equals("play"))
            {
                variable = variable.Replace('*', '/');
            }
            //Console.WriteLine("BansheeRemoteListener: " + action+ " " + variable);
            Banshee.Collection.TrackInfo currTrack = ServiceManager.PlayerEngine.CurrentTrack;
            string replyText = "";
            ushort currVol;
            ushort volStep   = 10;
            bool   replyReq  = false;
            string home      = Environment.GetEnvironmentVariable("HOME");
            string coverPath = "";

            //string dbPath=home+"/.config/banshee-1/banshee.db";
            if (currTrack != null && currTrack.ArtworkId != null)
            {
                coverPath = home + "/.cache/media-art/" + currTrack.ArtworkId.ToString() + ".jpg";
            }

            switch (action)
            {
            case "coverImage":                                  /*request*/
                byte[] coverImage = File.ReadAllBytes(coverPath);
                client.Send(coverImage);
                replyReq = true;
                break;

            /*case "syncCount":
             *      int count = System.IO.File.ReadAllBytes(dbPath).Length;
             *      client.Send(System.Text.Encoding.UTF8.GetBytes(count.ToString()));
             *      replyReq=true;
             *      break;*/

            /*case "sync":			//request
             *      //Console.WriteLine("About to Read the File");
             *      byte[] db = File.ReadAllBytes(dbPath);
             *      //String s = Convert.ToString(db[8152063],16).PadLeft(2,'0');
             *      //Console.WriteLine("Byte Read   "+s);
             *      byte[] chunk;
             *      int remainingBytes=db.Length;
             *      int offset=0;
             *      int chunksize = 1024;
             *      //int rep = 0;
             *      //String hash="";// = System.Convert.ToBase64String
             *      //int numPieces = (int)Math.Ceiling((double)db.Length/2048);
             *      //Console.WriteLine("Number of bytes "+db.Length);
             *      //client.Send(System.Text.Encoding.UTF8.GetBytes(db.Length.ToString()));
             *      while(remainingBytes>0){
             *              if(remainingBytes>=chunksize){
             *                      chunk = new byte[chunksize];
             *                      Array.Copy(db,offset,chunk,0,chunksize);
             *                      //if(rep==0){
             *                      //	hash = System.Convert.ToBase64String(chunk,0,chunksize);
             *                              //Console.WriteLine("Hash is : "+hash);
             *                              //client.Close();
             *                              //client=myList.AcceptSocket();
             *                              //int bytesT = client.Receive(socketBuffer,socketBuffer.Length,SocketFlags.None);
             *                              //string textT = Encoding.UTF8.GetString(socketBuffer,0,bytesT);
             *                              //client=myList.AcceptSocket();
             *                              //Console.WriteLine("Received Hash is : "+textT);
             *
             *                      //}
             *                      offset+=chunksize;
             *                      remainingBytes=remainingBytes-chunksize;
             *              }
             *              else{
             *                      chunk = new byte[remainingBytes];
             *                      Array.Copy(db,offset,chunk,0,remainingBytes);
             *                      //hash = System.Convert.ToBase64String(chunk,0,chunksize);
             *                      remainingBytes=0;
             *              }
             *              client.Send(chunk);
             *              //rep++;
             *      }
             *      //client.Send(db);
             *      replyReq = true;
             *      break;*/

            /*case "sync":			//request
             *      //Console.WriteLine("About to Read the File");
             *      byte[] db = File.ReadAllBytes(dbPath);
             *      int byteLength = db.Length;
             *      int offset = Convert.ToInt32(variable);
             *      int chunksize = 1024;
             *      byte[] chunk;
             *      //if(offset+chunksize>byteLength){
             *      //	chunk=new byte[byteLength-offset];
             *      //	Array.Copy(db,offset,chunk,0,(byteLength-offset));
             *      //}
             *      //else{
             *              chunk = new byte[chunksize];
             *              Array.Copy(db,0,chunk,0,chunksize);
             *      //}
             *      client.Send(chunk);
             *      Console.WriteLine("Sent from offset "+variable);
             *      //String s = Convert.ToString(db[8152063],16).PadLeft(2,'0');
             *      //Console.WriteLine("Byte Read   "+s);
             *
             *      //int remainingBytes=db.Length;
             *      //int offset=0;
             *      //int chunksize = 1024;
             *      //int rep = 0;
             *      //String hash="";// = System.Convert.ToBase64String
             *      //int numPieces = (int)Math.Ceiling((double)db.Length/2048);
             *      //Console.WriteLine("Number of bytes "+db.Length);
             *      //client.Send(System.Text.Encoding.UTF8.GetBytes(db.Length.ToString()));
             *      //while(remainingBytes>0){
             *      //	if(remainingBytes>=chunksize){
             *      //		chunk = new byte[chunksize];
             *      //		Array.Copy(db,offset,chunk,0,chunksize);
             *                      //if(rep==0){
             *                      //	hash = System.Convert.ToBase64String(chunk,0,chunksize);
             *                              //Console.WriteLine("Hash is : "+hash);
             *                              //client.Close();
             *                              //client=myList.AcceptSocket();
             *                              //int bytesT = client.Receive(socketBuffer,socketBuffer.Length,SocketFlags.None);
             *                              //string textT = Encoding.UTF8.GetString(socketBuffer,0,bytesT);
             *                              //client=myList.AcceptSocket();
             *                              //Console.WriteLine("Received Hash is : "+textT);
             *
             *                      //}
             *      //		offset+=chunksize;
             *      //		remainingBytes=remainingBytes-chunksize;
             *      //	}
             *      //	else{
             *      //		chunk = new byte[remainingBytes];
             *      //		Array.Copy(db,offset,chunk,0,remainingBytes);
             *                      //hash = System.Convert.ToBase64String(chunk,0,chunksize);
             *      //		remainingBytes=0;
             *      //	}
             *              //client.Send(chunk);
             *              //rep++;
             *      //}
             *      //client.Send(db);
             *      replyReq = true;
             *      break;*/

            case "coverExists":                                 /*request*/
                replyText = coverExists(coverPath);
                replyReq  = true;
                break;

            case "playPause":                                   /*command*/
                ServiceManager.PlayerEngine.TogglePlaying();
                replyReq = true;
                break;

            case "next":                                        /*command*/
                ServiceManager.PlaybackController.Next();
                replyReq = true;
                break;

            case "prev":                                        /*command*/
                ServiceManager.PlaybackController.Previous();
                replyReq = true;
                break;

            case "play":
                var source = ServiceManager.SourceManager.ActiveSource as ITrackModelSource;
                if (source != null)
                {
                    var countSongs             = source.Count;
                    UnknownTrackInfo track     = new UnknownTrackInfo(new SafeUri(variable));
                    TrackInfo        trackTemp = null;
                    for (int i = 0; i < countSongs; i++)
                    {
                        trackTemp = source.TrackModel [i];
                        if (trackTemp.TrackEqual(track))
                        {
                            break;
                        }
                    }
                    if (trackTemp != null)
                    {
                        ServiceManager.PlayerEngine.OpenPlay(trackTemp);
                    }
                }
                replyReq = true;
                break;

            case "volumeDown":                                  /*command*/
                currVol = ServiceManager.PlayerEngine.Volume;
                //ServiceManager.PlayerEngine.Open(new SafeUri("hello"));
                if (currVol < 10)
                {
                    ServiceManager.PlayerEngine.Volume = 0;
                }
                else
                {
                    ServiceManager.PlayerEngine.Volume = (ushort)(currVol - volStep);
                }
                replyReq = true;
                break;

            case "volumeUp":                                    /*command*/
                currVol = ServiceManager.PlayerEngine.Volume;
                if (currVol > 90)
                {
                    ServiceManager.PlayerEngine.Volume = 100;
                }
                else
                {
                    ServiceManager.PlayerEngine.Volume = (ushort)(currVol + volStep);
                }
                replyReq = true;
                break;

            case "mute":                                        /*command*/
                currVol = ServiceManager.PlayerEngine.Volume;
                if (currVol > 0)
                {
                    volume = currVol;
                    ServiceManager.PlayerEngine.Volume = 0;
                }
                else
                {
                    ServiceManager.PlayerEngine.Volume = volume;
                }
                replyReq = true;
                break;

            case "status":                                      /*request*/
                replyText = ServiceManager.PlayerEngine.CurrentState.ToString().ToLower();
                Console.WriteLine("Status " + replyText);
                replyReq = true;
                break;

            case "album":                                       /*request*/
                replyText = currTrack.DisplayAlbumTitle;
                replyReq  = true;
                break;

            case "artist":                                      /*request*/
                replyText = currTrack.DisplayArtistName;
                replyReq  = true;
                break;

            case "title":                                       /*request*/
                replyText = currTrack.DisplayTrackTitle;
                replyReq  = true;
                break;

            case "trackCurrentTime":                    /*request*/
                replyText = (ServiceManager.PlayerEngine.Position / 1000).ToString();
                replyReq  = true;
                break;

            case "trackTotalTime":                      /*request*/
                replyText = currTrack.Duration.ToString();
                replyReq  = true;
                break;

            case "seek":                                        /*command*/
                ServiceManager.PlayerEngine.Position = UInt32.Parse(variable) * 1000;
                replyReq = true;
                break;

            case "shuffle":                                     /*command*/ /*request*/
                if (ServiceManager.PlaybackController.ShuffleMode.ToString() == "off")
                {
                    ServiceManager.PlaybackController.ShuffleMode = "song";
                    replyText = "song";
                }
                else if (ServiceManager.PlaybackController.ShuffleMode.ToString() == "song")
                {
                    //ServiceManager.PlaybackController.ShuffleMode = PlaybackShuffleMode.Linear ;
                    ServiceManager.PlaybackController.ShuffleMode = "artist";
                    replyText = "Artist";
                }
                else if (ServiceManager.PlaybackController.ShuffleMode.ToString() == "artist")
                {
                    //ServiceManager.PlaybackController.ShuffleMode = PlaybackShuffleMode.Linear ;
                    ServiceManager.PlaybackController.ShuffleMode = "album";
                    replyText = "Album";
                }
                else if (ServiceManager.PlaybackController.ShuffleMode.ToString() == "album")
                {
                    //ServiceManager.PlaybackController.ShuffleMode = PlaybackShuffleMode.Linear ;
                    ServiceManager.PlaybackController.ShuffleMode = "rating";
                    replyText = "Rating";
                }
                else if (ServiceManager.PlaybackController.ShuffleMode.ToString() == "rating")
                {
                    //ServiceManager.PlaybackController.ShuffleMode = PlaybackShuffleMode.Linear ;
                    ServiceManager.PlaybackController.ShuffleMode = "score";
                    replyText = "Score";
                }
                else
                {
                    ServiceManager.PlaybackController.ShuffleMode = "off";
                    replyText = "off";
                }
                //replyText="off";
                //replyText = ServiceManager.PlaybackController.ShuffleMode.ToString();
                //Console.WriteLine(ServiceManager.PlaybackController.ShuffleMode.ToString());
                replyReq = true;
                break;

            case "repeat":                                      /*command*/ /*request*/
                if (ServiceManager.PlaybackController.RepeatMode == PlaybackRepeatMode.None)
                {
                    ServiceManager.PlaybackController.RepeatMode = PlaybackRepeatMode.RepeatAll;
                    replyText = "all";
                }
                else if (ServiceManager.PlaybackController.RepeatMode == PlaybackRepeatMode.RepeatAll)
                {
                    ServiceManager.PlaybackController.RepeatMode = PlaybackRepeatMode.RepeatSingle;
                    replyText = "single";
                }
                else
                {
                    ServiceManager.PlaybackController.RepeatMode = PlaybackRepeatMode.None;
                    replyText = "off";
                }
                //replyText = ServiceManager.PlaybackController.RepeatMode.ToString();
                //Console.WriteLine(replyText);
                replyReq = true;
                break;

            case "all":                                                 /*request*/
                replyText  = ServiceManager.PlayerEngine.CurrentState.ToString().ToLower() + sep;
                replyText += currTrack.DisplayAlbumTitle.Replace('/', '\\') + sep;
                replyText += currTrack.DisplayArtistName.Replace('/', '\\') + sep;
                replyText += currTrack.DisplayTrackTitle.Replace('/', '\\') + sep;
                replyText += ((uint)(ServiceManager.PlayerEngine.Position / 1000)).ToString() + sep;
                replyText += ((uint)(currTrack.Duration.TotalSeconds)).ToString() + sep;
                replyText += coverExists(coverPath);
                replyReq   = true;
                break;

            case "test":
                replyText = "";
                replyReq  = true;
                break;

            default:
                replyText = "";
                replyReq  = false;
                break;
            }

            byte[] messageByte = System.Text.Encoding.UTF8.GetBytes(replyText);

            if (replyReq)
            {
                reply(client, messageByte);
                //Console.WriteLine(System.Text.Encoding.UTF8.GetString(messageByte));
                //}

                client.Close();
            }
        }
示例#21
0
 private Folder GetFolderForTrack (TrackInfo track)
 {
     if (track.HasAttribute (TrackMediaAttributes.VideoStream)) {
         return mtp_device.VideoFolder;
     } else if (track.HasAttribute (TrackMediaAttributes.Podcast)) {
         return mtp_device.PodcastFolder;
     } else {
         return mtp_device.MusicFolder;
     }
 }
示例#22
0
        private void SaveToID3 (TrackInfo track, string lyrics)
        {
            TagLib.File file = StreamTagger.ProcessUri (track.Uri);
            if (file == null || lyrics.Equals(file.Tag.Lyrics)) {
                return;
            }

            file.Tag.Lyrics = lyrics;
            file.Save ();

            track.FileSize = Banshee.IO.File.GetSize (track.Uri);
            track.FileModifiedStamp = Banshee.IO.File.GetModifiedTime (track.Uri);
            track.LastSyncedStamp = DateTime.Now;
        }
示例#23
0
        private void OnStageIteration(object o, EventArgs args)
        {
            Invalidate ();

            if (stage.Actor != null) {
                last_fps = stage.Actor.FramesPerSecond;
                return;
            }

            InvalidateCache ();

            if (ApplicationContext.Debugging) {
                Log.DebugFormat ("TrackInfoDisplay RenderAnimation: {0:0.00} FPS", last_fps);
            }

            if (current_image != null && current_image != incoming_image && !IsMissingImage (current_image)) {
                ((IDisposable)current_image).Dispose ();
            }

            current_image = incoming_image;
            current_track = incoming_track;

            incoming_track = null;

            OnArtworkChanged ();
        }
示例#24
0
        private void LoadImage(TrackInfo track, bool force)
        {
            LoadImage (track.MediaAttributes, track.ArtworkId, force);

            if (track == current_track) {
                if (current_image != null && current_image != incoming_image && !IsMissingImage (current_image)) {
                    ((IDisposable)current_image).Dispose ();
                }
                current_image = incoming_image;
            }
        }
示例#25
0
        public void SaveLyrics (TrackInfo track, string lyrics, bool rewrite)
        {
            if (!IsLyricsOk (lyrics)) {
                /*update the db always */
                LyricsManager.Instance.UpdateDB (track, lyrics);
                return;
            }

            ThreadAssist.SpawnFromMain (delegate {
                if (rewrite) {
                    cache.DeleteLyrics (track);
                }
                Save (track, lyrics);
                LyricsManager.Instance.UpdateDB (track, lyrics);
            });
        }
示例#26
0
 private void RenderStage(Cairo.Context cr, TrackInfo track, ImageSurface image)
 {
     RenderCoverArt (cr, image);
     RenderTrackInfo (cr, track, true, true);
 }
示例#27
0
        private void Save (TrackInfo track, string lyrics)
        {
            if (Utils.IsHtml (lyrics)) {
                lyrics = Utils.ToNormalString (lyrics);
            }

            if (!cache.IsInCache (track)) {
                cache.WriteLyrics (track, lyrics);
            }

            if (Banshee.Configuration.Schema.LibrarySchema.WriteMetadata.Get ()) {
                SaveToID3 (track, lyrics);
            }
        }
示例#28
0
        private void OnPlayerEvent(PlayerEventArgs args)
        {
            switch (args.Event) {
                case PlayerEvent.StartOfStream:
                case PlayerEvent.TrackInfoUpdated:
                    current_track = ServiceManager.PlayerEngine.CurrentTrack;
                    ToggleRatingMenuSensitive ();
                    ShowTrackNotification ();
                    break;
                case PlayerEvent.StateChange:
                    UpdateActions ();
                    break;
                case PlayerEvent.EndOfStream:
                    current_track = null;
                    ToggleRatingMenuSensitive ();
                    break;
            }

            if (notif_area != null) {
                notif_area.OnPlayerEvent (args);
            }
        }
示例#29
0
  /*
  * Refresh the lyrics for the current track
  */
 public void RefreshLyrics (TrackInfo track)
 {
     cache.DeleteLyrics (track);
     FetchLyrics (track);
 }
示例#30
0
        /*
         * Get the lyrics for the current track
         */
        public void FetchLyrics (TrackInfo track)
        {
            string lyrics = null;
            string error = null;
            string suggestion = null;

            LoadStarted (null, null);

            ThreadAssist.SpawnFromMain (delegate {
                try {
                    if (cache.IsInCache (track)) {
                        lyrics = cache.ReadLyrics (track);
                    } else {
                        lyrics = DownloadLyrics (track);
                    }

                    if (IsLyricsOk (lyrics)) {
                        Save (track, lyrics);
                    } else {
                        suggestion = GetSuggestions (track);
                    }

                    if (LyricOutOfDate (track)) {
                        return;
                    }
                } catch (Exception e) {
                    Log.DebugException (e);
                    error = e.Message;
                }

                ThreadAssist.ProxyToMain (delegate {
                    LoadFinished (this, new LoadFinishedEventArgs (lyrics, suggestion, error));});
            });
        }
示例#31
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;
 }
        void OnSocketReceive(IAsyncResult ar)
        {
            Socket client = null;
            int    bytes  = 0;

            try
            {
                client = (Socket)ar.AsyncState;
                bytes  = client.EndReceive(ar);

                client.BeginReceive(socketBuffer, 0, socketBuffer.Length, SocketFlags.None, OnSocketReceive, client);


                string   text          = Encoding.UTF8.GetString(socketBuffer, 0, bytes);
                string   sep           = "/";
                string[] remoteMessage = text.Split('/');
                string   action        = remoteMessage[0];
                string   variable      = remoteMessage[1];
                if (action.Equals("play"))
                {
                    variable = variable.Replace('*', '/');
                }

                Banshee.Collection.TrackInfo currTrack = ServiceManager.PlayerEngine.CurrentTrack;
                string replyText = "";
                ushort currVol;
                ushort volStep   = 10;
                bool   replyReq  = false;
                string home      = Environment.GetEnvironmentVariable("HOME");
                string coverPath = "";
                string dbPath    = home + "/.config/banshee-1/banshee.db";
                if (currTrack != null && currTrack.ArtworkId != null)
                {
                    coverPath = home + "/.cache/media-art/" + currTrack.ArtworkId.ToString() + ".jpg";
                }

                switch (action)
                {
                case "coverImage":
                    byte[] coverImage = File.ReadAllBytes(coverPath);
                    client.Send(coverImage);
                    replyReq = true;
                    break;

                case "syncCount":
                    int count = System.IO.File.ReadAllBytes(dbPath).Length;
                    client.Send(System.Text.Encoding.UTF8.GetBytes(count.ToString()));
                    replyReq = true;
                    break;

                case "sync":
                    byte[] db = File.ReadAllBytes(dbPath);
                    client.Send(db);
                    replyReq = true;
                    break;

                case "coverExists":
                    replyText = coverExists(coverPath);
                    replyReq  = true;
                    break;

                case "playPause":
                    ServiceManager.PlayerEngine.TogglePlaying();
                    replyReq = true;
                    break;

                case "next":
                    ServiceManager.PlaybackController.Next();
                    replyReq = true;
                    break;

                case "prev":
                    ServiceManager.PlaybackController.Previous();
                    replyReq = true;
                    break;

                case "play":
                    var source = ServiceManager.SourceManager.MusicLibrary as DatabaseSource;
                    source.FilterQuery = "";
                    if (source != null)
                    {
                        var countSongs = source.Count;

                        UnknownTrackInfo track     = new UnknownTrackInfo(new SafeUri(variable));
                        TrackInfo        trackTemp = null;
                        for (int i = 0; i < countSongs; i++)
                        {
                            trackTemp = source.TrackModel [i];
                            if (trackTemp.TrackEqual(track))
                            {
                                break;
                            }
                        }
                        if (trackTemp != null)
                        {
                            ServiceManager.PlayerEngine.OpenPlay(trackTemp);
                        }
                    }
                    replyReq = true;
                    break;

                case "volumeDown":
                    currVol = ServiceManager.PlayerEngine.Volume;
                    if (currVol < 10)
                    {
                        ServiceManager.PlayerEngine.Volume = 0;
                    }
                    else
                    {
                        ServiceManager.PlayerEngine.Volume = (ushort)(currVol - volStep);
                    }
                    replyReq = true;
                    break;

                case "volumeUp":
                    currVol = ServiceManager.PlayerEngine.Volume;
                    if (currVol > 90)
                    {
                        ServiceManager.PlayerEngine.Volume = 100;
                    }
                    else
                    {
                        ServiceManager.PlayerEngine.Volume = (ushort)(currVol + volStep);
                    }
                    replyReq = true;
                    break;

                case "mute":
                    currVol = ServiceManager.PlayerEngine.Volume;
                    if (currVol > 0)
                    {
                        volume = currVol;
                        ServiceManager.PlayerEngine.Volume = 0;
                    }
                    else
                    {
                        ServiceManager.PlayerEngine.Volume = volume;
                    }
                    replyReq = true;
                    break;

                case "status":
                    replyText = ServiceManager.PlayerEngine.CurrentState.ToString().ToLower();
                    replyReq  = true;
                    break;

                case "album":
                    replyText = currTrack.DisplayAlbumTitle;
                    replyReq  = true;
                    break;

                case "artist":
                    replyText = currTrack.DisplayArtistName;
                    replyReq  = true;
                    break;

                case "title":
                    replyText = currTrack.DisplayTrackTitle;
                    replyReq  = true;
                    break;

                case "trackCurrentTime":
                    replyText = (ServiceManager.PlayerEngine.Position / 1000).ToString();
                    replyReq  = true;
                    break;

                case "trackTotalTime":
                    replyText = currTrack.Duration.ToString();
                    replyReq  = true;
                    break;

                case "seek":
                    ServiceManager.PlayerEngine.Position = UInt32.Parse(variable) * 1000;
                    replyReq = true;
                    break;

                case "shuffle":
                    if (ServiceManager.PlaybackController.ShuffleMode.ToString() == "off")
                    {
                        ServiceManager.PlaybackController.ShuffleMode = "song";
                        replyText = "song";
                    }
                    else if (ServiceManager.PlaybackController.ShuffleMode.ToString() == "song")
                    {
                        ServiceManager.PlaybackController.ShuffleMode = "artist";
                        replyText = "Artist";
                    }
                    else if (ServiceManager.PlaybackController.ShuffleMode.ToString() == "artist")
                    {
                        ServiceManager.PlaybackController.ShuffleMode = "album";
                        replyText = "Album";
                    }
                    else if (ServiceManager.PlaybackController.ShuffleMode.ToString() == "album")
                    {
                        ServiceManager.PlaybackController.ShuffleMode = "rating";
                        replyText = "Rating";
                    }
                    else if (ServiceManager.PlaybackController.ShuffleMode.ToString() == "rating")
                    {
                        ServiceManager.PlaybackController.ShuffleMode = "score";
                        replyText = "Score";
                    }
                    else
                    {
                        ServiceManager.PlaybackController.ShuffleMode = "off";
                        replyText = "off";
                    }
                    replyReq = true;
                    break;

                case "repeat":
                    if (ServiceManager.PlaybackController.RepeatMode == PlaybackRepeatMode.None)
                    {
                        ServiceManager.PlaybackController.RepeatMode = PlaybackRepeatMode.RepeatAll;
                        replyText = "all";
                    }
                    else if (ServiceManager.PlaybackController.RepeatMode == PlaybackRepeatMode.RepeatAll)
                    {
                        ServiceManager.PlaybackController.RepeatMode = PlaybackRepeatMode.RepeatSingle;
                        replyText = "single";
                    }
                    else
                    {
                        ServiceManager.PlaybackController.RepeatMode = PlaybackRepeatMode.None;
                        replyText = "off";
                    }
                    replyReq = true;
                    break;

                case "all":
                    replyText  = ServiceManager.PlayerEngine.CurrentState.ToString().ToLower() + sep;
                    replyText += currTrack.DisplayAlbumTitle.Replace('/', '\\') + sep;
                    replyText += currTrack.DisplayArtistName.Replace('/', '\\') + sep;
                    replyText += currTrack.DisplayTrackTitle.Replace('/', '\\') + sep;
                    replyText += ((uint)(ServiceManager.PlayerEngine.Position / 1000)).ToString() + sep;
                    replyText += ((uint)(currTrack.Duration.TotalSeconds)).ToString() + sep;
                    replyText += coverExists(coverPath);
                    replyReq   = true;
                    break;

                case "test":
                    replyText = "";
                    replyReq  = true;
                    break;

                default:
                    replyText = "";
                    replyReq  = false;
                    break;
                }

                byte[] messageByte = System.Text.Encoding.UTF8.GetBytes(replyText);

                if (replyReq)
                {
                    reply(client, messageByte);
                }
                client.Close();
            }
            catch (Exception)
            {
            }
        }