public static async Task <string> GetCommentDataAsync(NiconicoContext context, int userId, string commentServerUrl, int threadId, bool isKeyRequired) { var paramDict = new Dictionary <string, string>(); paramDict.Add("user_id", userId is 0 ? "" : userId.ToString()); paramDict.Add("version", "20090904"); paramDict.Add("thread", threadId.ToString()); paramDict.Add("res_from", "-1000"); // 公式動画の場合はThreadKeyとforce_184を取得する if (isKeyRequired) { var threadKeyResponse = await GetThreadKeyDataAsync(context, threadId) .ContinueWith(prevTask => ParseThreadKey(prevTask.Result)); if (threadKeyResponse != null) { paramDict.Add("threadkey", threadKeyResponse.ThreadKey); paramDict.Add("force_184", threadKeyResponse.Force184); } } var param = HttpQueryExtention.DictionaryToQuery(paramDict); var commentUrl = $"{commentServerUrl}thread?{Uri.EscapeUriString(param)}"; return(await context.GetStringAsync(commentUrl)); }
public static async Task <string> GetDmcWatchResponseDataAsync(NiconicoContext context, string requestId) { if (!NiconicoRegex.IsVideoId(requestId)) { // throw new ArgumentException(); } var dict = new Dictionary <string, string>(); var url = $"{NiconicoUrls.VideoWatchPageUrl}{requestId}"; url += "?" + HttpQueryExtention.DictionaryToQuery(dict); try { var message = new HttpRequestMessage(HttpMethod.Get, new Uri(url)); var res = await context.SendAsync(message); if (res.ReasonPhrase == "Forbidden") { throw new WebException("require payment."); } var text = await res.Content.ReadAsStringAsync(); return(text); } catch (Exception e) { throw new WebException("access failed watch/" + requestId, e); } }
static async Task <RssVideoResponse> Internal_GetHotTopicRankingRssWithKeyAsync(string key, RankingTerm term) { if (!IsHotTopicAcceptTerm(term)) { throw new ArgumentOutOfRangeException($"out of range {nameof(RankingTerm)}. accept with {string.Join(" or ", Constants.HotTopicAccepteRankingTerms)}."); } var dict = new Dictionary <string, string>() { { "rss", "2.0" }, { "lang", "ja-jp" } }; dict.Add(nameof(key), Uri.EscapeDataString(key)); dict.Add(nameof(term), term.GetDescription()); try { return(await VideoRssContentHelper.GetRssVideoResponseAsync( $"{Constants.NiconicoRankingHotTopicDomain}?{HttpQueryExtention.DictionaryToQuery(dict)}" )); } catch { return(new RssVideoResponse() { IsOK = false, Items = new List <RssVideoData>() }); } }
public static async Task <RssVideoResponse> GetCommunityVideosAsync(NiconicoContext context, string communityId, uint page) { var dict = new Dictionary <string, string>(); dict.Add("rss", "2.0"); dict.Add(nameof(page), page.ToString()); return(await VideoRssContentHelper.GetRssVideoResponseAsync( $"{NiconicoUrls.CommynityVideoPageUrl}/{communityId}?{HttpQueryExtention.DictionaryToQuery(dict)}" )); }
public static async Task <string> GetRelatedPlaylistDataAsync(NiconicoContext context, string videoId, string referer) { var dict = new Dictionary <string, string>(); dict.Add("watch_id", videoId); dict.Add("referer", referer); dict.Add("continuous", ""); dict.Add("playlist_type", ""); var query = HttpQueryExtention.DictionaryToQuery(dict); return(await context .GetStringAsync($"{NiconicoUrls.VideoPlaylistApiUrl}?{query}")); }
public static string MakeNicoRepoUrl_User(uint userId, string lastTimelineItemId = null) { var dict = new Dictionary <string, string>(); if (lastTimelineItemId != null) { dict.Add("cursor", lastTimelineItemId); } dict.Add("client_app", "pc_profilerepo"); var unixTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(); dict.Add("_", unixTime.ToString()); return($"{NicoRepoTimelineApiUrl}user/{userId.ToString()}?{HttpQueryExtention.DictionaryToQuery(dict)}"); }
public static Task <NicoVideoResponse> GetRelatedVideoAsync(NiconicoContext context, string videoId, uint from, uint limit, Sort sortMethod, Order sortDir) { var dict = new Dictionary <string, string>(); dict.Add("v", videoId); dict.Add(nameof(from), from.ToString()); dict.Add(nameof(limit), limit.ToString()); dict.Add(nameof(sortMethod), sortMethod.ToShortString()); dict.Add(nameof(sortDir), sortDir.ToShortString()); var query = HttpQueryExtention.DictionaryToQuery(dict); return(context .GetJsonAsAsync <NicoVideoResponse>($"{NiconicoUrls.RelatedVideoApiUrl}?{query}")); }
// https://www.nicovideo.jp/api/watch/v3_guest/1615359905?_frontendId=6&_frontendVersion=0&actionTrackId=rV8Nf4Qith_1615871913294&skips=harmful&additionals=pcWatchPage,external,marquee,series&isContinueWatching=true&i18nLanguage=ja-jp&t=1615871919713 // https://www.nicovideo.jp/api/watch/v3/1615359905?_frontendId=6&_frontendVersion=0&actionTrackId=nYQzK4jFdB_1615872059788&skips=harmful&additionals=pcWatchPage,external,marquee,series&isContinueWatching=true&i18nLanguage=ja-jp&t=1615872080318 public static async Task <string> GetDmcWatchJsonDataAsync(NiconicoContext context, string requestId, bool isLoggedIn, string actionTrackId) { if (!NiconicoRegex.IsVideoId(requestId)) { // throw new ArgumentException(); } //bool isLoggedIn = true; var dict = new Dictionary <string, string>(); var url = $"{NiconicoUrls.VideoApiUrlBase}watch/{(isLoggedIn ? "v3" : "v3_guest")}/{requestId}"; dict.Add("_frontendId", "6"); dict.Add("_frontendVersion", "0"); dict.Add("actionTrackId", actionTrackId); dict.Add("skips", "harmful"); dict.Add("additionals", WebUtility.UrlEncode("pcWatchPage,external,marquee,series")); dict.Add("isContinueWatching", "true"); dict.Add("i18nLanguage", "ja-jp"); dict.Add("t", DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString()); url += "?" + HttpQueryExtention.DictionaryToQuery(dict); var requestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri(url)); requestMessage.Headers.Add("Accept", "*/*"); requestMessage.Headers.Referer = new Uri($"https://www.nicovideo.jp/watch/{requestId}"); requestMessage.Headers.Add("Sec-Fetch-Site", "same-origin"); requestMessage.Headers.Host = new Windows.Networking.HostName("www.nicovideo.jp"); try { var res = await context.SendAsync(requestMessage); if (res.ReasonPhrase == "Forbidden") { throw new WebException("require payment."); } var text = await res.Content.ReadAsStringAsync(); return(text); } catch (Exception e) { throw new WebException("access failed watch/" + requestId, e); } }
static async Task <RssVideoResponse> Internal_GetHotTopicRankingRssAsync(RankingTerm term, int page) { if (!IsHotTopicAcceptTerm(term)) { throw new ArgumentOutOfRangeException($"out of range {nameof(RankingTerm)}. accept with {string.Join(" or ", Constants.HotTopicAccepteRankingTerms)}."); } if (page == 0 || page > Constants.MaxPageHotTopic) { throw new ArgumentOutOfRangeException($"out of range {nameof(page)}. inside btw from 1 to {Constants.MaxPageHotTopic} in with tag."); } var dict = new Dictionary <string, string>() { { "rss", "2.0" }, { "lang", "ja-jp" } }; dict.Add(nameof(term), term.GetDescription()); if (page != 1) { dict.Add(nameof(page), page.ToString()); } try { return(await VideoRssContentHelper.GetRssVideoResponseAsync( $"{Constants.NiconicoRankingHotTopicDomain}?{HttpQueryExtention.DictionaryToQuery(dict)}" )); } catch { return(new RssVideoResponse() { IsOK = false, Items = new List <RssVideoData>() }); } }