Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,62 @@ features explicitly removed below are not promises of current functionality.
Superseded prereleases are marked deprecated after the replacement is verified.
Published assets and original source tags remain unchanged for provenance.

## 1.3.0-fork.13 - category-scoped refresh task
## 1.3.0-fork.20-rc.1 - consolidated release candidate

- Consolidate the current features, setup, operational limits and testing
guidance in README.md. Historical point releases below are deprecated.

## 1.3.0-fork.19 - refresh controls and recovery

- Add a persistent settings lock, collapsed setup sections, category refresh
actions, configurable timeout and more detailed refresh status.
- Estimate request progress from the last successful matching configuration.
Timeout recovery reuses bounded catalogue checkpoints and restarts any
interrupted Emby category import; oversized checkpoints require restart.

## 1.3.0-fork.18 - alphabet pagination fix

- Preserve TuneIn's unescaped `#` alphabet filter in pagination links while
retaining destination and fragment restrictions.
- Include a safe reason when a catalogue destination is rejected, without
exposing its URL or credentials in the refresh task report.

## 1.3.0-fork.17 - staged refresh root fix

- Allow Emby's channel-root query during staged refresh and report swallowed
import errors before attempting artwork updates.

## 1.3.0-fork.16 - refresh performance and status

- Discover and stage bounded selected-category results before starting Emby's
category import, share identical validated catalogue requests within a task
run and briefly after successful refreshes, and record safe discovery/import
timing and cache-hit diagnostics. Add an administrator-configurable catalogue
request interval, defaulting to three seconds. Respect provider rate-limit
responses without assuming that music results establish language or location
membership.
- Show the current category and discovery, import or artwork phase in the
dedicated refresh task status without background polling.

## 1.3.0-fork.15 - alphabetic browse refresh fix

- Accept TuneIn's bounded alphabetic station/show filters for **Find by Name**,
including encoded `#` and international letters, without relaxing destination
or selected-category restrictions. These provider links previously failed Music
refreshes. Include safe rejected-parameter details in the task's main error
message when Emby omits inner exceptions from its stored report.

## 1.3.0-fork.14 - refresh diagnostics (deprecated)

- Preserve the original refresh exception chain in the native failed-task report,
including failures swallowed by host traversal. Identify the category, phase,
completed/started catalogue requests and last HTTP status instead of reporting
only a generic section failure. Existing administrator-only report limits apply.
Rejected catalogue parameter errors identify the parameter and rejection class,
length and occurrence count without including its value or URL.
This release does not claim to fix the observed refresh failure.

## 1.3.0-fork.13 - category-scoped refresh task (deprecated)

- Add one visible, manually schedulable **Refresh TuneIn** task. It runs only
enabled TuneIn categories and their saved sub-category selections; the separate
Expand Down
16 changes: 10 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ No upstream pull request or merge is created by building or publishing this fork
## Versioning and independent identity

Upstream currently declares assembly/file version `1.2.8.0`. The fork's new
configuration/refresh functionality uses SemVer `1.3.0-fork.13`: the prerelease
configuration/refresh functionality uses SemVer `1.3.0-fork.20-rc.1`: the prerelease
suffix identifies a fork test candidate, not an official upstream release.
The `.csproj` `<Version>` is the source of truth. The SDK derives assembly/file
version `1.3.0.0`; informational version includes the exact source commit.
Expand Down Expand Up @@ -91,15 +91,19 @@ Do not alter station logos when migrating bundled root/group artwork.
Keep legacy refresh history and schedule/trigger backups in the independent state
file, not the signed station configuration. Keep one visible **Refresh TuneIn**
scheduled task, with no default trigger, limited to enabled categories and saved
selections. Do not reintroduce per-group task registrations, schedule-suppression
settings or mutation APIs. The one-time startup
selections. Category refresh actions may use admin-only plugin APIs, but do not
reintroduce per-group task registrations or schedule-suppression settings. The one-time startup
migration may undo recorded plugin suppression of the exact built-in task, restoring
saved/native triggers only while its schedule is empty and preserving administrator
edits. Failed migration must retain state, attempt rollback and log errors.
Ordinary configuration Save must never change schedules. The built-in task's
read-only description and native result must not be modified or fabricated.
Settings reads the dedicated TuneIn task status only on open/manual update, without
polling. Retrieving its native failed-task report requires an explicit click and administrator access;
Keep scheduled discovery bounded and complete before Emby imports a section;
do not infer language/location membership from station identity or music alone.
Reuse only equivalent scoped catalogue responses, enforce the configured pacing
and provider retry delays, and treat Emby's import as non-transactional.
Settings may poll local status while open, without contacting TuneIn or starting
a refresh. Retrieving its native failed-task report requires an explicit click and administrator access;
bound it, reject stale attempts and render private error details as plain text.
Do not implement `IHasChangeEvent` or queue the global task on install/update/Save:
configuration invalidation must stay local. Existing host triggers are independent.
Expand All @@ -109,7 +113,7 @@ folder artwork, custom images and stable playback IDs when removing group worker
## Upstream review checklist

