fix iqiyi

This commit is contained in:
cxfksword
2024-04-30 22:36:01 +08:00
parent 3120675d98
commit 7e2b62de3e
6 changed files with 79 additions and 69 deletions

View File

@@ -30,7 +30,7 @@ namespace Jellyfin.Plugin.Danmu.Test
{
try
{
var keyword = "与凤行";
var keyword = "又见逍遥";
var result = await api.SearchAsync(keyword, CancellationToken.None);
Console.WriteLine(result);
}
@@ -51,8 +51,8 @@ namespace Jellyfin.Plugin.Danmu.Test
{
try
{
// var id = "25f5iplvm8s"; // 综艺
var id = "xkt6z3z798"; // 电视剧
var id = "25f5iplvm8s"; // 综艺
// var id = "19tfhh8axvc"; // 电视剧
// var id = "1e54n0pt5ro"; // 电影
var result = await api.GetVideoAsync(id, CancellationToken.None);
Console.WriteLine(result);
@@ -73,7 +73,7 @@ namespace Jellyfin.Plugin.Danmu.Test
{
try
{
var albumId = "7765466759502501";
var albumId = "252894801";
var result = await api.GetZongyiEpisodesAsync(albumId, CancellationToken.None);
Console.WriteLine(result);
}
@@ -125,5 +125,6 @@ namespace Jellyfin.Plugin.Danmu.Test
}).GetAwaiter().GetResult();
}
}
}

View File

@@ -175,5 +175,28 @@ namespace Jellyfin.Plugin.Danmu.Test
}).GetAwaiter().GetResult();
}
[TestMethod]
public void TestGetEpisodesForApi()
{
var api = new Iqiyi(loggerFactory);
Task.Run(async () =>
{
try
{
var id = "25f5iplvm8s"; // 综艺
// var id = "19tfhh8axvc"; // 电视剧
// var id = "1e54n0pt5ro"; // 电影
var result = await api.GetEpisodesForApi(id);
Console.WriteLine(result);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}).GetAwaiter().GetResult();
}
}
}

View File

@@ -1,24 +0,0 @@
using System.Text.RegularExpressions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace Jellyfin.Plugin.Danmu.Scrapers.Iqiyi.Entity
{
public class IqiyiHtmlAlbumInfo
{
[JsonPropertyName("qipuId")]
public Int64 AlbumId { get; set; }
[JsonPropertyName("albumName")]
public string AlbumName { get; set; }
[JsonPropertyName("albumPageUrl")]
public string AlbumUrl { get; set; }
[JsonPropertyName("videoCount")]
public int VideoCount { get; set; }
}
}

View File

@@ -1,10 +1,6 @@
using System.Text.RegularExpressions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace Jellyfin.Plugin.Danmu.Scrapers.Iqiyi.Entity
{
@@ -12,26 +8,24 @@ namespace Jellyfin.Plugin.Danmu.Scrapers.Iqiyi.Entity
{
private static readonly Regex regLinkId = new Regex(@"v_(\w+?)\.html", RegexOptions.Compiled);
[JsonPropertyName("albumQipuId")]
public Int64 AlbumId { get; set; }
[JsonPropertyName("tvid")]
public Int64 TvId { get; set; }
[JsonPropertyName("videoName")]
public String VideoName { get; set; }
[JsonPropertyName("videoUrl")]
public String VideoUrl { get; set; }
[JsonPropertyName("channelName")]
public string ChannelName { get; set; }
[JsonPropertyName("duration")]
[JsonPropertyName("albumId")]
public long AlbumId { get; set; }
[JsonPropertyName("tvId")]
public long TvId { get; set; }
[JsonPropertyName("name")]
public string VideoName { get; set; }
[JsonPropertyName("playUrl")]
public string VideoUrl { get; set; }
[JsonPropertyName("channelId")]
public int channelId { get; set; }
[JsonPropertyName("durationSec")]
public int Duration { get; set; }
[JsonPropertyName("videoCount")]
public int VideoCount { get; set; }
[JsonIgnore]
public List<IqiyiEpisode> Epsodelist { get; set; }
[JsonIgnore]
public IqiyiHtmlAlbumInfo? AlbumInfo { get; set; }
[JsonIgnore]
public string LinkId
{
@@ -49,5 +43,30 @@ namespace Jellyfin.Plugin.Danmu.Scrapers.Iqiyi.Entity
}
}
[JsonIgnore]
public string ChannelName
{
get
{
switch (channelId)
{
case 1:
return "电影";
case 2:
return "电视剧";
case 3:
return "纪录片";
case 4:
return "动漫";
case 6:
return "综艺";
case 15:
return "儿童";
default:
return string.Empty;
}
}
}
}
}

View File

