forked from modwedar/YoutubeDataApi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaylist.dart
48 lines (41 loc) · 1.31 KB
/
playlist.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import 'package:youtube_data_api/models/thumbnail.dart';
class PlayList {
///Youtube playlist id
String? playListId;
///Youtube playlist thumbnails
List<Thumbnail>? thumbnails;
///Youtube playlist title
String? title;
///Youtube playlist channel name
String? channelName;
///Youtube playlist number of videos
String? videoCount;
PlayList(
{this.playListId,
this.thumbnails,
this.title,
this.channelName,
this.videoCount});
factory PlayList.fromMap(Map<String, dynamic>? map) {
List<Thumbnail> thumbnails = [];
map?['playlistRenderer']['thumbnails']
.forEach((thumbnail) {
thumbnails.add(Thumbnail(url: thumbnail['thumbnails'][0]['url'], width: thumbnail['thumbnails'][0]['width'], height: thumbnail['thumbnails'][0]['height']));
});
return PlayList(
playListId: map?['playlistRenderer']['playlistId'],
thumbnails: thumbnails,
title: map?['playlistRenderer']['title']['simpleText'],
videoCount: map?['playlistRenderer']['videoCount'],
channelName: map?['playlistRenderer']['shortBylineText']['runs'][0]
['text']);
}
Map<String, dynamic> toJson() {
return {
"playListId": playListId,
"thumbnails": thumbnails,
"title": title,
"videoCount": videoCount,
};
}
}