loadFeed static method
This method takes a Url pointing to an RSS feed containing the Podcast details and episodes. You can optionally specify a timeout value in milliseconds and a custom user-agent string that will be used in HTTP/HTTPS communications with the feed source.
Implementation
static Future<Podcast> loadFeed({
required String url,
final timeout = const Duration(seconds: 20),
String userAgent = '',
}) async {
final client = Dio(
BaseOptions(
connectTimeout: timeout,
receiveTimeout: timeout,
headers: {
'User-Agent': userAgent.isEmpty ? podcastSearchAgent : userAgent,
},
),
);
try {
final response = await client.get(url);
var rssFeed = RssFeed.parse(response.data);
// Parse the episodes
return _loadFeed(rssFeed, url);
} on DioException catch (e) {
switch (e.type) {
case DioExceptionType.connectionTimeout:
case DioExceptionType.sendTimeout:
case DioExceptionType.receiveTimeout:
throw PodcastTimeoutException(e.message ?? '');
case DioExceptionType.connectionError:
case DioExceptionType.badResponse:
throw PodcastFailedException(e.message ?? '');
case DioExceptionType.badCertificate:
throw PodcastCertificateException(e.message ?? '');
case DioExceptionType.cancel:
throw PodcastCancelledException(e.message ?? '');
case DioExceptionType.unknown:
throw PodcastUnknownException(e.message ?? '');
}
}
}