コード例 #1
0
ファイル: SongSearch.cs プロジェクト: Shyany/vocadb
        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.ParseByUrl(query, false, null,
                                                                     VideoService.NicoNicoDouga, VideoService.Youtube, VideoService.Bilibili, VideoService.File, VideoService.LocalFile, VideoService.Vimeo);

                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);
        }
コード例 #2
0
        public ActionResult ParsePVUrl(string pvUrl, string callback, DataFormat format = DataFormat.Auto)
        {
            var result = VideoServiceHelper.ParseByUrl(pvUrl, true, LoginManager);

            if (!result.IsOk)
            {
                return(Json(new GenericResponse <string>(false, result.Exception.Message)));
            }

            var contract = new PVContract(result, PVType.Original);

            return(Object(contract, format, callback));
        }
コード例 #3
0
ファイル: AlbumController.cs プロジェクト: sethura/vocadb
        public ActionResult CreatePVForAlbumByUrl(int albumId, string pvUrl)
        {
            var result = VideoServiceHelper.ParseByUrl(pvUrl, true);

            if (!result.IsOk)
            {
                return(Json(new GenericResponse <string>(false, result.Exception.Message)));
            }

            var contract = new PVContract(result, PVType.Other);

            var view = RenderPartialViewToString("PVForSongEditRow", contract);

            return(Json(new GenericResponse <string>(view)));
        }
コード例 #4
0
ファイル: SongSearch.cs プロジェクト: ffdd270/vocadb
        public ParsedSongQuery ParseTextQuery(SearchTextQuery textQuery)
        {
            var query = textQuery.OriginalQuery;

            if (string.IsNullOrWhiteSpace(query))
            {
                return(new ParsedSongQuery());
            }

            var trimmed = query.Trim();

            var term = GetTerm(trimmed, "id", "tag", "artist-tag", "artist-type", "publish-date");

            if (term == null)
            {
                // 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.ParseByUrl(query, false, null,
                                                                         VideoService.NicoNicoDouga, VideoService.Youtube, VideoService.Bilibili, VideoService.File, VideoService.LocalFile, VideoService.Vimeo);

                    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
                        }
                    }
                    ;
                }
            }
            else
            {
                switch (term.PropertyName)
                {
                case "tag":
                    return(new ParsedSongQuery {
                        TagName = term.Value
                    });

                case "artist-tag":
                    return(new ParsedSongQuery {
                        ArtistTag = term.Value
                    });

                case "artist-type":
                    return(new ParsedSongQuery {
                        ArtistType = EnumVal <ArtistType> .ParseSafe(term.Value, ArtistType.Unknown)
                    });

                case "id":
                    return(new ParsedSongQuery {
                        Id = PrimitiveParseHelper.ParseIntOrDefault(term.Value, 0)
                    });

                case "publish-date":
                    return(ParseDateRange(term.Value));
                }
            }

            return(new ParsedSongQuery {
                Name = textQuery
            });
        }