Parse() public method

public Parse ( SafeUri uri ) : bool
uri Hyena.SafeUri
return bool
Beispiel #1
0
        public override void Load(StreamReader reader, bool validateHeader)
        {
            XmlTextReader xml_reader = new XmlTextReader(reader);

            xml_reader.WhitespaceHandling = WhitespaceHandling.None;
            xml_reader.EntityHandling     = EntityHandling.ExpandCharEntities;

            if (!CheckAsxHeader(xml_reader))
            {
                throw new InvalidPlaylistException();
            }

            while (xml_reader.Read())
            {
                if (xml_reader.NodeType != XmlNodeType.Element || xml_reader.Depth != 1)
                {
                    continue;
                }

                switch (xml_reader.LocalName.ToLower())
                {
                case "title":
                    try {
                        xml_reader.Read();
                        Title = xml_reader.Value;
                    }
                    catch {
                    }
                    break;

                case "entry":
                    LoadEntry(xml_reader);
                    break;

                case "entryref":
                    string href = xml_reader["HREF"] ?? xml_reader["href"];
                    if (href != null)
                    {
                        var secondary = PlaylistParser.Parse(new SafeUri(ResolveUri(href)));
                        if (secondary != null)
                        {
                            // splice in Elements of secondary
                            foreach (PlaylistElement e in secondary.Elements)
                            {
                                Elements.Add(e);
                            }
                        }
                    }
                    break;
                }
            }
        }
 private void LoadStreamUri(string uri)
 {
     try {
         PlaylistParser parser = new PlaylistParser();
         if (parser.Parse(new SafeUri(uri))) {
             foreach(Dictionary<string, object> element in parser.Elements) {
                 if(element.ContainsKey("uri")) {
                     // mms can be a nested link
                     string element_uri = element["uri"].ToString();
                     if(element_uri.StartsWith("mms:", StringComparison.CurrentCultureIgnoreCase)){
                         LoadStreamUri("http" + element_uri.Substring(element_uri.IndexOf(":")));
                     }
                     stream_uris.Add(new SafeUri(((Uri)element["uri"]).AbsoluteUri));
                 }
             }
         } else {
             stream_uris.Add(new SafeUri(uri));
         }
         Log.DebugFormat ("Parsed {0} URIs out of {1}", stream_uris.Count, this);
     } catch (System.Net.WebException e) {
         Hyena.Log.Exception (this.ToString (), e);
         SavePlaybackError (StreamPlaybackError.ResourceNotFound);
     } catch (Exception e) {
         Hyena.Log.Exception (this.ToString (), e);
         SavePlaybackError (StreamPlaybackError.Unknown);
     }
 }
        public override void Load(StreamReader reader, bool validateHeader)
        {
            XmlTextReader xml_reader = new XmlTextReader(reader);
            xml_reader.WhitespaceHandling = WhitespaceHandling.None;
            xml_reader.EntityHandling = EntityHandling.ExpandCharEntities;

            if(!CheckAsxHeader(xml_reader)) {
                throw new InvalidPlaylistException();
            }

            while (xml_reader.Read ()) {
                if (xml_reader.NodeType != XmlNodeType.Element || xml_reader.Depth != 1) {
                    continue;
                }

                switch (xml_reader.LocalName.ToLower ()) {
                    case "title":
                        try {
                            xml_reader.Read ();
                            Title = xml_reader.Value;
                        }
                        catch {
                        }
                        break;

                    case "entry":
                        LoadEntry (xml_reader);
                        break;

                    case "entryref":
                        string href = xml_reader["HREF"] ?? xml_reader["href"];
                        if (href != null) {
                            PlaylistParser secondary = new PlaylistParser ();
                            if (secondary.Parse (new SafeUri (ResolveUri (href)))) {
                                // splice in Elements of secondary
                                foreach (Dictionary<string, object> e in secondary.Elements) {
                                    Elements.Add (e);
                                }
                            }
                        }
                        break;
                }
            }
        }
        public void ReadAsxEntryRef ()
        {
            PlaylistParser parser = new PlaylistParser ();
            parser.BaseUri = BaseUri;

            parser.Parse (new SafeUri ("http://download.banshee.fm/test/remote.asx"));
            IPlaylistFormat plref = LoadPlaylist (new AsxPlaylistFormat (), "entryref.asx");
            Assert.AreEqual (2, plref.Elements.Count);
            AssertEqual (parser.Elements, plref.Elements);
        }
        public void ReadDetectMagic ()
        {
            PlaylistParser parser = new PlaylistParser ();
            parser.BaseUri = BaseUri;

            foreach (string path in Directory.GetFiles (playlists_dir)) {
                parser.Parse (new SafeUri (Path.Combine (Environment.CurrentDirectory, path)));
            }

            parser.Parse (new SafeUri ("http://download.banshee.fm/test/extended.pls"));
            AssertTest (parser.Elements, false);
        }
Beispiel #6
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);
            }
        }
        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);
            }
        }