Beispiel #1
0
        private ParsedSongQuery ParseReferenceQuery(string trimmed, string query)
        {
            // Optimization: check prefix, in most cases the user won't be searching by URL
            if (trimmed.StartsWith("/s/", StringComparison.InvariantCultureIgnoreCase))
            {
                var entryId = _entryUrlParser.Parse(trimmed, allowRelative: true);

                if (entryId.EntryType == EntryType.Song)
                {
                    return new ParsedSongQuery {
                               Id = entryId.Id
                    }
                }
                ;
            }
            else if (trimmed.StartsWith("http", StringComparison.InvariantCultureIgnoreCase))
            {
                // Test PV URL with services that don't require a web call
                var videoParseResult = VideoServiceHelper.ParseByUrlAsync(query, false, null,
                                                                          VideoService.NicoNicoDouga, VideoService.Youtube, VideoService.Bilibili, VideoService.File, VideoService.LocalFile, VideoService.Vimeo).Result;

                if (videoParseResult.IsOk)
                {
                    if (videoParseResult.Service == Domain.PVs.PVService.NicoNicoDouga)
                    {
                        return(new ParsedSongQuery {
                            NicoId = videoParseResult.Id
                        });
                    }
                    else
                    {
                        return(new ParsedSongQuery {
                            PV = new PVContract {
                                PVId = videoParseResult.Id, Service = videoParseResult.Service
                            }
                        });
                    }
                }

                var entryId = _entryUrlParser.Parse(trimmed, allowRelative: false);

                if (entryId.EntryType == EntryType.Song)
                {
                    return new ParsedSongQuery {
                               Id = entryId.Id
                    }
                }
                ;
            }

            return(null);
        }