Example #1
0
        public static VideoTitleParseResult ParseResponse(NicoResponse nicoResponse)
        {
            if (nicoResponse.Status == "fail")
            {
                var err = (nicoResponse.Error != null ? nicoResponse.Error.Description : "empty response");
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + err));
            }

            var title       = HtmlEntity.DeEntitize(nicoResponse.Thumb.Title);
            var thumbUrl    = UrlHelper.UpgradeToHttps(nicoResponse.Thumb.Thumbnail_Url) ?? string.Empty;
            var userId      = nicoResponse.Thumb.User_Id ?? string.Empty;
            var length      = ParseLength(nicoResponse.Thumb.Length);
            var author      = nicoResponse.Thumb.User_Nickname;
            var publishDate = DateTimeHelper.ParseDateTimeOffsetAsDate(nicoResponse.Thumb.First_Retrieve);

            if (string.IsNullOrEmpty(author))
            {
                author = GetUserName(userId);
            }

            var result = VideoTitleParseResult.CreateSuccess(title, author, userId, thumbUrl, length, uploadDate: publishDate);

            result.Tags = nicoResponse.Thumb.Tags;

            return(result);
        }
Example #2
0
        public static VideoTitleParseResult GetTitleAPI(string id)
        {
            var url = string.Format("https://ext.nicovideo.jp/api/getthumbinfo/{0}", id);

            var request = WebRequest.Create(url);

            request.Timeout = 10000;

            NicoResponse nicoResponse;

            try {
                using (var response = request.GetResponse())
                    using (var stream = response.GetResponseStream()) {
                        nicoResponse = GetResponse(stream);
                    }
            } catch (WebException x) {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + x.Message));
            } catch (XmlException x) {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + x.Message));
            } catch (IOException x) {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + x.Message));
            }

            return(ParseResponse(nicoResponse));
        }
Example #3
0
        public VideoTitleParseResult GetTitle(string id)
        {
            var service = new YoutubeService(AppConfig.YoutubeApiKey);

            YoutubeVideoResponse result;

            try {
                result = service.Video(id);
            } catch (WebException x) {
                return(VideoTitleParseResult.CreateError(x.Message));
            }

            if (!result.Items.Any())
            {
                return(VideoTitleParseResult.Empty);
            }

            var video       = result.Items.First();
            var thumbUrl    = video.Snippet.Thumbnails.Default != null ? video.Snippet.Thumbnails.Default.Url : string.Empty;
            var length      = GetLength(video);
            var author      = video.Snippet.ChannelTitle;
            var publishDate = GetPublishDate(video);

            return(VideoTitleParseResult.CreateSuccess(video.Snippet.Title, author, thumbUrl, length, uploadDate: publishDate));
        }
