getMediaUrlFromMessage method
Fetch the picture or video URL from a message.
Returns null if the message failed to be parsed.
Implementation
Future<String?> getMediaUrlFromMessage() async {
final match = _getRegExpMatchFromMessage();
final url = match?.group(1);
final type = match?.group(2);
// Skip ambiguous URLs.
if (match == null || url == null || type == null) return null;
final html = await _getHtml(url);
// Skip if HTML cannot be fetched.
if (html == null) return null;
switch (type) {
case 'picture':
return _getPictureUrl(html);
case 'video':
return _getVideoUrl(html);
default:
return null;
}
}