Version 1.9.2 implement `videoDuration`
This commit is contained in:
parent
5a94b500d2
commit
f619a6db9d
|
@ -1,5 +1,8 @@
|
|||
## 1.9.2
|
||||
- Implement `videoDuration` in `ChannelVideo`.
|
||||
|
||||
## 1.9.1
|
||||
- Bug fixes (due to youtube changes)
|
||||
- Bug fixes (due to YouTube changes)
|
||||
|
||||
## 1.9.0
|
||||
- Support nnbd (dart 1.12)
|
||||
|
|
|
@ -9,8 +9,11 @@ class ChannelVideo with EquatableMixin {
|
|||
/// Video title.
|
||||
final String videoTitle;
|
||||
|
||||
/// Video duration
|
||||
final Duration videoDuration;
|
||||
|
||||
/// Initialize an instance of [ChannelVideo]
|
||||
ChannelVideo(this.videoId, this.videoTitle);
|
||||
ChannelVideo(this.videoId, this.videoTitle, this.videoDuration);
|
||||
|
||||
@override
|
||||
String toString() => '[ChannelVideo] $videoTitle ($videoId)';
|
||||
|
|
|
@ -166,6 +166,16 @@ class _InitialData {
|
|||
VideoId(video.getT<String>('videoId')!),
|
||||
video.get('title')?.getT<String>('simpleText') ??
|
||||
video.get('title')?.getList('runs')?.map((e) => e['text']).join() ??
|
||||
'');
|
||||
'',
|
||||
video
|
||||
.getList('thumbnailOverlays')
|
||||
?.firstOrNull
|
||||
?.get('thumbnailOverlayTimeStatusRenderer')
|
||||
?.get('text')
|
||||
?.getT<String>('simpleText')
|
||||
?.toDuration() ??
|
||||
Duration.zero);
|
||||
}
|
||||
}
|
||||
|
||||
// video['thumbnailOverlays'].first['thumbnailOverlayTimeStatusRenderer']['text']['simpleText']
|
||||
|
|
|
@ -219,33 +219,8 @@ class _Video {
|
|||
root.getList('descriptionSnippet')?.parseRuns() ?? '';
|
||||
|
||||
Duration? get duration =>
|
||||
_stringToDuration(root.get('lengthText')?.getT<String>('simpleText'));
|
||||
root.get('lengthText')?.getT<String>('simpleText')?.toDuration();
|
||||
|
||||
int get viewCount =>
|
||||
root.get('viewCountText')?.getT<String>('simpleText')?.parseInt() ?? 0;
|
||||
|
||||
/// Format: HH:MM:SS
|
||||
static Duration? _stringToDuration(String? string) {
|
||||
if (string == null || string.trim().isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var parts = string.split(':');
|
||||
assert(parts.length <= 3);
|
||||
|
||||
if (parts.length == 1) {
|
||||
return Duration(seconds: int.parse(parts.first));
|
||||
}
|
||||
if (parts.length == 2) {
|
||||
return Duration(
|
||||
minutes: int.parse(parts.first), seconds: int.parse(parts[1]));
|
||||
}
|
||||
if (parts.length == 3) {
|
||||
return Duration(
|
||||
hours: int.parse(parts[0]),
|
||||
minutes: int.parse(parts[1]),
|
||||
seconds: int.parse(parts[2]));
|
||||
}
|
||||
throw Error();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ void main() {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
test('Get videos of a youtube channel from the uploads page', () async {
|
||||
var videos = await yt!.channels
|
||||
.getUploadsFromPage('UCEnBXANsKmyj2r9xVyKoDiQ')
|
||||
|
|
Loading…
Reference in New Issue