forked from gokadzev/Musify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.dart
60 lines (52 loc) · 1.7 KB
/
checker.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
49
50
51
52
53
54
55
56
57
58
59
60
// ignore_for_file: avoid_print
import 'package:http/http.dart' as http;
import 'package:musify/DB/albums.db.dart';
import 'package:musify/DB/playlists.db.dart';
import 'package:youtube_explode_dart/youtube_explode_dart.dart';
final _yt = YoutubeExplode();
List playlists = [...playlistsDB, ...albumsDB];
void main() async {
print('PLAYLISTS AND ALBUMS CHECKING RESULT:');
print(' ');
for (final playlist in playlists) {
try {
final plist = await _yt.playlists.get(playlist['ytid']);
if (plist.videoCount == null) {
if (playlist['isAlbum'] != null && playlist['isAlbum']) {
print('> The album with the ID ${playlist['ytid']} does not exist.');
} else {
print(
'> The playlist with the ID ${playlist['ytid']} does not exist.',
);
}
}
final imageAvailability = await isImageAvailable(playlist['image']);
if (!imageAvailability) {
if (playlist['isAlbum'] != null && playlist['isAlbum']) {
print(
'> The album artwork with the URL ${playlist['image']} is not available.',
);
} else {
print(
'> The playlist artwork with the URL ${playlist['image']} is not available.',
);
}
}
} catch (e) {
print(
'An error occurred while checking playlist ${playlist['title']}: $e',
);
}
}
print(' ');
print('The checking process is done');
}
Future<bool> isImageAvailable(String url) async {
try {
final response = await http.head(Uri.parse(url));
return response.statusCode == 200;
} catch (e) {
print('Something went wrong in isImageAvailable for the url: $url');
return false;
}
}