private string GetTrackPath (TrackInfo track, string ext)
        {
            string file_path = null;

            if (track.HasAttribute (TrackMediaAttributes.Podcast)) {
                string album = FileNamePattern.Escape (track.DisplayAlbumTitle);
                string title = FileNamePattern.Escape (track.DisplayTrackTitle);
                file_path = System.IO.Path.Combine ("Podcasts", album);
                file_path = System.IO.Path.Combine (file_path, title);
            } else if (track.HasAttribute (TrackMediaAttributes.VideoStream)) {
                string album = FileNamePattern.Escape (track.DisplayAlbumTitle);
                string title = FileNamePattern.Escape (track.DisplayTrackTitle);
                file_path = System.IO.Path.Combine (album, title);
            } else if (ms_device == null || !ms_device.GetTrackPath (track, out file_path)) {
                // If the folder_depth property exists, we have to put the files in a hiearchy of
                // the exact given depth (not including the mount point/audio_folder).
                if (FolderDepth != -1) {
                    int depth = FolderDepth;
                    string album_artist = FileNamePattern.Escape (track.DisplayAlbumArtistName);
                    string track_album  = FileNamePattern.Escape (track.DisplayAlbumTitle);
                    string track_number = FileNamePattern.Escape (String.Format ("{0:00}", track.TrackNumber));
                    string track_title  = FileNamePattern.Escape (track.DisplayTrackTitle);

                    if (depth == 0) {
                        // Artist - Album - 01 - Title
                        string track_artist = FileNamePattern.Escape (track.DisplayArtistName);
                        file_path = String.Format ("{0} - {1} - {2} - {3}", track_artist, track_album, track_number, track_title);
                    } else if (depth == 1) {
                        // Artist - Album/01 - Title
                        file_path = String.Format ("{0} - {1}", album_artist, track_album);
                        file_path = System.IO.Path.Combine (file_path, String.Format ("{0} - {1}", track_number, track_title));
                    } else if (depth == 2) {
                        // Artist/Album/01 - Title
                        file_path = album_artist;
                        file_path = System.IO.Path.Combine (file_path, track_album);
                        file_path = System.IO.Path.Combine (file_path, String.Format ("{0} - {1}", track_number, track_title));
                    } else {
                        // If the *required* depth is more than 2..go nuts!
                        for (int i = 0; i < depth - 2; i++) {
                            if (i == 0) {
                                file_path = album_artist.Substring (0, Math.Min (i+1, album_artist.Length)).Trim ();
                            } else {
                                file_path = System.IO.Path.Combine (file_path, album_artist.Substring (0, Math.Min (i+1, album_artist.Length)).Trim ());
                            }

                        }

                        // Finally add on the Artist/Album/01 - Track
                        file_path = System.IO.Path.Combine (file_path, album_artist);
                        file_path = System.IO.Path.Combine (file_path, track_album);
                        file_path = System.IO.Path.Combine (file_path, String.Format ("{0} - {1}", track_number, track_title));
                    }
                } else {
                    file_path = MusicLibrarySource.MusicFileNamePattern.CreateFromTrackInfo (track);
                }
            }

            if (track.HasAttribute (TrackMediaAttributes.VideoStream)) {
              file_path = System.IO.Path.Combine (WritePathVideo, file_path);
            } else {
              file_path = System.IO.Path.Combine (WritePath, file_path);
            }
            file_path += ext;

            return file_path;
        }
Example #2
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;
     }
 }
Example #3
0
        public static void ImportPlaylistToLibrary (string path, PrimarySource source, DatabaseImportManager importer)
        {
            try {
                SafeUri uri = new SafeUri (path);
                PlaylistParser parser = new PlaylistParser ();
                string relative_dir = System.IO.Path.GetDirectoryName (uri.LocalPath);
                if (relative_dir[relative_dir.Length - 1] != System.IO.Path.DirectorySeparatorChar) {
                    relative_dir = relative_dir + System.IO.Path.DirectorySeparatorChar;
                }
                parser.BaseUri = new Uri (relative_dir);
                if (parser.Parse (uri)) {
                    List<string> uris = new List<string> ();
                    foreach (PlaylistElement element in parser.Elements) {
                        uris.Add (element.Uri.LocalPath);
                    }

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

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

                    // Give source a fallback value - MusicLibrary when it's null
                    if (source == null)
                        source = ServiceManager.SourceManager.MusicLibrary;
                    
                    // Only import an non-empty playlist
                    if (uris.Count > 0) {
                        ImportPlaylistWorker worker = new ImportPlaylistWorker (
                            parser.Title,
                            uris.ToArray (), source, importer);
                        worker.Import ();
                    }
                }
            } catch (Exception e) {
                Hyena.Log.Exception (e);
            }
        }
Example #4
0
        private void HandleOpen(TrackInfo track)
        {
            var uri = track.Uri;
            if (current_state != PlayerState.Idle && current_state != PlayerState.NotReady && current_state != PlayerState.Contacting) {
                Close (false);
            }

            try {
                CurrentTrackTimeStamp = DateTime.Now;
                current_track = track;
                OnStateChanged (PlayerState.Loading);
                OpenUri (uri, track.HasAttribute (TrackMediaAttributes.VideoStream) || track is UnknownTrackInfo);
            } catch (Exception e) {
                Close (true);
                OnEventChanged (new PlayerEventErrorArgs (e.Message));
            }
        }
Example #5
0
        private void HandleNextTrack(TrackInfo track)
        {
            pending_track = track;
            if (current_state != PlayerState.Playing) {
                // Pre-buffering the next track only makes sense when we're currently playing
                // Instead, just open.
                if (track != null && track.Uri != null) {
                    HandleOpen (track);
                    Play ();
                }
                return;
            }

            try {
                // Setting the next track doesn't change the player state.
                SetNextTrackUri (track == null ? null : track.Uri,
                    track == null || track.HasAttribute (TrackMediaAttributes.VideoStream) || track is UnknownTrackInfo);
            } catch (Exception e) {
                Log.Exception ("Failed to pre-buffer next track", e);
            }
        }
        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.");
            }

            if (!track.HasAttribute (TrackMediaAttributes.Music)) {
                throw new InvalidFileException ("You can only download lyrics for a music track.");
            }

            //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.Warning (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;
        }
Example #7
0
        private static void FindTrackMediaAttributes (TrackInfo track, TagLib.File file)
        {
            if ((file.Properties.MediaTypes & TagLib.MediaTypes.Audio) != 0) {
                track.MediaAttributes |= TrackMediaAttributes.AudioStream;
            }

            if ((file.Properties.MediaTypes & TagLib.MediaTypes.Video) != 0) {
                track.MediaAttributes |= TrackMediaAttributes.VideoStream;
            }

            if (file.Tag.FirstGenre == "Podcast" || file.Tag.Album == "Podcast") {
                track.MediaAttributes |= TrackMediaAttributes.Podcast;
            }

            // TODO: Actually figure out, if possible at the tag/file level, if
            // the file is actual music, podcast, audiobook, movie, tv show, etc.
            // For now just assume that if it's only audio and not podcast, it's
            // music, since that's what we've just historically assumed on any media type
            if (!track.HasAttribute (TrackMediaAttributes.VideoStream) &&
                !track.HasAttribute (TrackMediaAttributes.Podcast)) {
                track.MediaAttributes |= TrackMediaAttributes.Music;
            } else {
                // If it was already set, unset it
                track.MediaAttributes &= ~TrackMediaAttributes.Music;
            }
        }