getVideosRelatedToChannel method Null safety
Get Videos Related To Channel
A simplified method for access channel specific data. If you want more customization, the same result can be obtained by calling the queryVideos() method.
Arguments
channelId
ID of the Youtube Channel that is being queriedtype
The type of video resource to fetch. Clips finds clip videos of a vtuber channel, Video finds thechannelId
channel's uploads, and collabs finds videos uploaded by other channels that mention thischannelId
includes
Request extra data be included in the results. They are not guarenteed to be returned.languages
List of Language enum to filter channels/clips. Official streams do not follow this parameterlimit
Result limit. Max of 50.offset
Offset resultspaginated
If paginated is set to true, returnsVideoFullList
with total, otherwise returnsVideoFullList
without the total.
Implementation
@override
Future<VideoFullList> getVideosRelatedToChannel(
String channelId, {
required VideoSearchType type,
List<Includes>? includes,
List<Language> languages = const [Language.all],
int limit = 25,
int offset = 0,
bool paginated = true,
}) async {
// Limit cannot be greater than 50 otherwise request will be denied
assert(limit <= 50);
final Map<String, dynamic> params = {};
// Add the items with default values (they can't be null)
params.addAll({
'limit': '$limit',
'offset': '$offset',
});
_addIncludes(includes, params);
_addLanguages(languages, params);
_addPaginated(paginated, params);
final response = await get(path: '${_Constants.channelsPath}/$channelId/${EnumUtil.convertVideoSearchTypeToString(type)}', params: params);
if (paginated) {
// Grab total and return with it
final videoList = VideoFullList.fromJson(response.body);
return videoList.copyWith(paginated: true);
}
final List list = jsonDecode(response.body);
return VideoFullList(videos: list.map((video) => VideoFull.fromMap(video)).toList());
}