Example #4
0
        public override async Task <VideoUrlParseResult> ParseByUrlAsync(string url, bool getTitle)
        {
            var id = GetIdByUrl(url);

            if (string.IsNullOrEmpty(id))
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.NoMatcher, "No matcher"));
            }

            if (!getTitle)
            {
                return(VideoUrlParseResult.CreateOk(url, PVService.Bilibili, id, VideoTitleParseResult.Empty));
            }

            var paramStr    = string.Format("appkey={0}&id={1}&type=xml{2}", AppConfig.BilibiliAppKey, id, AppConfig.BilibiliSecretKey);
            var paramStrMd5 = CryptoHelper.HashString(paramStr, CryptoHelper.MD5).ToLowerInvariant();

            var requestUrl = string.Format("https://api.bilibili.com/view?appkey={0}&id={1}&type=xml&sign={2}", AppConfig.BilibiliAppKey, id, paramStrMd5);

            XDocument doc;

            try {
                doc = await HtmlRequestHelper.GetStreamAsync(requestUrl, stream => XDocument.Load(stream), timeoutSec : 10, userAgent : "VocaDB/1.0 ([email protected])");
            } catch (WebException x) {
                log.Warn(x, "Unable to load Bilibili URL {0}", url);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, new VideoParseException(string.Format("Unable to load Bilibili URL: {0}", x.Message), x)));
            } catch (XmlException x) {
                log.Warn(x, "Unable to load Bilibili URL {0}", url);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, new VideoParseException(string.Format("Unable to load Bilibili URL: {0}", x.Message), x)));
            } catch (IOException x) {
                log.Warn(x, "Unable to load Bilibili URL {0}", url);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, new VideoParseException(string.Format("Unable to load Bilibili URL: {0}", x.Message), x)));
            }

            var titleElem   = doc.XPathSelectElement("/info/title");
            var thumbElem   = doc.XPathSelectElement("/info/pic");
            var authorElem  = doc.XPathSelectElement("/info/author");
            var authorId    = GetValue(doc, "/info/mid");
            var createdElem = doc.XPathSelectElement("/info/created_at");

            int.TryParse(GetValue(doc, "/info/cid"), out var cid);             // Unsure what this is, but it's required for embedding

            if (titleElem == null)
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "No title element"));
            }

            var title   = HtmlEntity.DeEntitize(titleElem.Value);
            var thumb   = thumbElem?.Value ?? string.Empty;
            var author  = authorElem?.Value ?? string.Empty;
            var created = createdElem != null ? (DateTime?)DateTime.Parse(createdElem.Value) : null;
            var length  = await GetLength(id);

            var metadata = new PVExtendedMetadata(new BiliMetadata {
                Cid = cid
            });

            return(VideoUrlParseResult.CreateOk(url, PVService.Bilibili, id,
                                                VideoTitleParseResult.CreateSuccess(title, author, authorId, thumb, length: length, uploadDate: created, extendedMetadata: metadata)));
        }
Example #5
0
        public static VideoTitleParseResult GetTitleHtml(string id)
        {
            var url = string.Format("http://nicovideo.jp/watch/{0}", id);

            string      videoTitle = null;
            var         request    = WebRequest.Create(url);
            WebResponse response;

            try {
                response = request.GetResponse();
            } catch (WebException x) {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + x.Message));
            }

            var enc = GetEncoding(response.Headers[HttpResponseHeader.ContentEncoding]);

            try {
                using (var stream = response.GetResponseStream()) {
                    videoTitle = GetVideoTitle(stream, enc);
                }
            } finally {
                response.Close();
            }

            if (!string.IsNullOrEmpty(videoTitle))
            {
                return(VideoTitleParseResult.CreateSuccess(videoTitle, null, null));
            }
            else
            {
                return(VideoTitleParseResult.CreateError("Title element not found"));
            }
        }
Example #6
0
        private VideoTitleParseResult GetTitle(string id)
        {
            var url = string.Format("http://vimeo.com/api/v2/video/{0}.xml", id);

            var         request    = WebRequest.Create(url);
            var         serializer = new XmlSerializer(typeof(VimeoResult));
            VimeoResult result;

            try {
                using (var response = request.GetResponse())
                    using (var stream = response.GetResponseStream()) {
                        result = (VimeoResult)serializer.Deserialize(stream);
                    }
            } catch (WebException x) {
                return(VideoTitleParseResult.CreateError("Vimeo (error): " + x.Message));
            }

            if (result == null || result.Video == null || string.IsNullOrEmpty(result.Video.Title))
            {
                return(VideoTitleParseResult.CreateError("Vimeo (error): title element not found"));
            }

            var author   = result.Video.User_Name;
            var thumbUrl = result.Video.Thumbnail_Small;
            var length   = result.Video.Duration;
            var date     = Convert.ToDateTime(result.Video.Upload_Date);         // xmlserializer can't parse the date

            return(VideoTitleParseResult.CreateSuccess(result.Video.Title, author, null, thumbUrl, length, uploadDate: date));
        }