Prepare the PR from the tested feature branch in `oconnoradv/EmbyTuneIn` to
`MediaBrowser/TuneIn:master`. The fork's `master` contains the consolidated
`MediaBrowser/TuneIn:master`. The fork's `main` contains the consolidated
squash-merged implementation.
Fetch the latest upstream `master` and inspect the comparison before submission;
do not force-push, discard work or merge upstream changes without reviewing them.
Expand Down
173 changes: 173 additions & 0 deletions MediaBrowser.Plugins.TuneIn.Tests/ConfigurationAndNavigationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,47 @@ public void CatalogueSchemaRejectsAmbiguousBodiesAndUnknownRowStructures(string
TuneInDirectory.ParseCatalogue(Encoding.UTF8.GetBytes(xml)));
}

[Fact]
public void TimeoutSettingDoesNotInvalidateExistingNavigationIdsButScopesResumeIdentity()
{
var original = Ready();
original.EnableTalk = true;
original.NavigationSecret = Convert.ToBase64String(Enumerable.Range(0, 32).Select(value => (byte)value).ToArray());
var changedTimeout = Ready();
changedTimeout.EnableTalk = true;
changedTimeout.NavigationSecret = original.NavigationSecret;
changedTimeout.RefreshTimeoutMinutes = 90;

var originalSnapshot = new ConfigurationSnapshot(original);
var changedSnapshot = new ConfigurationSnapshot(changedTimeout);

var serializer = new System.Xml.Serialization.XmlSerializer(typeof(PluginConfiguration));
string serialized;
using (var writer = new System.IO.StringWriter(System.Globalization.CultureInfo.InvariantCulture))
{
serializer.Serialize(writer, original);
serialized = writer.ToString();
}
var timeoutTag = "<RefreshTimeoutMinutes>";
var timeoutStart = serialized.IndexOf(timeoutTag, StringComparison.Ordinal);
Assert.True(timeoutStart >= 0);
var lineStart = serialized.LastIndexOf('\n', timeoutStart) + 1;
var lineEnd = serialized.IndexOf('\n', timeoutStart);
Assert.True(lineEnd >= timeoutStart);
var fork18Xml = serialized.Remove(lineStart, lineEnd + 1 - lineStart);
string expectedKey;
using (var hash = System.Security.Cryptography.SHA256.Create())
expectedKey = BitConverter.ToString(hash.ComputeHash(Encoding.UTF8.GetBytes(fork18Xml))).Replace("-", "");

Assert.Equal(expectedKey, originalSnapshot.Key);
Assert.Equal(expectedKey, changedSnapshot.Key);
Assert.NotEqual(originalSnapshot.SettingsKey, changedSnapshot.SettingsKey);
var directory = new TuneInDirectory(() => original);
var id = directory.Register(directory.Snapshot(), new NavigationEntry { Category = "talk", StationId = "s1" });
original.RefreshTimeoutMinutes = changedTimeout.RefreshTimeoutMinutes;
Assert.Equal("s1", directory.Resolve(directory.Snapshot(), id).StationId);
}

