Skip to content

Commit

Permalink
Fix compatibility mode option being ignored (lighttube-org#102)
Browse files Browse the repository at this point in the history
- Add a permanent compatibility option in the settings
- Fix the Player.cshtml to respect the compatibility setting
- Fix videos not loading when the video proxy is disabled
  • Loading branch information
kuylar authored Dec 22, 2023
1 parent e0db589 commit 050ec48
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
6 changes: 5 additions & 1 deletion LightTube/Controllers/SettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<IActionResult> Appearance()

[Route("appearance")]
[HttpPost]
public IActionResult Appearance(string hl, string gl, string theme, string recommendations)
public IActionResult Appearance(string hl, string gl, string theme, string recommendations, string compatibility)
{
Response.Cookies.Append("hl", hl, new CookieOptions
{
Expand All @@ -52,6 +52,10 @@ public IActionResult Appearance(string hl, string gl, string theme, string recom
{
Expires = DateTimeOffset.MaxValue
});
Response.Cookies.Append("compatibility", recommendations == "on" ? "true" : "false", new CookieOptions
{
Expires = DateTimeOffset.MaxValue
});
return Redirect("/settings/appearance");
}

Expand Down
6 changes: 6 additions & 0 deletions LightTube/Controllers/YoutubeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public async Task<IActionResult> Embed(string v, bool contentCheckOk, bool compa
sponsors = Array.Empty<SponsorBlockSegment>();
}

if (HttpContext.GetDefaultCompatibility())
compatibility = true;

InnerTubeNextResponse video =
await _youtube.GetVideoAsync(v, language: HttpContext.GetLanguage(), region: HttpContext.GetRegion());
if (player is null || e is not null)
Expand Down Expand Up @@ -75,6 +78,9 @@ await _youtube.GetVideoAsync(v, localPlaylist ? null : list, language: HttpConte
region: HttpContext.GetRegion());
InnerTubeContinuationResponse? comments = null;

if (HttpContext.GetDefaultCompatibility())
compatibility = true;

try
{
string commentsContinuation = InnerTube.Utils.PackCommentsContinuation(v, CommentsContext.Types.SortOrder.TopComments);
Expand Down
5 changes: 5 additions & 0 deletions LightTube/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public static bool GetDefaultRecommendationsVisibility(this HttpContext context)
? recommendations == "visible"
: true;

public static bool GetDefaultCompatibility(this HttpContext context) =>
context.Request.Cookies.TryGetValue("compatibility", out string compatibility)
? compatibility == "true"
: false;

public static string GetVersion()
{
if (_version is null)
Expand Down
21 changes: 21 additions & 0 deletions LightTube/Views/Settings/Appearance.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,26 @@
}
</div>
</label>

<label class="settings-option">
<div class="settings-option__info">
<div class="ml-2 title">
Compatibility mode
</div>
<div>
Use MP4 streams instead of HLS streams. Breaks livestreams
</div>
</div>
<div class="settings-option__option">
@if (Context.GetDefaultCompatibility())
{
<input type="checkbox" name="compatibility" checked>
}
else
{
<input type="checkbox" name="compatibility">
}
</div>
</label>
<br>
<input type="submit" class="btn-outline btn-blue" style="width:fit-content;" value="Save Changes">
5 changes: 4 additions & 1 deletion LightTube/Views/Shared/Player.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ else
href: "/channel/@Model.Player!.Details.Author.Id"
},
title: "@Model.Player!.Details.Title", // .Replace("\"", "\\\"")
hlsManifest: "/proxy/media/@(Model.Player.Details.Id).m3u8",
@if (Model.UseHls)
{
@:hlsManifest: "/proxy/media/@(Model.Player.Details.Id).m3u8",
}
buttons: {
play: '<svg class="bi" width="20" height="20" fill="currentColor"><use href="/svg/bootstrap-icons.svg#play-fill"/></svg>',
pause: '<svg class="bi" width="20" height="20" fill="currentColor"><use href="/svg/bootstrap-icons.svg#pause-fill"/></svg>',
Expand Down

0 comments on commit 050ec48

Please sign in to comment.