Example #7
0
        public static VideoTitleParseResult ParseResponse(NicoResponse nicoResponse)
        {
            if (nicoResponse.Status == "fail")
            {
                var err = (nicoResponse.Error != null ? nicoResponse.Error.Description : "empty response");
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + err));
            }

            var title       = HtmlEntity.DeEntitize(nicoResponse.Thumb.Title);
            var thumbUrl    = nicoResponse.Thumb.Thumbnail_Url ?? string.Empty;
            var userId      = nicoResponse.Thumb.User_Id ?? string.Empty;
            var length      = ParseLength(nicoResponse.Thumb.Length);
            var author      = nicoResponse.Thumb.User_Nickname;
            var publishDate = DateTimeHelper.ParseDateTimeOffsetAsDate(nicoResponse.Thumb.First_Retrieve);

            if (string.IsNullOrEmpty(author))
            {
                author = GetUserName(userId);
            }

            var tagMapping  = nicoTagMappingFactory.GetMappings();
            var matchedTags = nicoResponse.Thumb.Tags
                              .Where(e => tagMapping.ContainsKey(e))
                              .Select(e => tagMapping[e])
                              .ToArray();

            var result = VideoTitleParseResult.CreateSuccess(title, author, thumbUrl, length, uploadDate: publishDate);

            result.AuthorId = userId;
            result.Tags     = matchedTags;

            return(result);
        }
Example #8
0
        public VideoTitleParseResult GetTitle(string id)
        {
            var url = string.Format("http://vimeo.com/api/v2/video/{0}.xml", id);

            var         request = WebRequest.Create(url);
            WebResponse response;

            try {
                response = request.GetResponse();
            } catch (WebException x) {
                return(VideoTitleParseResult.CreateError("Vimeo (error): " + x.Message));
            }

            XDocument doc;

            try {
                doc = XDocument.Load(response.GetResponseStream());
            } catch (XmlException x) {
                return(VideoTitleParseResult.CreateError("Vimeo (error): " + x.Message));
            }

            var titleElem = doc.XPathSelectElement("videos/video/title");

            if (titleElem == null)
            {
                return(VideoTitleParseResult.CreateError("Vimeo (error): title element not found"));
            }

            var author   = XmlHelper.GetNodeTextOrEmpty(doc, "videos/video/user_name");
            var thumbUrl = XmlHelper.GetNodeTextOrEmpty(doc, "videos/video/thumbnail_small");

            return(VideoTitleParseResult.CreateSuccess(titleElem.Value, author, thumbUrl));
        }
Example #9
0
        public override async Task <VideoUrlParseResult> ParseByUrlAsync(string url, bool getTitle)
        {
            var youtubeDl = new YoutubeDL {
                RetrieveAllInfo = true,
                YoutubeDlPath   = GetPath(AppConfig.YoutubeDLPath),
                PythonPath      = GetPath(AppConfig.PythonPath)
            };

            youtubeDl.StandardOutputEvent += StandardOutputEvent;
            youtubeDl.StandardErrorEvent  += StandardErrorEvent;

            DownloadInfo result;

            try {
                var task = youtubeDl.GetDownloadInfoAsync(url);
                result = await TimeoutAfter(task, 10000);
            } catch (TaskCanceledException) {
                var warnings = GetErrorString(youtubeDl.Info);
                _log.Error("Timeout. Error list: {0}", warnings);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Timeout"));
            } catch (TimeoutException) {
                youtubeDl.CancelDownload();
                _log.Error("Timeout");
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Timeout"));
            }

            if (result == null)
            {
                var warnings = GetErrorString(youtubeDl.Info);
                _log.Error("Result from parser is empty. Error list: {0}", warnings);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Result from parser is empty"));
            }

            if (!(result is VideoDownloadInfo info))
            {
                var warnings = GetErrorString(youtubeDl.Info);
                _log.Error("Unexpected result from parser. Error list: {0}. Result type is {1}. Title is {2}", warnings, result.GetType().Name, result.Title);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Unexpected result from parser."));
            }

            DateTime?date = null;

            if (DateTime.TryParseExact(info.UploadDate, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var parsedDate))
            {
                date = parsedDate;
            }

            var bandcampMetadata = new PVExtendedMetadata(new BandcampMetadata {
                Url = info.WebpageUrl
            });

            var meta = VideoTitleParseResult.CreateSuccess(info.Title, info.Uploader, info.UploaderId, info.Thumbnail, (int?)info.Duration, uploadDate: date, extendedMetadata: bandcampMetadata);

            return(VideoUrlParseResult.CreateOk(url, PVService.Bandcamp, info.Id, meta));
        }
