Exemple #1
0
        public Preview(
            string externalId,
            MediaContentSource contentSource,
            MediaContentType contentType,
            string contentTitle,
            string contentDescription,
            Thumbnail thumbnail)
        {
            try
            {
                if (string.IsNullOrEmpty(contentTitle))
                {
                    throw new ArgumentException("Given title is null or empty");
                }

                ContentId   = new ContentId(externalId, contentSource, contentType);
                Title       = contentTitle;
                Description = contentDescription;
                Thumbnail   = thumbnail ?? throw new ArgumentNullException(nameof(thumbnail));
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException("Could not create preview", exception);
            }
        }
        public async Task <ActionResult> SearchForContent(MediaContentSource source, string queryString)
        {
            var query = new GetRelevantContentQuery {
                SelectedSource = source, QueryString = queryString
            };
            var searchResult = await _mediator.Send(query);

            return(PartialView("SearchResults", searchResult));
        }
        public async Task <SearchResult> SearchForContentAsync(
            MediaContentSource source,
            ContentQueryType contentQueryType,
            string queryString,
            CancellationToken cancellationToken)
        {
            try
            {
                SearchResult searchResult;

                switch (source)
                {
                case MediaContentSource.YouTube:
                    if (contentQueryType == ContentQueryType.Keywords)
                    {
                        searchResult = await _youTubeRepository.SearchForVideosByKeywords(queryString, cancellationToken);
                    }
                    else
                    {
                        var cachedContent = await _applicationDbContext.CachedContent.FirstOrDefaultAsync(
                            cc => cc.ExternalId == queryString && cc.ContentSource == source,
                            cancellationToken);

                        if (cachedContent != null)
                        {
                            searchResult = new SearchResult {
                                RequestedContent = _mapper.Map <Content>(cachedContent)
                            };
                        }
                        else
                        {
                            searchResult = await _youTubeRepository.SearchForVideoById(queryString, cancellationToken);

                            if (searchResult.RequestedContent != null)
                            {
                                await CacheContent(searchResult.RequestedContent, cancellationToken);
                            }
                        }
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(MediaContentSource));
                }


                return(searchResult);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"An exception occured on attempt to search the content for " +
                                                    $"{source} by {contentQueryType} (query string: {queryString})", exception);
            }
        }
        public string ExtractExternalContentIdFromUrl(MediaContentSource source, string queryString)
        {
            var selectedSourceScope = _contentIdScope[source];

            int beginningPosition = queryString.IndexOf(selectedSourceScope.Item1, StringComparison.Ordinal)
                                    + selectedSourceScope.Item1.Length;
            int endingPosition = queryString.IndexOf(selectedSourceScope.Item2, StringComparison.Ordinal);

            endingPosition = endingPosition == -1 ? queryString.Length - 1 : endingPosition;

            return(queryString.Substring(beginningPosition, endingPosition - beginningPosition + 1));
        }
        public ContentQueryType DefineQueryStringType(MediaContentSource source, string queryString)
        {
            if (!_mediaContentSourceDomains.Keys.Contains(source))
            {
                throw new InvalidOperationException("Request domain is not specified for selected content source");
            }

            string selectedSourceDomain = _mediaContentSourceDomains[source];

            return(queryString.Contains(selectedSourceDomain)
                ? ContentQueryType.ContentId
                : ContentQueryType.Keywords);
        }
Exemple #6
0
        public ContentId(
            string externalId,
            MediaContentSource contentSource,
            MediaContentType contentType)
        {
            try
            {
                if (string.IsNullOrEmpty(externalId))
                {
                    throw new ArgumentException("External ID is null or empty");
                }

                ExternalId    = externalId;
                ContentSource = contentSource;
                ContentType   = contentType;
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException("Could not create content ID", exception);
            }
        }
Exemple #7
0
        public void Create_preview()
        {
            string             actualExternalId  = "someId";
            MediaContentSource actualSource      = MediaContentSource.YouTube;
            MediaContentType   actualType        = MediaContentType.Video;
            string             actualTitle       = "sometitle";
            string             actualDescription = "somedescription";
            Thumbnail          actualThumbnail   = new Thumbnail(100, 100, "https://someurl.com");

            var preview = new Preview(
                actualExternalId,
                actualSource,
                actualType,
                actualTitle,
                actualDescription,
                actualThumbnail);

            Assert.Equal(actualExternalId, preview.ContentId.ExternalId);
            Assert.Equal(actualSource, preview.ContentId.ContentSource);
            Assert.Equal(actualType, preview.ContentId.ContentType);
            Assert.Equal(actualTitle, preview.Title);
            Assert.Equal(actualDescription, preview.Description);
            Assert.Equal(actualThumbnail.Url, preview.Thumbnail.Url);
        }