@@ -134,7 +134,7 @@ public class Iqiyi : AbstractScraper
{
foreach (var ep in video.Epsodelist)
{
media.Episodes.Add(new ScraperEpisode() { Id = $"{ep.LinkId}", CommentId = $"{ep.TvId}" });
media.Episodes.Add(new ScraperEpisode() { Id = $"{ep.LinkId}", CommentId = $"{ep.TvId}", Title = ep.Name });
}
}
@@ -156,7 +156,7 @@ public class Iqiyi : AbstractScraper
return null;
}
return new ScraperEpisode() { Id = id, CommentId = $"{video.TvId}" };
return new ScraperEpisode() { Id = id, CommentId = $"{video.TvId}", Title = video.VideoName };
}
public override async Task<ScraperDanmaku?> GetDanmuContent(BaseItem item, string commentId)

View File

@@ -2,22 +2,17 @@ using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using ComposableAsync;
using Jellyfin.Plugin.Danmu.Core.Extensions;
using Jellyfin.Plugin.Danmu.Scrapers.Entity;
using Jellyfin.Plugin.Danmu.Scrapers.Iqiyi.Entity;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using RateLimiter;
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using System.Xml.Serialization;
@@ -25,8 +20,8 @@ namespace Jellyfin.Plugin.Danmu.Scrapers.Iqiyi;
public class IqiyiApi : AbstractApi
{
private new const string HTTP_USER_AGENT = "Mozilla/5.0 (Linux; Android 10; SM-G981B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Mobile Safari/537.36 Edg/115.0.0.0";
private static readonly Regex regVideoInfo = new Regex(@"""videoInfo"":(\{.+?\}),", RegexOptions.Compiled);
private new const string HTTP_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.183";
private static readonly Regex regVideoInfo = new Regex(@"pageProps"":\{""videoInfo"":(\{.+?\}),""featureInfo", RegexOptions.Compiled);
private static readonly Regex regAlbumInfo = new Regex(@"""albumInfo"":(\{.+?\}),", RegexOptions.Compiled);
@@ -104,21 +99,21 @@ public class IqiyiApi : AbstractApi
var videoInfo = await GetVideoBaseAsync(id, cancellationToken).ConfigureAwait(false);
if (videoInfo != null)
{
if (videoInfo.ChannelName == "综艺" && videoInfo.AlbumInfo != null)
if (videoInfo.channelId == 6)
{ // 综艺需要特殊处理
videoInfo.Epsodelist = await this.GetZongyiEpisodesAsync($"{videoInfo.AlbumInfo.AlbumId}", cancellationToken).ConfigureAwait(false);
videoInfo.Epsodelist = await this.GetZongyiEpisodesAsync($"{videoInfo.AlbumId}", cancellationToken).ConfigureAwait(false);
}
else if (videoInfo.ChannelName != "电影" && videoInfo.AlbumInfo != null)
{ // 电视剧需要再获取剧集信息
videoInfo.Epsodelist = await this.GetEpisodesAsync($"{videoInfo.AlbumId}", videoInfo.AlbumInfo.VideoCount, cancellationToken).ConfigureAwait(false);
}
else if (videoInfo.ChannelName == "电影")
else if (videoInfo.channelId == 1)
{ // 电影
var duration = new TimeSpan(0, 0, videoInfo.Duration);
videoInfo.Epsodelist = new List<IqiyiEpisode>() {
new IqiyiEpisode() {TvId = videoInfo.TvId, Order = 1, Name = videoInfo.VideoName, Duration = duration.ToString(@"hh\:mm\:ss"), PlayUrl = videoInfo.VideoUrl}
};
}
else
{ // 电视剧需要再获取剧集信息
videoInfo.Epsodelist = await this.GetEpisodesAsync($"{videoInfo.AlbumId}", videoInfo.VideoCount, cancellationToken).ConfigureAwait(false);
}
_memoryCache.Set<IqiyiHtmlVideoInfo?>(cacheKey, videoInfo, expiredOption);
return videoInfo;
@@ -144,7 +139,7 @@ public class IqiyiApi : AbstractApi
await this.LimitRequestFrequently();
var url = $"https://m.iqiyi.com/v_{id}.html";
var url = $"https://www.iqiyi.com/v_{id}.html";
var response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
@@ -153,13 +148,9 @@ public class IqiyiApi : AbstractApi
var videoInfo = videoJson.FromJson<IqiyiHtmlVideoInfo>();
if (videoInfo != null)
{
var albumJson = regAlbumInfo.FirstMatchGroup(body);
videoInfo.AlbumInfo = albumJson.FromJson<IqiyiHtmlAlbumInfo>();
_memoryCache.Set<IqiyiHtmlVideoInfo?>(cacheKey, videoInfo, expiredOption);
this._memoryCache.Set(cacheKey, videoInfo, expiredOption);
return videoInfo;
}
_memoryCache.Set<IqiyiHtmlVideoInfo?>(cacheKey, null, expiredOption);
return null;
}