Skip to content

Commit ca86e4a

Browse files
committed
支持自定义 X-FORWARDED-FOR
1 parent e6e8915 commit ca86e4a

File tree

5 files changed

+67
-5
lines changed

5 files changed

+67
-5
lines changed

Emby.Plugins.JavScraper/Configuration/ConfigPage.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ <h2 class="sectionTitle">JavScraper 配置</h2><span id="current_version" name="
6060
</select>
6161
<div class="selectArrowContainer"><div style="visibility:hidden;">0</div><i class="selectArrow md-icon"></i></div>
6262
</div>
63+
6364
<div id="selectProxyTypeJsProxy" name="selectProxyTypeJsProxy" class="selectProxyTypeJsProxy">
6465
<div class="inputContainer">
6566
<label class="inputLabel inputLabel-float inputLabelUnfocused" for="txtJsProxy">修改版 JsProxy 代理地址:</label>
@@ -99,6 +100,24 @@ <h2 class="sectionTitle">JavScraper 配置</h2><span id="current_version" name="
99100
用户名和密码,可以为空。
100101
</div>
101102
</div>
103+
104+
<br />
105+
<div>
106+
<div class="checkboxContainer checkboxContainer-withDescription">
107+
<label>
108+
<input type="checkbox" is="emby-checkbox" id="chkEnableX_FORWARDED_FOR" />
109+
<span>增加 X-FORWARDED-FOR HTTP 请求头</span>
110+
</label>
111+
<div class="fieldDescription checkboxFieldDescription"></div>
112+
</div>
113+
114+
<div class="inputContainer">
115+
<label class="inputLabel inputLabel-float inputLabelUnfocused" for="txtX_FORWARDED_FOR">X-FORWARDED-FOR IP地址:</label>
116+
<input is="emby-input" id="txtX_FORWARDED_FOR" name="txtX_FORWARDED_FOR" class="emby-input" label="X-FORWARDED-FOR IP地址:">
117+
</div>
118+
119+
<div class="fieldDescription">增加 X-FORWARDED-FOR HTTP 请求头的作用在于伪造来源IP地址,以突破区域限制。常用同一个也可能导致被封锁。这个功能仅部分网站有效。</div>
120+
</div>
102121
</div>
103122
</div>
104123

@@ -434,6 +453,9 @@ <h2 class="sectionTitle">JavScraper 配置</h2><span id="current_version" name="
434453

435454
$('#selectProxyType', page).val(config.ProxyType).change();
436455

456+
page.querySelector('#chkEnableX_FORWARDED_FOR').checked = config.EnableX_FORWARDED_FOR;
457+
$('#txtX_FORWARDED_FOR', page).val(config.X_FORWARDED_FOR).change();
458+
437459
$('#txtIgnoreGenre', page).val(config.IgnoreGenre).change();
438460
page.querySelector('#chkGenreIgnoreActor').checked = config.GenreIgnoreActor;
439461
page.querySelector('#chkTitleIgnoreActor').checked = config.TitleIgnoreActor;
@@ -498,6 +520,9 @@ <h2 class="sectionTitle">JavScraper 配置</h2><span id="current_version" name="
498520
config.ProxyUserName = $('#txtProxyUserName', form).val();
499521
config.ProxyPassword = $('#txtProxyPassword', form).val();
500522

523+
config.EnableX_FORWARDED_FOR = $('#chkEnableX_FORWARDED_FOR').prop('checked');
524+
config.X_FORWARDED_FOR = $('#txtX_FORWARDED_FOR', form).val();
525+
501526
config.IgnoreGenre = $('#txtIgnoreGenre', form).val();
502527
config.GenreIgnoreActor = $('#chkGenreIgnoreActor').prop('checked');
503528
config.TitleIgnoreActor = $('#chkTitleIgnoreActor').prop('checked');

Emby.Plugins.JavScraper/Configuration/Jellyfin.ConfigPage.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ <h2 class="sectionTitle">JavScraper 配置</h2><span id="current_version" name="
6464
<span class="selectArrow material-icons keyboard_arrow_down"></span>
6565
</div>
6666
</div>
67+
6768
<div id="selectProxyTypeJsProxy" name="selectProxyTypeJsProxy" class="selectProxyTypeJsProxy">
6869
<div class="inputContainer">
6970
<label class="inputLabel inputLabel-float inputLabelUnfocused" for="txtJsProxy">修改版 JsProxy 代理地址:</label>
@@ -103,6 +104,24 @@ <h2 class="sectionTitle">JavScraper 配置</h2><span id="current_version" name="
103104
用户名和密码,可以为空。
104105
</div>
105106
</div>
107+
108+
<br>
109+
<div>
110+
<div class="checkboxContainer checkboxContainer-withDescription">
111+
<label>
112+
<input type="checkbox" is="emby-checkbox" id="chkEnableX_FORWARDED_FOR">
113+
<span>增加 X-FORWARDED-FOR HTTP 请求头</span>
114+
</label>
115+
<div class="fieldDescription checkboxFieldDescription"></div>
116+
</div>
117+
118+
<div class="inputContainer">
119+
<label class="inputLabel inputLabel-float inputLabelUnfocused" for="txtX_FORWARDED_FOR">X-FORWARDED-FOR IP地址:</label>
120+
<input is="emby-input" id="txtX_FORWARDED_FOR" name="txtX_FORWARDED_FOR" class="emby-input" label="X-FORWARDED-FOR IP地址:">
121+
</div>
122+
123+
<div class="fieldDescription">增加 X-FORWARDED-FOR HTTP 请求头的作用在于伪造来源IP地址,以突破区域限制。常用同一个也可能导致被封锁。这个功能仅部分网站有效。</div>
124+
</div>
106125
</fieldset>
107126