Example #10
0
        public override VideoUrlParseResult ParseByUrl(string url, bool getTitle)
        {
            var id = GetIdByUrl(url);

            if (string.IsNullOrEmpty(id))
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.NoMatcher, "No matcher"));
            }

            var paramStr    = string.Format("appkey={0}&id={1}&type=xml{2}", AppConfig.BilibiliAppKey, id, AppConfig.BilibiliSecretKey);
            var paramStrMd5 = CryptoHelper.HashString(paramStr, CryptoHelper.MD5).ToLowerInvariant();

            var requestUrl = string.Format("https://api.bilibili.com/view?appkey={0}&id={1}&type=xml&sign={2}", AppConfig.BilibiliAppKey, id, paramStrMd5);

            var request = (HttpWebRequest)WebRequest.Create(requestUrl);

            request.UserAgent = "VocaDB/1.0 ([email protected])";
            request.Timeout   = 10000;
            XDocument doc;

            try {
                using (var response = request.GetResponse())
                    using (var stream = response.GetResponseStream()) {
                        doc = XDocument.Load(stream);
                    }
            } catch (WebException x) {
                log.Warn(x, "Unable to load Bilibili URL {0}", url);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, new VideoParseException(string.Format("Unable to load Bilibili URL: {0}", x.Message), x)));
            } catch (XmlException x) {
                log.Warn(x, "Unable to load Bilibili URL {0}", url);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, new VideoParseException(string.Format("Unable to load Bilibili URL: {0}", x.Message), x)));
            } catch (IOException x) {
                log.Warn(x, "Unable to load Bilibili URL {0}", url);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, new VideoParseException(string.Format("Unable to load Bilibili URL: {0}", x.Message), x)));
            }

            var titleElem   = doc.XPathSelectElement("/info/title");
            var thumbElem   = doc.XPathSelectElement("/info/pic");
            var authorElem  = doc.XPathSelectElement("/info/author");
            var createdElem = doc.XPathSelectElement("/info/created_at");

            if (titleElem == null)
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "No title element"));
            }

            var title   = HtmlEntity.DeEntitize(titleElem.Value);
            var thumb   = thumbElem != null ? thumbElem.Value : string.Empty;
            var author  = authorElem != null ? authorElem.Value : string.Empty;
            var created = createdElem != null ? (DateTime?)DateTime.Parse(createdElem.Value) : null;

            return(VideoUrlParseResult.CreateOk(url, PVService.Bilibili, id,
                                                VideoTitleParseResult.CreateSuccess(title, author, thumb, uploadDate: created)));
        }
Example #11
0
        private VideoUrlParseResult(string url, PVService service, string id, VideoTitleParseResult meta)
        {
            Url      = url;
            Service  = service;
            Id       = id;
            Title    = meta.Title ?? string.Empty;
            Author   = meta.Author ?? string.Empty;
            ThumbUrl = meta.ThumbUrl ?? string.Empty;

            ResultType = VideoUrlParseResultType.Ok;
        }
Example #12
0
        public static async Task <VideoTitleParseResult> GetTitleAPIAsync(string id)
        {
            VideoDataResult result;

            try {
                result = await new NicoApiClient(HtmlEntity.DeEntitize).GetTitleAPIAsync(id);
            } catch (NicoApiException x) {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + x.Message));
            }
            return(ParseResponse(result));
        }
        private VideoUrlParseResult(string url, PVService service, string id, VideoTitleParseResult meta)
        {
            Url = url;
            Service = service;
            Id = id;
            Title = meta.Title ?? string.Empty;
            Author = meta.Author ?? string.Empty;
            ThumbUrl = meta.ThumbUrl ?? string.Empty;

            ResultType = VideoUrlParseResultType.Ok;
        }
Example #14
0
        public override VideoTitleParseResult GetVideoTitle(string id)
        {
            Uri    uri;
            string name = string.Empty;

            if (Uri.TryCreate(id, UriKind.Absolute, out uri))
            {
                name = HttpUtility.UrlDecode(uri.Segments.Last());
            }

            return(VideoTitleParseResult.CreateSuccess(name, string.Empty, string.Empty, string.Empty));
        }
