private void ProcessRegularPlaylist(string name, XmlReader xml_reader)
        {
            var playlist_source = new PlaylistSource(name, ServiceManager.SourceManager.MusicLibrary);

            playlist_source.Save();
            ServiceManager.SourceManager.MusicLibrary.AddChildSource(playlist_source);

            // Get the songs in the playlists
            if (xml_reader != null)
            {
                while (xml_reader.ReadToFollowing("integer") && !CheckForCanceled())
                {
                    xml_reader.Read();
                    int itunes_id = Int32.Parse(xml_reader.ReadContentAsString());
                    int track_id;
                    if (data.track_ids.TryGetValue(itunes_id, out track_id))
                    {
                        try {
                            ServiceManager.DbConnection.Execute(
                                "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)",
                                playlist_source.DbId, track_id);
                        } catch {
                        }
                    }
                }
                playlist_source.Reload();
                playlist_source.NotifyUser();
            }
        }
Пример #2
0
        public override void SyncPlaylists()
        {
            if (!CanSyncPlaylists)
            {
                return;
            }

            foreach (string file_name in PlaylistFiles)
            {
                try {
                    Banshee.IO.File.Delete(new SafeUri(file_name));
                } catch (Exception e) {
                    Log.Error(e);
                }
            }

            // Add playlists from Banshee to the device
            PlaylistFormatBase playlist_format = null;
            List <Source>      children        = new List <Source> (Children);

            foreach (Source child in children)
            {
                PlaylistSource from         = child as PlaylistSource;
                string         escaped_name = StringUtil.EscapeFilename(child.Name);
                if (from != null && !String.IsNullOrEmpty(escaped_name))
                {
                    from.Reload();
                    if (playlist_format == null)
                    {
                        playlist_format = Activator.CreateInstance(PlaylistTypes[0].Type) as PlaylistFormatBase;
                        playlist_format.FolderSeparator = MediaCapabilities.FolderSeparator;
                    }

                    SafeUri playlist_path = new SafeUri(System.IO.Path.Combine(
                                                            PlaylistsWritePath, String.Format("{0}.{1}", escaped_name, PlaylistTypes[0].FileExtension)));

                    System.IO.Stream stream = null;
                    try {
                        stream = Banshee.IO.File.OpenWrite(playlist_path, true);

                        if (ms_device.RootPath == null)
                        {
                            playlist_format.BaseUri = new Uri(PlaylistsWritePath);
                        }
                        else
                        {
                            playlist_format.RootPath = ms_device.RootPath;
                            playlist_format.BaseUri  = new Uri(BaseDirectory);
                        }

                        playlist_format.Save(stream, from);
                    } catch (Exception e) {
                        Log.Error(e);
                    } finally {
                        stream.Close();
                    }
                }
            }
        }
        // Commented out for now - this method doesn't handle actually subscribing to the feeds
        // (the most important task in migrating podcasts), and it looks like it imports podcast files
        // into the Music Library.

        /*private void ImportPodcasts(LibraryImportManager manager, XmlNodeList podcasts)
         * {
         *  foreach (XmlElement entry in podcasts) {
         *      if (CheckForCanceled ()) {
         *          break;
         *      }
         *
         *      processed++;
         *
         *      string title = String.Empty, feed = String.Empty;
         *      SafeUri uri = null;
         *
         *      foreach (XmlElement child in entry.ChildNodes) {
         *          if (child == null || child.InnerText == null || child.InnerText == String.Empty) {
         *              continue;
         *          }
         *
         *          try {
         *              switch (child.Name) {
         *                  case "title":
         *                      title = child.InnerText;
         *                      break;
         *                  case "album":
         *                      feed = child.InnerText;
         *                      break;
         *                  case "mountpoint":
         *                      uri = new SafeUri (child.InnerText);
         *                      break;
         *              }
         *          } catch (Exception) {
         *              // parsing InnerText failed
         *          }
         *      }
         *
         *      if (uri == null) {
         *          continue;
         *      }
         *
         *      UpdateUserJob (processed, count, "", title);
         *
         *      try {
         *          DatabaseTrackInfo track = manager.ImportTrack (uri);
         *
         *          if (track == null) {
         *              LogError (SafeUri.UriToFilename (uri), Catalog.GetString ("Unable to import podcast."));
         *              continue;
         *          }
         *
         *          track.TrackTitle = title;
         *          track.AlbumTitle = feed;
         *          track.Genre = "Podcast";
         *
         *          track.Save (false);
         *      } catch (Exception e) {
         *          LogError (SafeUri.UriToFilename (uri), e);
         *      }
         *  }
         * }*/

        private void ImportStaticPlaylists(XmlNodeList playlists)
        {
            foreach (XmlElement list in playlists)
            {
                if (CheckForCanceled())
                {
                    break;
                }

                processed++;

                try {
                    string title = String.Empty;
                    if (list.HasAttribute("name"))
                    {
                        title = list.GetAttribute("name");
                    }

                    UpdateUserJob(processed, count, "", title);

                    PlaylistSource playlist = new PlaylistSource(title, ServiceManager.SourceManager.MusicLibrary);
                    playlist.Save();
                    ServiceManager.SourceManager.MusicLibrary.AddChildSource(playlist);


                    HyenaSqliteCommand insert_command = new HyenaSqliteCommand(String.Format(
                                                                                   @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES ({0}, ?)", playlist.DbId));

                    foreach (XmlElement entry in list.ChildNodes)
                    {
                        if (entry.Name != "location")
                        {
                            continue;
                        }

                        int track_id = ServiceManager.SourceManager.MusicLibrary.GetTrackIdForUri(entry.InnerText);
                        if (track_id > 0)
                        {
                            ServiceManager.DbConnection.Execute(insert_command, track_id);
                        }
                    }

                    playlist.Reload();
                    playlist.NotifyUser();
                } catch (Exception e) {
                    LogError("", e);
                }
            }
        }
Пример #4
0
        public override void SyncPlaylists()
        {
            if (!CanSyncPlaylists)
            {
                return;
            }

            foreach (string file_name in PlaylistFiles)
            {
                Banshee.IO.File.Delete(new SafeUri(file_name));
            }

            // Add playlists from Banshee to the device
            PlaylistFormatBase playlist_format = null;
            List <Source>      children        = new List <Source> (Children);

            foreach (Source child in children)
            {
                PlaylistSource from = child as PlaylistSource;
                if (from != null)
                {
                    from.Reload();
                    if (playlist_format == null)
                    {
                        playlist_format = Activator.CreateInstance(PlaylistTypes[0].Type) as PlaylistFormatBase;
                    }

                    SafeUri playlist_path = new SafeUri(System.IO.Path.Combine(
                                                            PlaylistsPath, String.Format("{0}.{1}", from.Name, PlaylistTypes[0].FileExtension)));

                    System.IO.Stream stream = Banshee.IO.File.OpenWrite(playlist_path, true);
                    playlist_format.BaseUri = new Uri(BaseDirectory);
                    playlist_format.Save(stream, from);
                    stream.Close();
                }
            }
        }