Exemple #1
0
        /// <summary>
        /// Attempts to parse a URL that refers to a media collection.
        /// </summary>
        /// <param name="url">The URL to parse.</param>
        /// <returns>The state of the parser. See the documentation for <see cref="UrlParseState"/> for more info.</returns>
        public UrlParseState Parse(string url)
        {
            Service     = null;
            ParseResult = null;

            if (String.IsNullOrWhiteSpace(url))
            {
                return(UrlParseState.NullOrEmptyString);
            }

            Uri actualUrl;

            if (!Uri.TryCreate(url, UriKind.Absolute, out actualUrl))
            {
                return(UrlParseState.InvalidUrl);
            }

            Service = pluginManager.GetServiceByBaseUri(actualUrl);
            if (Service == null)
            {
                return(UrlParseState.NoServiceFound);
            }

            if (!Service.AsAuthenticatable().IsAuthenticated)
            {
                return(UrlParseState.ServiceNotAuthenticated);
            }

            if ((ParseResult = Service.ParseUrl(actualUrl)) == null || ParseResult?.Type == MediaType.Unknown)
            {
                return(UrlParseState.NoMedia);
            }

            return(UrlParseState.Success);
        }
Exemple #2
0
        private bool ValidateEnteredUrl()
        {
            urlValidStateLabel.ResetText();
            urlValidStateLabel.Links.Clear();
            urlValidStateLabel.Image = Resources.error;
            dlButton.Enabled         = false;

            // Hide on empty
            if (String.IsNullOrWhiteSpace(idTextBox.Text))
            {
                urlValidStateLabel.Visible = false;
                return(false);
            }
            urlValidStateLabel.Visible = true;

            Uri url;

            // Invalid URL
            if (!Uri.TryCreate(idTextBox.Text, UriKind.Absolute, out url))
            {
                urlValidStateLabel.Text = UrlInvalid;
                return(false);
            }
            var service = Program.DefaultPluginManager.GetServiceByBaseUri(url);

            // No service associated with host
            if (service == null)
            {
                urlValidStateLabel.Text = UrlNoService;
                return(false);
            }
            // Not authenticated
            var authenticatable = service.AsAuthenticatable();

            if (!authenticatable.IsAuthenticated)
            {
                urlValidStateLabel.Text = String.Format(UrlNeedsAuthentication, service.Info.Name);
                var linkIndex = urlValidStateLabel.Text.LastIndexOf(UrlNeedsAuthenticationLink1, StringComparison.Ordinal);
                urlValidStateLabel.Links.Add(linkIndex, urlValidStateLabel.Text.Length, service);
                return(false);
            }
            // URL doesn't point to media
            var result = service.ParseUrl(url);

            if (result == null)
            {
                urlValidStateLabel.Text = UrlNotParseable;
                return(false);
            }
            // Success
            urlValidStateLabel.Image = Resources.done;
            urlValidStateLabel.Text  = String.Format(UrlValidParseResult, result.Type, service.Info.Name);
            dlButton.Enabled         = true;
            mResult  = result;
            mService = service;
            return(true);
        }
        private async Task Parse()
        {
            Result = await _dataParsingService.Parse(Source, ParseResultType.MediaItems)
                     .ConfigureAwait(true);

            if (Result.Count > 0 && Result.MediaItems?.Count > 0)
            {
                AddRange(_mapper.GetMany(Result.MediaItems));
            }
        }
Exemple #4
0
        private void InitializeCommands()
        {
            ParseCommand = new RelayCommand(async() =>
            {
                using (_busyStack.GetToken())
                {
                    Result = await _dataParsingService.Parse(Source, ParseResultType.MediaItems);

                    if (Result.Count > 0 && Result.MediaItems?.Count > 0)
                    {
                        Items.AddRange(_mapper.GetMany(Result.MediaItems));
                    }
                }
            }, () => !string.IsNullOrWhiteSpace(Source));
        }
        private UrlParseResult ParsePlayerUrl(Uri url)
        {
            // eg https://play.google.com/music/listen?authuser&u=0#/album/Bxrl5ep5hy42lcgslqo2g763fmi/21+Savage/Savage+Mode
            var hashParts = url.Fragment.Split('/');

            if (hashParts.Length <= 2)
            {
                return(null);
            }
            var type   = hashParts[1];
            var id     = hashParts[2];
            var result = new UrlParseResult {
                Id = ParseId(id), Type = ParseType(type), OriginalUri = url
            };

            return(result);
        }
Exemple #6
0
        public override UrlParseResult ParseUrl(Uri url)
        {
            if (url.Host != TidalWebDomain)
            {
                return(null);
            }
            var pathParts = url.LocalPath.Split('/');

            if (pathParts.Length <= 2)
            {
                return(null);
            }
            var ctype  = pathParts[1];
            var id     = pathParts[2];
            var result = new UrlParseResult {
                Id = id, Type = MediaType.Unknown, OriginalUri = url
            };

            switch (ctype)
            {
            case "album":
                result.Type = MediaType.Album;
                break;

            case "track":
                result.Type = MediaType.Track;
                break;

            case "artist":
                result.Type = MediaType.Artist;
                break;

            case "playlist":
                result.Type = MediaType.Playlist;
                break;

            default:
                result.Type = MediaType.Unknown;
                break;
            }
            return(result);
        }
        public override UrlParseResult ParseUrl(Uri url)
        {
            if (url.Host != GooglePlayHost)
            {
                return(null);
            }
            var hashParts = url.Fragment.Split('/');

            if (hashParts.Length <= 2)
            {
                return(null);
            }
            var type   = hashParts[1];
            var id     = hashParts[2];
            var result = new UrlParseResult {
                Id = id, Type = MediaType.Unknown, OriginalUri = url
            };

            switch (type)
            {
            case "album":
                result.Type = MediaType.Album;
                break;

            case "artist":
                result.Type = MediaType.Artist;
                break;

            // Will auto-playlists actually be interchangeable with user-generated playlists?
            case "pl":
            case "ap":
                result.Type = MediaType.Playlist;
                break;

            default:
                result.Type = MediaType.Unknown;
                break;
            }
            return(result);
        }