Example #15
0
        public VideoTitleParseResult GetTitle(string id)
        {
            YoutubeVideoResponse result;

            try {
                result = service.Video(id);
            } catch (WebException x) {
                return(VideoTitleParseResult.CreateError(x.Message));
            }

            return(GetTitle(result));
        }
Example #16
0
        public async Task <VideoTitleParseResult> GetTitleAsync(string id)
        {
            YoutubeVideoResponse result;

            try {
                result = await service.VideoAsync(id);
            } catch (HttpRequestException x) {
                return(VideoTitleParseResult.CreateError(x.Message));
            }

            return(GetTitle(result));
        }
Example #17
0
        private VideoTitleParseResult ParseDocument(HtmlDocument doc, string url)
        {
            var title = doc.DocumentNode.SelectSingleNode("//meta[@name = 'twitter:title']")?.Attributes["content"]?.Value;

            title = !string.IsNullOrEmpty(title) ? title.Substring(0, title.Length - 1) : title;
            var thumb  = doc.DocumentNode.SelectSingleNode("//meta[@name = 'twitter:image']")?.Attributes["content"]?.Value;
            var length = ParseLength(doc.DocumentNode.SelectSingleNode("//p[contains(@class, 'dummy_current_time_label')]")?.InnerText.Trim());
            var date   = ParseDate(doc.DocumentNode.SelectSingleNode("//div[@class = 'audio-main-content-info-heading']")?.InnerText);
            var author = doc.DocumentNode.SelectSingleNode("//a[@class = 'user-info-icon']")?.Attributes["title"]?.Value;             // <a class="user-info-icon" title="ERIGON" href="/erigon">

            return(VideoTitleParseResult.CreateSuccess(title, author, null, thumb, length, uploadDate: date));
        }
Example #18
0
        public override async Task <VideoUrlParseResult> ParseByUrlAsync(string url, bool getTitle)
        {
            var id = GetIdByUrl(url);

            if (string.IsNullOrEmpty(id))
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.NoMatcher, "No matcher"));
            }

            var requestUrl = "https://api.bilibili.com/x/web-interface/view?" + (id.StartsWith("BV") ? $"bvid={id}" : $"aid={id}");

            BilibiliResponse response;

            try {
                response = await JsonRequest.ReadObjectAsync <BilibiliResponse>(requestUrl, timeout : TimeSpan.FromSeconds(10), userAgent : "VocaDB/1.0 ([email protected])");
            } catch (Exception x) when(x is HttpRequestException || x is WebException || x is JsonSerializationException || x is IOException)
            {
                log.Warn(x, "Unable to load Bilibili URL {0}", url);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, new VideoParseException(string.Format("Unable to load Bilibili URL: {0}", x.Message), x)));
            }

            var authorId = response.Data.Owner.Mid.ToString();
            var aid      = response.Data.Aid;
            var bvid     = response.Data.Bvid;
            var cid      = response.Data.Cid;

            if (!getTitle)
            {
                return(VideoUrlParseResult.CreateOk(url, PVService.Bilibili, aid.ToString(), VideoTitleParseResult.Empty));
            }

            if (string.IsNullOrEmpty(response.Data.Title))
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "No title element"));
            }

            var title   = HtmlEntity.DeEntitize(response.Data.Title);
            var thumb   = response.Data.Pic ?? string.Empty;
            var author  = response.Data.Owner.Name ?? string.Empty;
            var created = response.Data.PubDate;
            var length  = response.Data.Duration;

            var metadata = new PVExtendedMetadata(new BiliMetadata {
                Aid  = aid,
                Bvid = bvid,
                Cid  = cid
            });

            return(VideoUrlParseResult.CreateOk(url, PVService.Bilibili, aid.ToString(),
                                                VideoTitleParseResult.CreateSuccess(title, author, authorId, thumb, length: length, uploadDate: created, extendedMetadata: metadata)));
        }
