<commit_before>using ATL.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml;

namespace ATL.PlaylistReaders.BinaryLogic
{
    /// <summary>
    /// SMIL playlist reader
    /// NB : Very basic implementation that lists every single audio file in the playlist
    /// </summary>
    public class SMILReader : PlaylistReader
    {

        public override void GetFiles(FileStream fs, ref IList<String> result)
        {
            XmlTextReader source = new XmlTextReader(fs);

            while (source.Read())
            {
                switch (source.NodeType)
                {
                    case XmlNodeType.Element: // Element start
                        if (source.Name.Equals("audio", StringComparison.OrdinalIgnoreCase))
                        {
                            result.Add(getResourceLocation(ref source));
                        }
                        else if (source.Name.Equals("media", StringComparison.OrdinalIgnoreCase))
                        {
                            result.Add(getResourceLocation(ref source));
                        }
                        break;

//                    case XmlNodeType.Text:
//                        break;

//                    case XmlNodeType.EndElement: // Element end
//                        break;
                }
            }

            source.Close();
        }

        // Most SMIL sample playlists store resource location with a relative path
        private String getResourceLocation(ref XmlTextReader source)
        {
            String result = "";
            while (source.MoveToNextAttribute()) // Read the attributes.
            {
                if (source.Name.Equals("src", StringComparison.OrdinalIgnoreCase))
                {
                    result = source.Value;

                    // It it an URI ?
                    if (result.Contains("://") && Uri.IsWellFormedUriString(result,UriKind.RelativeOrAbsolute))
                    {
                        try
                        {
                            Uri uri = new Uri(result);
                            if (uri.IsFile)
                            {
                                result = uri.LocalPath;
                            }
                            else // other protocols (e.g. HTTP, SMB)
                            {
                                //TODO
                            }
                        }
                        catch (UriFormatException)
                        {
                            LogDelegator.GetLogDelegate()(Log.LV_WARNING, result + " is not a valid URI [" + FFileName + "]");
                        }
                    }
                    
                    if (!System.IO.Path.IsPathRooted(result))
                    {
                        result = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(FFileName), result);
                    }
                }
            }
            return result;
        }
    }
}
<commit_msg>Handle "diskless" paths in SMIL playlists<commit_after>using ATL.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;

namespace ATL.PlaylistReaders.BinaryLogic
{
    /// <summary>
    /// SMIL playlist reader
    /// NB : Very basic implementation that lists every single audio file in the playlist
    /// </summary>
    public class SMILReader : PlaylistReader
    {

        public override void GetFiles(FileStream fs, ref IList<String> result)
        {
            XmlTextReader source = new XmlTextReader(fs);

            while (source.Read())
            {
                switch (source.NodeType)
                {
                    case XmlNodeType.Element: // Element start
                        if (source.Name.Equals("audio", StringComparison.OrdinalIgnoreCase))
                        {
                            result.Add(getResourceLocation(ref source));
                        }
                        else if (source.Name.Equals("media", StringComparison.OrdinalIgnoreCase))
                        {
                            result.Add(getResourceLocation(ref source));
                        }
                        break;

//                    case XmlNodeType.Text:
//                        break;

//                    case XmlNodeType.EndElement: // Element end
//                        break;
                }
            }

            source.Close();
        }

        // Most SMIL sample playlists store resource location with a relative path
        private String getResourceLocation(ref XmlTextReader source)
        {
            String result = "";
            while (source.MoveToNextAttribute()) // Read the attributes.
            {
                if (source.Name.Equals("src", StringComparison.OrdinalIgnoreCase))
                {
                    result = source.Value;

                    // It it an URI ?
                    if (result.Contains("://"))
                    {
                        if (Uri.IsWellFormedUriString(result, UriKind.RelativeOrAbsolute))
                        {
                            try
                            {
                                Uri uri = new Uri(result);
                                if (uri.IsFile)
                                {
                                    result = uri.LocalPath;
                                }
                                else // other protocols (e.g. HTTP, SMB)
                                {
                                    //TODO
                                }
                            }
                            catch (UriFormatException)
                            {
                                LogDelegator.GetLogDelegate()(Log.LV_WARNING, result + " is not a valid URI [" + FFileName + "]");
                            }
                        } else
                        {
                            result = result.Replace("file:///", "").Replace("file://", "");
                        }
                    }
                    
                    if (!System.IO.Path.IsPathRooted(result))
                    {
                        result = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(FFileName), result);
                    }
                    result = System.IO.Path.GetFullPath(result);
                }
            }
            return result;
        }
    }
}

{'fraction_non_alphanumeric': 0.08265603435055972, 'fraction_numerical': 0.0, 'mean_word_length': 0.9250295159386068, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1360236', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1376, 'n_words': 301}