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
|
## 1.9.1
|
||||||
- Bug fixes (due to youtube changes)
|
- Bug fixes (due to YouTube changes)
|
||||||
|
|
||||||
## 1.9.0
|
## 1.9.0
|
||||||
- Support nnbd (dart 1.12)
|
- Support nnbd (dart 1.12)
|
||||||
|
|
|
@ -9,8 +9,11 @@ class ChannelVideo with EquatableMixin {
|
||||||
/// Video title.
|
/// Video title.
|
||||||
final String videoTitle;
|
final String videoTitle;
|
||||||
|
|
||||||
|
/// Video duration
|
||||||
|
final Duration videoDuration;
|
||||||
|
|
||||||
/// Initialize an instance of [ChannelVideo]
|
/// Initialize an instance of [ChannelVideo]
|
||||||
ChannelVideo(this.videoId, this.videoTitle);
|
ChannelVideo(this.videoId, this.videoTitle, this.videoDuration);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => '[ChannelVideo] $videoTitle ($videoId)';
|
String toString() => '[ChannelVideo] $videoTitle ($videoId)';
|
||||||
|
|
|
@ -166,6 +166,16 @@ class _InitialData {
|
||||||
VideoId(video.getT<String>('videoId')!),
|
VideoId(video.getT<String>('videoId')!),
|
||||||
video.get('title')?.getT<String>('simpleText') ??
|
video.get('title')?.getT<String>('simpleText') ??
|
||||||
video.get('title')?.getList('runs')?.map((e) => e['text']).join() ??
|
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() ?? '';
|
root.getList('descriptionSnippet')?.parseRuns() ?? '';
|
||||||
|
|
||||||
Duration? get duration =>
|
Duration? get duration =>
|
||||||
_stringToDuration(root.get('lengthText')?.getT<String>('simpleText'));
|
root.get('lengthText')?.getT<String>('simpleText')?.toDuration();
|
||||||
|
|
||||||
int get viewCount =>
|
int get viewCount =>
|
||||||
root.get('viewCountText')?.getT<String>('simpleText')?.parseInt() ?? 0;
|
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 {
|
test('Get videos of a youtube channel from the uploads page', () async {
|
||||||
var videos = await yt!.channels
|
var videos = await yt!.channels
|
||||||
.getUploadsFromPage('UCEnBXANsKmyj2r9xVyKoDiQ')
|
.getUploadsFromPage('UCEnBXANsKmyj2r9xVyKoDiQ')
|
||||||
|
|
Loading…
Reference in New Issue