[Theory]
[InlineData("4.9.1.80", false)]
[InlineData("4.9.1.81", false)]
Expand Down Expand Up @@ -129,6 +170,46 @@ public async Task ConfiguredRootIsLocalAndDisabledOrIncompleteCategoriesAreAbsen
public void CoordinatesAreFiniteRangeCheckedInvariantPairs(string value, bool valid) =>
Assert.Equal(valid, ConfigurationSnapshot.TryCoordinates(value, out _));

[Theory]
[InlineData(0, false)]
[InlineData(1, true)]
[InlineData(3, true)]
[InlineData(30, true)]
[InlineData(31, false)]
public void ApiIntervalIsValidatedOnConfigurationSave(int seconds, bool valid)
{
var config = Ready();
config.ApiRequestIntervalSeconds = seconds;
if (valid) ConfigurationSnapshot.Validate(config);
else Assert.Throws<ArgumentException>(() => ConfigurationSnapshot.Validate(config));
}

[Theory]
[InlineData(0, false)]
[InlineData(1, true)]
[InlineData(60, true)]
[InlineData(1440, true)]
[InlineData(1441, false)]
public void RefreshTimeoutIsValidatedOnConfigurationSave(int minutes, bool valid)
{
var config = Ready();
config.RefreshTimeoutMinutes = minutes;
if (valid) ConfigurationSnapshot.Validate(config);
else Assert.Throws<ArgumentException>(() => ConfigurationSnapshot.Validate(config));
}

[Fact]
public void LegacyConfigurationDefaultsToThreeSecondIntervalAndOneHourTimeout()
{
var serializer = new System.Xml.Serialization.XmlSerializer(typeof(PluginConfiguration));
using (var reader = new System.IO.StringReader("<PluginConfiguration><Username>legacy</Username></PluginConfiguration>"))
{
var config = (PluginConfiguration)serializer.Deserialize(reader);
Assert.Equal(3, config.ApiRequestIntervalSeconds);
Assert.Equal(60, config.RefreshTimeoutMinutes);
}
}

[Fact]
public async Task LocalCoordinatesPersistOnEveryDescendantAndUnrelatedLinksAreRemoved()
{
Expand Down Expand Up @@ -192,6 +273,53 @@ public void LanguageFilterIsCarriedAndGenericHubsAreNormalized()
DirectoryRequest.ParseLink("http://opml.radiotime.com/Browse.ashx?id=g22&filter=l122,l999")));
}

[Theory]
[InlineData("s:~A", "s%3A~A")]
[InlineData("s:~#", "s%3A~%23")]
[InlineData("s:~É", "s%3A~%C3%89")]
[InlineData("p:~湘", "p%3A~%E6%B9%98")]
public void AlphabeticCatalogueFiltersAreEncodedAndPreserveLanguageScope(string filter, string encoded)
{
var link = DirectoryRequest.ParseLink("https://opml.radiotime.com/Browse.ashx?id=c57941&filter=" + encoded);
Assert.Equal(filter, link.Parameters["filter"]);
Assert.Contains("filter=" + encoded, link.Url);
var scoped = TuneInChannel.ScopedRequest(new ConfigurationSnapshot(Ready()),
new NavigationEntry { Category = "language", SelectionId = "l122" }, link);
Assert.Equal(filter + ":l122", scoped.Parameters["filter"]);
}

[Theory]
[InlineData("s:~#", "s:~#")]
[InlineData("p%3A~#", "p:~#")]
public void BareHashInFinalAlphabetFilterIsEncodedForPagination(string rawFilter, string expected)
{
var link = DirectoryRequest.ParseLink(
"http://opml.radiotime.com/Browse.ashx?offset=50&id=c57941&filter=" + rawFilter);
Assert.Equal(expected, link.Parameters["filter"]);
Assert.Equal("50", link.Parameters["offset"]);
Assert.Contains("filter=" + Uri.EscapeDataString(expected), link.Url);
Assert.DoesNotContain("#", link.Url);
}

