Skip to content

Commit

Permalink
Merge pull request #66 from rstefko/master
Browse files Browse the repository at this point in the history
Support for ownCloud Music
  • Loading branch information
midwan authored May 7, 2022
2 parents be70bb4 + 17f16d0 commit 208376a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
6 changes: 3 additions & 3 deletions MB_SubSonic/Domain/subsonic-rest-api-1.14.0.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 24 additions & 5 deletions MB_SubSonic/Subsonic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ private static IEnumerable<KeyValuePair<string, string>> GetIndexes(string colle
return folders;
}

private static void GetFolderFiles(string baseFolderName, string folderId,
private static void GetFolderFiles(string baseFolderName, string folderPath, string folderId,
ICollection<KeyValuePair<byte, string>[]> files)
{
// Workaround for MusicBee calling GetFile on root folder(s)
Expand Down Expand Up @@ -499,6 +499,12 @@ private static void GetFolderFiles(string baseFolderName, string folderId,
var childEntry = content.child[index];
if (!childEntry.isDir)
{
// Support for servers that does not provide path (eg. ownCloud Music)
if (childEntry.path == null)
{
childEntry.path = string.Concat(folderPath.Substring(baseFolderName.Length + 1), childEntry.id);
}

var tags = GetTags(childEntry, baseFolderName);
if (tags != null)
files.Add(tags);
Expand Down Expand Up @@ -551,7 +557,7 @@ private static KeyValuePair<byte, string>[][] GetFolderFiles(string path)
if (rootFolders.Any(x => x.Key.Equals(folderId)))
return new KeyValuePair<byte, string>[][] { };

GetFolderFiles(path.Substring(0, path.IndexOf(@"\", StringComparison.Ordinal)), folderId, files);
GetFolderFiles(path.Substring(0, path.IndexOf(@"\", StringComparison.Ordinal)), path, folderId, files);
return files.ToArray();
}

Expand Down Expand Up @@ -646,7 +652,8 @@ private static string GetTranslatedUrl(string url)
private static string GetFileId(string url)
{
var folderId = GetFolderId(url);
if (string.IsNullOrWhiteSpace(folderId)) return null;
if (string.IsNullOrWhiteSpace(folderId))
return null;

// Workaround for MusicBee calling this on root folder(s)
var rootFolders = GetRootFolders(true, true, false);
Expand All @@ -670,11 +677,22 @@ private static string GetFileId(string url)
var content = result.Item as Directory;
var filePath = GetTranslatedUrl(url.Substring(url.IndexOf(@"\", StringComparison.Ordinal) + 1));

if (content?.child == null) return null;
if (content?.child == null)
return null;

foreach (var childEntry in content.child)
{
// Support for servers that does not provide path (eg. ownCloud Music)
if (childEntry.path == null && filePath.EndsWith(childEntry.id))
{
return childEntry.id;
}

if (childEntry.path == filePath)
{
return childEntry.id;
}
}
}
else
{
Expand All @@ -689,7 +707,8 @@ private static string GetFileId(string url)
var content = result.Item as LibreSonicAPI.Directory;
var filePath = GetTranslatedUrl(url.Substring(url.IndexOf(@"\", StringComparison.Ordinal) + 1));

if (content?.child == null) return null;
if (content?.child == null)
return null;

foreach (var childEntry in content.child)
if (childEntry.path == filePath)
Expand Down

0 comments on commit 208376a

Please sign in to comment.