Example #19
0
        public VideoTitleParseResult GetTitle(string id)
        {
            var settings      = new YouTubeRequestSettings("VocaDB", null);
            var request       = new YouTubeRequest(settings);
            var videoEntryUrl = new Uri(string.Format("http://gdata.youtube.com/feeds/api/videos/{0}", id));

            try {
                var video    = request.Retrieve <Video>(videoEntryUrl);
                var thumbUrl = video.Thumbnails.Count > 0 ? video.Thumbnails[0].Url : string.Empty;
                return(VideoTitleParseResult.CreateSuccess(video.Title, video.Author, thumbUrl));
            } catch (Exception x) {
                return(VideoTitleParseResult.CreateError(x.Message));
            }
        }
        private VideoUrlParseResult Parse(PostQueryResult result, string url)
        {
            if (result.PostType != PostType.Audio)
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, new VideoParseException("Content type indicates this isn't an audio post")));
            }

            var piaproMetadata = new PVExtendedMetadata(new PiaproMetadata {
                Timestamp = result.UploadTimestamp
            });

            return(VideoUrlParseResult.CreateOk(url, PVService.Piapro, result.Id,
                                                VideoTitleParseResult.CreateSuccess(result.Title, result.Author, result.AuthorId, result.ArtworkUrl, result.LengthSeconds, uploadDate: result.Date, extendedMetadata: piaproMetadata)));
        }
Example #21
0
        public static async Task <VideoTitleParseResult> GetTitleAPIAsync(string id)
        {
            var url = string.Format("https://ext.nicovideo.jp/api/getthumbinfo/{0}", id);

            NicoResponse nicoResponse;

            try {
                nicoResponse = await XmlRequest.GetXmlObjectAsync <NicoResponse>(url);
            } catch (HttpRequestException x) {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + x.Message));
            }

            return(ParseResponse(nicoResponse));
        }
Example #22
0
        private VideoUrlParseResult(string url, PVService service, string id, VideoTitleParseResult meta)
        {
            Url           = url;
            Service       = service;
            Id            = id;
            Title         = meta.Title ?? string.Empty;
            Author        = meta.Author ?? string.Empty;
            AuthorId      = meta.AuthorId ?? string.Empty;
            ThumbUrl      = meta.ThumbUrl ?? string.Empty;
            LengthSeconds = meta.LengthSeconds;
            Tags          = meta.Tags;
            UploadDate    = meta.UploadDate;

            ResultType = VideoUrlParseResultType.Ok;
        }
Example #23
0
        private VideoTitleParseResult GetTitle(YoutubeVideoResponse result)
        {
            if (!result.Items.Any())
            {
                return(VideoTitleParseResult.Empty);
            }

            var video       = result.Items.First();
            var thumbUrl    = video.Snippet.Thumbnails.Default != null ? video.Snippet.Thumbnails.Default.Url : string.Empty;
            var length      = GetLength(video);
            var author      = video.Snippet.ChannelTitle;
            var authorId    = video.Snippet.ChannelId;
            var publishDate = GetPublishDate(video);

            return(VideoTitleParseResult.CreateSuccess(video.Snippet.Title, author, authorId, thumbUrl, length, uploadDate: publishDate));
        }
Example #24
0
        public static VideoTitleParseResult ParseResponse(VideoDataResult nicoResponse)
        {
            string author = nicoResponse.Author;
            string userId = nicoResponse.AuthorId;

            if (string.IsNullOrEmpty(author))
            {
                author = GetUserName(userId);
            }

            var result = VideoTitleParseResult.CreateSuccess(nicoResponse.Title, author, userId, nicoResponse.ThumbUrl, nicoResponse.LengthSeconds, uploadDate: nicoResponse.UploadDate?.Date);

            result.Tags = nicoResponse.Tags.Select(tag => tag.Name).ToArray();

            return(result);
        }
