badpod
A Rust crate for working with imperfect feeds of podcasts.
This crate should not be used for
❌ working with proper, processed podcast feeds
❌ interfacing with your database
This crate can be used for
✅ interpreting external feeds, often from unknown sources
✅ providing feedback about the contents of the feed
Motivation
On a backend server, which has to communicate with a database, strict schemas are typically used. Therefore, if content from an external source that does not conform to the schema is loaded, one may fail to deserialize that content successfully.
This scenario is very common in podcasting space, where RSS feeds of podcasts may
- combine multiple standards (namespaces)
- have some elements missing
- have some values in wrong data types
- etc.
In that case, we may want a more flexible, intermediate schema: a schema that does not throw an error the instant it encounters an unexpected value but rather one that deserializes the content that it is able to and stores the content that it failed to deserialize for further cleanup or analysis.
Usage
Including in a project
Inside Cargo.toml:
[]
= "0.2.3"
Deserializing
let rss = match from_str ;
Features
Find whether tags or attributes are missing
We don't enforce almost any requirements on what tags must be included in the feed---that's a decision for you to make!
Almost every field of structs provided by badpod is either an Option or a Vector.
This allows to detect whether an XML tag or attribute is included in the feed that was processed.
match channel.podcast_value ;
Deserializing complicated tags
badpod converts complex data in text format to something that is easier to work with.
If that is not possible, we provide enums with variant Other, which is meant to represent data that could not be deserialized.
match geo ;
Other variant can be especially useful in enums with many variants.
If you don't get a match with Other, you know that deserialization yielded something that is reasonably expected.
match language ;
But just because you match a variant that is not Other does not mean that it is a valid value for you.
For example, MimeEnclosure has AudioOpus as one of the variants, but if you require that feeds only contain media files with formats supported by Apple Podcasts, then you will want to reject this.
Again, badpod is only a tool for analyzing feeds; you decide what a "proper" feed must look like.
Tag-aware deserialization
Many tags use the same data types but encode them differently.
For example, both <podcast:locked> and <itunes:explicit> are essentially boolean values, but the former serializes to "yes"/"no" and the latter to "true"/"false".
In badpod, both are deserialized to Bool.
match channel.itunes_explicit ;
Printing enums
Although this crate is mainly for deserialization, there are cases when enums need to be converted back to strings.
In badpod, all enums have Display trait implemented:
// Outputs "cs".
println!;
// Outputs "en".
println!;
// Outputs "en-gb".
println!;