108127
<fieldset class="verticalSection verticalSection-extrabottompadding">
@@ -440,6 +459,9 @@ <h2 class="sectionTitle">JavScraper 配置</h2><span id="current_version" name="
440459

441460
$('#selectProxyType', page).val(config.ProxyType).change();
442461

462+
page.querySelector('#chkEnableX_FORWARDED_FOR').checked = config.EnableX_FORWARDED_FOR;
463+
$('#txtX_FORWARDED_FOR', page).val(config.X_FORWARDED_FOR).change();
464+
443465
$('#txtIgnoreGenre', page).val(config.IgnoreGenre).change();
444466
page.querySelector('#chkGenreIgnoreActor').checked = config.GenreIgnoreActor;
445467
page.querySelector('#chkTitleIgnoreActor').checked = config.TitleIgnoreActor;
@@ -504,6 +526,9 @@ <h2 class="sectionTitle">JavScraper 配置</h2><span id="current_version" name="
504526
config.ProxyUserName = $('#txtProxyUserName', form).val();
505527
config.ProxyPassword = $('#txtProxyPassword', form).val();
506528

529+
config.EnableX_FORWARDED_FOR = $('#chkEnableX_FORWARDED_FOR').prop('checked');
530+
config.X_FORWARDED_FOR = $('#txtX_FORWARDED_FOR', form).val();
531+
507532
config.IgnoreGenre = $('#txtIgnoreGenre', form).val();
508533
config.GenreIgnoreActor = $('#chkGenreIgnoreActor').prop('checked');
509534
config.TitleIgnoreActor = $('#chkTitleIgnoreActor').prop('checked');

Emby.Plugins.JavScraper/Configuration/PluginConfiguration.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ public bool IsJsProxyBypass(string host)
8989
/// </summary>
9090
public string ProxyPassword { get; set; }
9191

92+
/// <summary>
93+
/// 启用 X-FORWARDED-FOR 配置
94+
/// </summary>
95+
public bool EnableX_FORWARDED_FOR { get; set; } = true;
96+
97+
/// <summary>
98+
/// X-FORWARDED-FOR IP地址
99+
/// </summary>
100+
public string X_FORWARDED_FOR { get; set; } = "17.172.224.99";
101+
92102
private const string default_ignoreGenre = "高畫質,高画质,高清画质,AV女優,AV女优,独占配信,獨佔動畫,DMM獨家,中文字幕,高清,中文,字幕";
93103
private List<string> _ignoreGenre;
94104

@@ -206,16 +216,14 @@ public JavScraperConfigItem[] Scrapers
206216
{
207217
_scrapers.Join(scrapers, o => o.Name, o => o.Name, (o, v) =>
208218
{
209-
if (o.Url.IsWebUrl())
219+
if (o.Url.IsWebUrl())
210220
v.BaseUrl = o.Url;
211221
else
212222
o.Url = v.DefaultBaseUrl;
213223
return true;
214224
}).ToArray();
215225
}
216-
217226
}
218-
219227
}
220228

221229
/// <summary>

Emby.Plugins.JavScraper/Emby.Plugins.JavScraper.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
<!--复制到 Emby 的补丁目录-->
7878
<Target Name="EmbyPlugin" AfterTargets="ILRepack" Condition="'$(Configuration)'=='Debug' or '$(Configuration)'=='Release'">
79-
<!--<Copy SourceFiles="$(TargetPath)" DestinationFolder="D:\emby\programdata\plugins\" OverwriteReadOnlyFiles="true" />-->
79+
<Copy SourceFiles="$(TargetPath)" DestinationFolder="D:\Software\emby\programdata\plugins\" OverwriteReadOnlyFiles="true" />
8080
</Target>
8181

8282
<!--复制到 Jellyfin 的补丁目录-->

Emby.Plugins.JavScraper/Http/ProxyHttpClientHandler.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ public ProxyHttpClientHandler()
6565
protected override Task<HttpResponseMessage> SendAsync(
6666
HttpRequestMessage request, CancellationToken cancellationToken)
6767
{
68-
request.Headers.TryAddWithoutValidation("X-FORWARDED-FOR", "17.172.224.88");
68+
request.Headers.Remove("X-FORWARDED-FOR");
69+
if (Plugin.Instance.Configuration.EnableX_FORWARDED_FOR && !string.IsNullOrWhiteSpace(Plugin.Instance.Configuration.X_FORWARDED_FOR) &&
70+
IPAddress.TryParse(Plugin.Instance.Configuration.X_FORWARDED_FOR, out var _))
71+
request.Headers.TryAddWithoutValidation("X-FORWARDED-FOR", Plugin.Instance.Configuration.X_FORWARDED_FOR);
72+
6973
//mgstage.com 加入年龄认证Cookies
7074
if (request.RequestUri.ToString().Contains("mgstage.com") && !(request.Headers.TryGetValues("Cookie", out var cookies) && cookies.Contains("abc=1")))
7175
request.Headers.Add("Cookie", "adc=1");

0 commit comments

Comments
 (0)