Example #25
0
        public static VideoTitleParseResult GetTitleAPI(string id)
        {
            var url = string.Format("http://ext.nicovideo.jp/api/getthumbinfo/{0}", id);

            var         request = WebRequest.Create(url);
            WebResponse response;

            try {
                response = request.GetResponse();
            } catch (WebException x) {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + x.Message));
            }

            XDocument doc;

            try {
                using (var stream = response.GetResponseStream()) {
                    doc = XDocument.Load(stream);
                }
            } catch (XmlException x) {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + x.Message));
            }

            var res = doc.Element("nicovideo_thumb_response");

            if (res == null || res.Attribute("status") == null || res.Attribute("status").Value == "fail")
            {
                var err = (res != null ? res.XPathSelectElement("//nicovideo_thumb_response/error/description").Value : "empty response");
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + err));
            }

            var titleElem = doc.XPathSelectElement("//nicovideo_thumb_response/thumb/title");

            if (titleElem == null)
            {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): title element not found"));
            }

            var title    = HtmlEntity.DeEntitize(titleElem.Value);
            var thumbUrl = XmlHelper.GetNodeTextOrEmpty(doc, "//nicovideo_thumb_response/thumb/thumbnail_url");
            var userId   = XmlHelper.GetNodeTextOrEmpty(doc, "//nicovideo_thumb_response/thumb/user_id");
            var author   = GetUserName(userId);

            return(VideoTitleParseResult.CreateSuccess(title, author, thumbUrl));
        }
Example #26
0
        public override VideoUrlParseResult ParseByUrl(string url, bool getTitle)
        {
            PostQueryResult result;

            try {
                result = new PiaproClient.PiaproClient().ParseByUrl(url);
            } catch (PiaproException x) {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, new VideoParseException(x.Message, x)));
            }

            if (result.PostType != PostType.Audio)
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, new VideoParseException("Content type indicates this isn't an audio post")));
            }

            return(VideoUrlParseResult.CreateOk(url, PVService.Piapro, result.Id,
                                                VideoTitleParseResult.CreateSuccess(result.Title, result.Author, string.Empty, result.LengthSeconds, uploadDate: result.Date)));
        }
Example #27
0
        public override async Task <VideoUrlParseResult> ParseByUrlAsync(string url, bool getTitle)
        {
            var extractor = new BandcampMetadataClient();
            var info      = await extractor.ExtractAsync(url);

            DateTime?date = null;

            if (DateTime.TryParseExact(info.UploadDate, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var parsedDate))
            {
                date = parsedDate;
            }

            var bandcampMetadata = new PVExtendedMetadata(new BandcampMetadata
            {
                Url = info.WebpageUrl
            });

            var meta = VideoTitleParseResult.CreateSuccess(info.Title, info.Uploader, info.UploaderId, info.Thumbnail, (int?)info.Duration, uploadDate: date, extendedMetadata: bandcampMetadata);

            return(VideoUrlParseResult.CreateOk(url, PVService.Bandcamp, info.Id, meta));
        }
Example #28
0
        public override VideoUrlParseResult ParseByUrl(string url, bool getTitle)
        {
            var id = GetIdByUrl(url);

            if (string.IsNullOrEmpty(id))
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.NoMatcher, "No matcher"));
            }

            var requestUrl = string.Format("http://api.bilibili.tv/view?type=xml&appkey={0}&id={1}", AppConfig.BilibiliAppKey, id);

            var       request = WebRequest.Create(requestUrl);
            XDocument doc;

            try {
                using (var response = request.GetResponse())
                    using (var stream = response.GetResponseStream()) {
                        doc = XDocument.Load(stream);
                    }
            } catch (WebException x) {
                log.WarnException("Unable to load Bilibili URL " + url, x);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, new VideoParseException("Unable to load Bilibili URL: " + x.Message, x)));
            }

            var titleElem  = doc.XPathSelectElement("/info/title");
            var thumbElem  = doc.XPathSelectElement("/info/pic");
            var authorElem = doc.XPathSelectElement("/info/author");

            if (titleElem == null)
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "No title element"));
            }

            var title  = HtmlEntity.DeEntitize(titleElem.Value);
            var thumb  = thumbElem != null ? thumbElem.Value : string.Empty;
            var author = authorElem != null ? authorElem.Value : string.Empty;

            return(VideoUrlParseResult.CreateOk(url, PVService.Bilibili, id,
                                                VideoTitleParseResult.CreateSuccess(title, author, thumb)));
        }
