Exemplo n.º 1
0
        public async Task <UrlParseResult> Parse(string data, ParseResultType type)
        {
            var url = new Uri(data.Trim());

            try
            {
                switch (url.DnsSafeHost)
                {
                case "youtu.be":
                    url = new Uri(url.AbsoluteUri.Replace(@"youtu.be/", @"youtube.com/watch?v="));
                    return(await Parse(url, type));

                case "www.youtube.com":
                    return(await Parse(url, type));

                default:
                    return(new UrlParseResult(_log));
                }
            }
            catch (Exception ex)
            {
                _log.Error(this, ex);
                return(new UrlParseResult(_log));
            }
        }
Exemplo n.º 2
0
        public UrlParseResult(ILoggingService log, List <PlaylistModel> items, ParseResultType type)
            : this(log, type)
        {
            Playlists = items;

            Log();
        }
        public void InitParseResults(List <ParseResult> results, ParseResultType viewType)
        {
            result.Clear();

            foreach (ParseResult r in results)
            {
                if (r.Type == viewType)
                {
                    result.Add(r);
                }
            }

            string count = result.Count.ToString();

            if (result.Count <= 1)
            {
                Button_Prev.IsEnabled = false;
                Button_Next.IsEnabled = false;

                Text_Current.Text = count;
                Text_Max.Text     = count;
            }
            else
            {
                Text_Max.Text = count;
            }

            SetCurrent(1);
        }
Exemplo n.º 4
0
        public UrlParseResult(ILoggingService log, List <MediaItemModel> items, ParseResultType type)
            : this(log, type)
        {
            MediaItems = items;

            Log();
        }
 public ParseResult(
     ParseResultType parseResultType,
     List <CommandSyntaxParsingResult> syntaxParsingResults
     )
 {
     ParseResultType      = parseResultType;
     SyntaxParsingResults = syntaxParsingResults;
 }
Exemplo n.º 6
0
        public UrlParseResult(IMapleLog log, Core.MediaItem item, ParseResultType type) : this(log, type)
        {
            MediaItems = new List <Core.MediaItem>()
            {
                item
            };

            Log();
        }
Exemplo n.º 7
0
        public UrlParseResult(IMapleLog log, Core.Playlist item, ParseResultType type) : this(log, type)
        {
            Playlists = new List <Core.Playlist>()
            {
                item
            };

            Log();
        }
Exemplo n.º 8
0
        public UrlParseResult(ILoggingService log, Data.MediaItem item, ParseResultType type)
            : this(log, type)
        {
            MediaItems = new List <Data.MediaItem>()
            {
                item
            };

            Log();
        }
Exemplo n.º 9
0
        public UrlParseResult(ILoggingService log, PlaylistModel item, ParseResultType type)
            : this(log, type)
        {
            Playlists = new List <PlaylistModel>()
            {
                item
            };

            Log();
        }
Exemplo n.º 10
0
        public UrlParseResult(ILoggingService log, MediaItemModel item, ParseResultType type)
            : this(log, type)
        {
            MediaItems = new List <MediaItemModel>()
            {
                item
            };

            Log();
        }
Exemplo n.º 11
0
        public UrlParseResult(ILoggingService log, Data.Playlist item, ParseResultType type)
            : this(log, type)
        {
            Playlists = new List <Data.Playlist>()
            {
                item
            };

            Log();
        }
Exemplo n.º 12
0
 public ExpressionEvaluationResult(
     string syntaxError,
     ParseResultType parseResult,
     object result,
     int evalResultCode,
     Exception evalError)
 {
     SyntaxError    = syntaxError;
     ParseResult    = parseResult;
     Result         = result;
     EvalResultCode = evalResultCode;
     EvalError      = evalError;
 }
