simplify retrieval of Entries

This commit is contained in:
Joseph
2024-02-24 11:08:45 +00:00
parent 3f0fe87c2e
commit 912248327a

View File

@ -454,31 +454,32 @@ func infoFromURL(
} }
// as we ignore errors for playlists some entries might show up as null // as we ignore errors for playlists some entries might show up as null
if options.Type == TypePlaylist { //
// note: instead of doing full recursion, we assume entries in
// playlists and channels are at most 2 levels deep, and we just
// collect entries from both levels.
//
// the following cases have not been tested:
//
// - entries that are more than 2 levels deep (will be missed)
// - the ability to restrict entries to a single level (we include both levels)
if options.Type == TypePlaylist || options.Type == TypeChannel {
var filteredEntrise []Info var filteredEntrise []Info
for _, e := range info.Entries { for _, e := range info.Entries {
if e.ID == "" { if e.ID == "" {
continue continue
} }
filteredEntrise = append(filteredEntrise, e) if e.Type == "playlist" {
} for _, ee := range e.Entries {
info.Entries = filteredEntrise if ee.ID == "" {
}
// channels contain playlists, so recurse into them
if options.Type == TypeChannel {
var filteredEntrise []Info
for _, p := range info.Entries {
if p.Type != "playlist" {
continue continue
} }
for _, e := range p.Entries { filteredEntrise = append(filteredEntrise, ee)
if e.ID == "" { }
continue continue
} }
filteredEntrise = append(filteredEntrise, e) filteredEntrise = append(filteredEntrise, e)
} }
}
info.Entries = filteredEntrise info.Entries = filteredEntrise
} }