Example #29
0
        /*public override string GetUrlById(string id) {
         *
         *      var compositeId = new CompositeId(id);
         *      var matcher = linkMatchers.First();
         *      return "http://" + matcher.MakeLinkFromId(compositeId.SoundCloudUrl);
         *
         * }*/

        private VideoUrlParseResult ParseByHtmlStream(Stream htmlStream, Encoding encoding, string url)
        {
            var doc = new HtmlDocument();

            doc.Load(htmlStream, encoding);

            var catLink = doc.DocumentNode.SelectSingleNode("//div[@class = 'dtl_data']/p[3]");

            if (catLink == null || !catLink.InnerHtml.Contains("/illust/?categoryId=1"))
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Content type indicates this isn't an audio file."));
            }

            var idElem = doc.DocumentNode.SelectSingleNode("//input[@name = 'id']");

            if (idElem == null)
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Could not find id element on page."));
            }

            var contentId = idElem.GetAttributeValue("value", string.Empty);

            var titleElem = doc.DocumentNode.SelectSingleNode("//h1[@class = 'dtl_title']");

            if (titleElem == null)
            {
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Could not find title element on page."));
            }

            var title = HtmlEntity.DeEntitize(titleElem.InnerText).Trim();

            var authorElem = doc.DocumentNode.SelectSingleNode("//div[@class = 'dtl_by_name']/a");
            var author     = (authorElem != null ? authorElem.InnerText : string.Empty);

            return(VideoUrlParseResult.CreateOk(url, PVService.Piapro, contentId, VideoTitleParseResult.CreateSuccess(title, author, string.Empty)));
        }
Example #30
0
 public static VideoUrlParseResult CreateOk(string url, PVService service, string id, VideoTitleParseResult meta)
 {
     return(new VideoUrlParseResult(url, service, id, meta));
 }
Example #31
0
        public static VideoTitleParseResult GetTitleAPI(string id)
        {
            var url = string.Format("http://ext.nicovideo.jp/api/getthumbinfo/{0}", id);

            var request = WebRequest.Create(url);

            request.Timeout = 10000;

            XDocument doc;

            try {
                using (var response = request.GetResponse())
                    using (var stream = response.GetResponseStream()) {
                        doc = XDocument.Load(stream);
                    }
            } catch (WebException x) {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + x.Message));
            } catch (XmlException x) {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + x.Message));
            } catch (IOException x) {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + x.Message));
            }

            var res = doc.Element("nicovideo_thumb_response");

            if (res == null || res.Attribute("status") == null || res.Attribute("status").Value == "fail")
            {
                var err = (res != null ? res.XPathSelectElement("//nicovideo_thumb_response/error/description").Value : "empty response");
                return(VideoTitleParseResult.CreateError("NicoVideo (error): " + err));
            }

            var titleElem = doc.XPathSelectElement("//nicovideo_thumb_response/thumb/title");

            if (titleElem == null)
            {
                return(VideoTitleParseResult.CreateError("NicoVideo (error): title element not found"));
            }

            var title    = HtmlEntity.DeEntitize(titleElem.Value);
            var thumbUrl = XmlHelper.GetNodeTextOrEmpty(doc, "//nicovideo_thumb_response/thumb/thumbnail_url");
            var userId   = XmlHelper.GetNodeTextOrEmpty(doc, "//nicovideo_thumb_response/thumb/user_id");
            var length   = ParseLength(XmlHelper.GetNodeTextOrEmpty(doc, "//nicovideo_thumb_response/thumb/length"));
            var author   = XmlHelper.GetNodeTextOrEmpty(doc, "//nicovideo_thumb_response/thumb/user_nickname");

            if (string.IsNullOrEmpty(author))
            {
                author = GetUserName(userId);
            }

            var tagMapping   = nicoTagMappingFactory.GetMappings();
            var nodeElements = doc.XPathSelectElements("//nicovideo_thumb_response/thumb/tags/tag");
            var matchedTags  = nodeElements
                               .Where(e => tagMapping.ContainsKey(e.Value))
                               .Select(e => tagMapping[e.Value])
                               .ToArray();

            var result = VideoTitleParseResult.CreateSuccess(title, author, thumbUrl, length);

            result.AuthorId = userId;
            result.Tags     = matchedTags;

            return(result);
        }
 public static VideoUrlParseResult CreateOk(string url, PVService service, string id, VideoTitleParseResult meta)
 {
     return new VideoUrlParseResult(url, service, id, meta);
 }