Exemplo n.º 13
0
        private async Task <UrlParseResult> Parse(Uri url, ParseResultType type)
        {
            var result     = new UrlParseResult(_log, type);
            var match      = _urlPattern.Match(url.AbsoluteUri);
            var collection = default(NameValueCollection);

            while (match.Success)
            {
                collection = HttpUtility.ParseQueryString(url.Query);
                var keys = collection.AllKeys;

                foreach (var key in keys)
                {
                    var id = collection.Get(key).ToLowerInvariant();

                    switch (key)
                    {
                    case "v":
                        var videos = await _api.GetVideo(id).ConfigureAwait(false);

                        foreach (var video in videos)
                        {
                            result.MediaItems.Add(video);
                        }

                        break;

                    case "list":
                        var playlists = await _api.GetPlaylists(id).ConfigureAwait(false);

                        foreach (var playlist in playlists)
                        {
                            result.Playlists.Add(playlist);
                        }

                        break;

                    default:
                        return(new UrlParseResult(_log, ParseResultType.None));
                    }
                }

                match = match.NextMatch();
            }

            return(result);
        }
 /// <summary>
 /// cmd line expr. eval result
 /// </summary>
 /// <param name="com">the analyzed command text</param>
 /// <param name="syntaxError">text of error if concerns syntax analysis</param>
 /// <param name="parseResult">parse result state</param>
 /// <param name="result">command evaluation result</param>
 /// <param name="evalResultCode">analysis return code or execution return code</param>
 /// <param name="evalError">eval exception error</param>
 /// <param name="evalErrorText">eval error text (if no exception)</param>
 public ExpressionEvaluationResult(
     string com,
     string syntaxError,
     ParseResultType parseResult,
     object result,
     int evalResultCode,
     Exception evalError  = null,
     string evalErrorText = null)
 {
     Com            = com;
     SyntaxError    = syntaxError;
     ParseResult    = parseResult;
     Result         = result;
     EvalResultCode = evalResultCode;
     EvalError      = evalError;
     EvalErrorText  = evalErrorText;
 }
Exemplo n.º 15
0
        private async Task <UrlParseResult> Parse(Uri url, ParseResultType type = ParseResultType.None)
        {
            var result         = new UrlParseResult(_log, type);
            var regex          = @"(?:http|https|)(?::\/\/|)(?:www.|m.|)(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]*)[a-z0-9;:@?&%=+\/\$_.-]*";
            var match          = Regex.Match(url.AbsoluteUri, regex);
            var youtubeService = new Service(_log);

            while (match.Success)
            {
                var keys = HttpUtility.ParseQueryString(url.Query).AllKeys;

                foreach (var key in keys)
                {
                    var id = HttpUtility.ParseQueryString(url.Query).Get(key);

                    switch (key)
                    {
                    case "v":
                        var videos = await youtubeService.GetVideo(id);

                        foreach (var video in videos)
                        {
                            result.MediaItems.Add(video);
                        }

                        break;

                    case "list":
                        var playlists = await youtubeService.GetPlaylists(id);

                        foreach (var playlist in playlists)
                        {
                            result.Playlists.Add(playlist);
                        }

                        break;
                    }
                }

                match = match.NextMatch();
            }

            return(result);
        }
Exemplo n.º 16
0
        public async Task <UrlParseResult> Parse(string data, ParseResultType type)
        {
            var failure = new UrlParseResult(_log, ParseResultType.None);

            if (type == ParseResultType.None)
            {
                return(failure);
            }

            if (string.IsNullOrEmpty(data))
            {
                return(failure);
            }

            if (Uri.TryCreate(data.Trim(), UriKind.RelativeOrAbsolute, out var url))
            {
                try
                {
                    switch (url.DnsSafeHost)
                    {
                    case "youtu.be":
                        url = new Uri(url.AbsoluteUri.Replace(@"youtu.be/", @"youtube.com/watch?v="));
                        return(await Parse(url, type).ConfigureAwait(false));

                    case "www.youtube.com":
                        return(await Parse(url, type).ConfigureAwait(false));
                    }
                }
                catch (Exception ex)
                {
                    _log.Error(this, ex);
                }
            }

            return(failure);
        }
Exemplo n.º 17
0
        public UrlParseResult(IMapleLog log, List <Core.MediaItem> items, ParseResultType type) : this(log, type)
        {
            MediaItems = items;

            Log();
        }
Exemplo n.º 18
0
 public ParseResult(ParseResultType type, int endIndex, string text)
 {
     EndIndex = endIndex;
     Text     = text;
     Type     = type;
 }
Exemplo n.º 19
0
 public ParseResult(ParseResultType type, string message, int line)
 {
     Type    = type;
     Message = message;
     Line    = line;
 }
Exemplo n.º 20
0
 public ParseResult(List <Token> tokens, ParseResultType resultType, int index)
 {
     this.Tokens     = tokens;
     this.ResultType = resultType;
     this.Index      = index;
 }
Exemplo n.º 21
0
 /// <summary>
 /// essentially no data was returned, when using this constructor
 /// </summary>
 public UrlParseResult(IMapleLog log, ParseResultType type = ParseResultType.None) : this(log)
 {
     Type = type;
 }
Exemplo n.º 22
0
        public UrlParseResult(IMapleLog log, List <Core.Playlist> items, ParseResultType type) : this(log, type)
        {
            Playlists = items;

            Log();
        }
Exemplo n.º 23
0
 public UrlParseResult(ILoggingService log, ParseResultType type)
     : this(log)
 {
     Type = type;
 }