Example #1
0
 public static List<SongMusicItem> LoadAllSongs()
 {
     List<SongMusicItem> songsCopy;
     lock (songs) {
         // Begin a new timer to clear the songs SecondsSongsCached seconds from now.
         clearSongsTimer.Change (SecondsSongsCached*1000, Timeout.Infinite);
         if (songs.Count == 0) {
             // Song list is not cached. Load songs from database.
             try {
                 Process proc = new Process();
                 proc.StartInfo.FileName = "/usr/bin/mpc";
                 proc.StartInfo.Arguments =@"playlist --format "":%title%:%artist%:%album%:%file%""";
                 proc.StartInfo.UseShellExecute=false;
                 proc.StartInfo.RedirectStandardOutput = true;
                 proc.Start();
                 String line = proc.StandardOutput.ReadLine();
                 while(line != null){
                     string[] info = line.Split(':');
                     SongMusicItem song;
                     string song_file, song_name, album_name, artist_name,cover;
                     int number = Convert.ToInt32(info[0].Substring(1,info[0].IndexOf(')') -1 ));
                     song_name = info[1];
                     artist_name = info[2];
                     album_name = info[3];
                     song_file = info[4];
                     string cover_name_artist = artist_name;
                     string cover_name_album = album_name;
                     //Try the album art first, then the artist art
                     cover_name_artist = cover_name_artist.Replace(" ","%20");
                     cover_name_album = cover_name_album.Replace(" ","%20");
                     cover = string.Format ("{0}-{1}.jpg", cover_name_artist, cover_name_album);
                     cover = Path.Combine (CoverArtDirectory, cover);
                     if(!File.Exists (cover)){
                         cover = string.Format ("{0}.jpg", cover_name_artist);
                         cover = Path.Combine (CoverArtDirectory, cover);
                         if (!File.Exists (cover)) cover = null;
                     }
                     song = new SongMusicItem (song_name, artist_name, album_name, cover,song_file,  number);
                     songs.Add (song);
                     line = proc.StandardOutput.ReadLine();
                 }
             } catch (Exception e) {
                 Console.Error.WriteLine ("Could not read MPD database file: " + e.Message);
             }
         }
         songsCopy = new List<SongMusicItem> (songs);
     }
     return songsCopy;
 }
Example #2
0
        void ProcessesList()
        {
            List<VideoItem> videos = new List<VideoItem> ();
            List<SongMusicItem> songs = new List<SongMusicItem> ();
            List<PodcastItem> podcasts = new List<PodcastItem> ();

            foreach (IDictionary<string, object> result in indexed_items)
            {
                IMediaFile item;
                string path, artPath, mediaType;
                Dictionary<string, string> tags;

                tags = SetupTags ();
                foreach (string tag in export_fields) {
                    object objTag;

                    result.TryGetValue (tag, out objTag);
                    tags [tag] = (objTag == null) ? "" : objTag.ToString ();
                }

                mediaType = tags ["media-attributes"];

                // some items dont have a local-path, we need to use the URI in this case.
                path = string.IsNullOrEmpty (tags ["local-path"]) ? tags ["URI"] : tags ["local-path"];
                artPath = string.IsNullOrEmpty (tags ["artwork-id"]) ? "" : Path.Combine (artwork_directory, tags ["artwork-id"] + ".jpg");

                //Handle videos in the collection
                if (mediaType.Contains ("VideoStream")) {
                    item = new VideoItem (tags ["name"], tags ["artist"], tags ["year"], artPath, path);

                    videos.Add (item as VideoItem);

                //Handle the podcasts in collection
                } else if (mediaType.Contains ("Podcast")) {
                    item = new PodcastPodcastItem (tags ["name"], tags ["album"], tags ["year"], artPath, path);

                    podcasts.Add (item as PodcastPodcastItem);

                //everything else should be Music
                } else {
                    item = new SongMusicItem (tags ["name"], tags ["artist"], tags ["album"], tags ["year"],
                        artPath, tags ["track-number"], path);

                    songs.Add (item as SongMusicItem);
                }

                Videos = videos;
                Songs = songs;
                Podcasts = podcasts;
            }
        }