youtubeDlGenerators top-level property
Implementation
final Map<String, FigGenerator> youtubeDlGenerators = {
'listVideos': FigGenerator(
script: (context) => [
'youtube-dl',
'--flat-playlist',
'-J',
...context.where((token) => token.contains('youtube.')),
],
postProcess: (out, [tokens]) {
try {
final json = jsonDecode(out);
final entries = json['entries'] as List<dynamic>;
return entries
.asMap()
.map((index, video) {
final name = '${index + 1} - ${video['title']}';
return MapEntry(
index,
FigSuggestion(
name: name,
description: video['uploader'],
insertValue: '${index + 1}',
icon:
'https://www.youtube.com/s/desktop/810941b4/img/favicon_32.png',
),
);
})
.values
.toList();
} catch (e) {
print(e);
return [];
}
},
),
'listClipboard': FigGenerator(
script: ['pbpaste'],
postProcess: (out, [tokens]) {
final regex = RegExp(r'^(https?://)?(www.)?(youtube.com|youtu.?be)/.+$');
try {
if (regex.hasMatch(out)) {
return [
FigSuggestion(
name: out,
description: 'Clipboard',
icon:
'https://www.youtube.com/s/desktop/810941b4/img/favicon_32.png',
),
];
}
} catch (e) {
print(e);
}
return [];
},
),
};