[Theory]
[InlineData("filter=s:~#private")]
[InlineData("filter=s:~&id=c57941#")]
[InlineData("filter=s:~&filter=s:~#")]
[InlineData("id=c57941#")]
public void BareHashNormalizationRejectsOtherFragments(string query) =>
Assert.Throws<System.IO.InvalidDataException>(() =>
DirectoryRequest.ParseLink("https://opml.radiotime.com/Browse.ashx?" + query));

[Theory]
[InlineData("filter=s%3A~%26username%3Dsecret")]
[InlineData("filter=s%3A~%0A")]
[InlineData("filter=s%3A~%2F")]
[InlineData("filter=s%3A~AB")]
[InlineData("id=s%3A~A")]
public void AlphabeticFilterSupportRejectsUnsafeOrUnexpectedParameters(string query) =>
Assert.Throws<System.IO.InvalidDataException>(() =>
DirectoryRequest.ParseLink("https://opml.radiotime.com/Browse.ashx?id=c57941&" + query));

[Theory]
[InlineData("music", "c424724")]
[InlineData("talk", "c424725")]
Expand Down Expand Up @@ -513,6 +641,51 @@ protected override object Invoke(MethodInfo method, object[] args)
public void CatalogueLinksCannotIntroduceArbitraryTargetsOrParameters(string value) =>
Assert.Throws<System.IO.InvalidDataException>(() => DirectoryRequest.ParseLink(value));

[Theory]
[InlineData(null, "missing or invalid absolute URL")]
[InlineData("ftp://opml.radiotime.com/Browse.ashx?secret=value", "unsupported scheme")]
[InlineData("https://opml.radiotime.com:444/Browse.ashx?secret=value", "non-default port")]
[InlineData("https://private:secret@opml.radiotime.com/Browse.ashx", "credentials in URL")]
[InlineData("https://opml.radiotime.com/Browse.ashx#private", "URL fragment")]
[InlineData("https://private.example/Browse.ashx?secret=value", "untrusted host")]
[InlineData("https://opml.radiotime.com/private?secret=value", "unsupported path")]
public void RejectedCatalogueDestinationsReportOnlySafeReason(string value, string reason)
{
var error = Assert.Throws<System.IO.InvalidDataException>(() => DirectoryRequest.ParseLink(value));
Assert.Equal("Untrusted catalogue link rejected (" + reason + ").", error.Message);
Assert.DoesNotContain("private", error.Message);
Assert.DoesNotContain("secret", error.Message);
}

[Theory]
[InlineData("filter=private%20value", "filter", "contains whitespace", 13, 1)]
[InlineData("id=private%26value", "id", "contains unsupported punctuation", 13, 1)]
[InlineData("sid=", "sid", "empty", 0, 1)]
[InlineData("offset=1&offset=2%2F", "offset", "contains unsupported punctuation", 4, 2)]
[InlineData("pivot=%C3%A9", "pivot", "contains non-ASCII characters", 1, 1)]
[InlineData("c=%01", "c", "contains a control character", 1, 1)]
public void RejectedCatalogueParameterDiagnosticsDoNotExposeValues(string query, string key, string reason, int length, int occurrences)
{
var error = Assert.Throws<System.IO.InvalidDataException>(() =>
DirectoryRequest.ParseLink("https://opml.radiotime.com/Browse.ashx?" + query));
Assert.Contains("'" + key + "'", error.Message);
Assert.Contains(reason, error.Message);
Assert.Contains("length " + length, error.Message);
Assert.Contains("occurrences " + occurrences, error.Message);
Assert.DoesNotContain("private", error.Message);
Assert.DoesNotContain("radiotime.com", error.Message);
}

[Fact]
public void RejectedOverlongCatalogueParameterReportsOnlyLength()
{
var value = new string('x', 81);
var error = Assert.Throws<System.IO.InvalidDataException>(() =>
DirectoryRequest.ParseLink("https://opml.radiotime.com/Browse.ashx?filter=" + value));
Assert.Contains("'filter' (longer than 80 characters; length 81; occurrences 1)", error.Message);
Assert.DoesNotContain(value, error.Message);
}

[Fact]
public void MetadataEndpointsRequireAdministratorAndRelayRequiresLocalServer()
{
Expand Down
Loading
Loading