本文整理汇总了C#中SessionEventArgs.GetResponseBodyAsString方法的典型用法代码示例。如果您正苦于以下问题:C# SessionEventArgs.GetResponseBodyAsString方法的具体用法?C# SessionEventArgs.GetResponseBodyAsString怎么用?C# SessionEventArgs.GetResponseBodyAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SessionEventArgs
的用法示例。
在下文中一共展示了SessionEventArgs.GetResponseBodyAsString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnResponse
// When we receive the result, we need to check if it needs to be modified.
private static void OnResponse(object sender, SessionEventArgs e)
{
if (e.ResponseStatusCode == HttpStatusCode.OK)
{
// Most APIs are returned in text/plain but serach songs page is returned in JSON. Don't forget this!
if (e.ResponseContentType.Trim().ToLower().Contains("text/plain") ||
e.ResponseContentType.Trim().ToLower().Contains("application/json"))
{
if (Configuration.Verbose)
{
Console.WriteLine($"Accessing URL {e.RequestUrl}");
}
// It should include album / playlist / artist / search pages.
if (e.RequestUrl.Contains("/eapi/v3/song/detail/") || e.RequestUrl.Contains("/eapi/v1/album/") || e.RequestUrl.Contains("/eapi/v3/playlist/detail") ||
e.RequestUrl.Contains("/eapi/batch") || e.RequestUrl.Contains("/eapi/cloudsearch/pc") || e.RequestUrl.Contains("/eapi/v1/artist"))
{
string modified = ModifyDetailApi(e.GetResponseBodyAsString());
e.SetResponseBodyString(modified);
}
// This is called when player tries to get the URL for a song.
else if (e.RequestUrl.Contains("/eapi/song/enhance/player/url"))
{
if (string.IsNullOrEmpty(Configuration.ForcePlaybackBitrate))
{
SetPlaybackMusicQuality(e.GetResponseBodyAsString());
}
else
{
Console.WriteLine($"Plackback bitrate is forced set to {Configuration.ForcePlaybackBitrate}");
Configuration.PlaybackBitrate = Configuration.ForcePlaybackBitrate;
Configuration.PlaybackQuality = ParseBitrate(Configuration.ForcePlaybackBitrate);
}
string modified = ModifyPlayerApi(e.GetResponseBodyAsString());
e.SetResponseBodyString(modified);
}
// When we try to download a song, the API tells whether it exceeds the limit. Of course no!
else if (e.RequestUrl.Contains("/eapi/song/download/limit"))
{
string modified = ModifyDownloadLimitApi();
e.SetResponseBodyString(modified);
}
// Similar to the player URL API, but used for download.
else if (e.RequestUrl.Contains("/eapi/song/enhance/download/url"))
{
string modified = e.GetResponseBodyAsString();
if (string.IsNullOrEmpty(Configuration.ForceDownloadBitrate))
{
SetDownloadMusicQuality(modified);
}
else
{
Console.WriteLine($"Download bitrate is forced set to {Configuration.ForceDownloadBitrate}");
Configuration.DownloadBitrate = Configuration.ForceDownloadBitrate;
Configuration.DownloadQuality = ParseBitrate(Configuration.ForceDownloadBitrate);
}
modified = ModifyDownloadApi(modified);
e.SetResponseBodyString(modified);
}
}
}
}