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 (Dictionary <string, object> element in parser.Elements) { uris.Add(((Uri)element["uri"]).LocalPath); } ImportPlaylistWorker worker = new ImportPlaylistWorker( parser.Title, uris.ToArray(), source, importer); worker.Import(); } } catch (Exception e) { Hyena.Log.Exception(e); } }
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); } }
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); } }
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 (Dictionary<string, object> element in parser.Elements) { uris.Add (((Uri)element["uri"]).LocalPath); } ImportPlaylistWorker worker = new ImportPlaylistWorker ( parser.Title, uris.ToArray (), source, importer); worker.Import (); } } catch (Exception e) { Hyena.Log.Exception (e); } }