funkblubber/lib/parser.dart

52 lines
1.1 KiB
Dart
Raw Normal View History

2023-01-26 16:35:58 -05:00
import 'package:funkblubber/funkentity.dart';
import 'package:funkblubber/console.dart' as console;
FunkObject extract(final List<String> args) {
FunkObject result = FunkObject(
kind: FunkEntity.error,
id: '',
domain: '',
);
if (args.isEmpty) {
console.error('no arguments provided');
return result;
}
try {
final Uri uri = Uri.parse(args[0]);
final segments = uri.pathSegments;
for (int i = 0; i < segments.length; ++i) {
switch (segments[i]) {
case 'artists':
result = FunkObject(
kind: FunkEntity.artist,
id: segments[i + 1],
domain: uri.host,
);
++i;
break;
case 'album':
result = FunkObject(
kind: FunkEntity.album,
id: segments[i + 1],
domain: uri.host,
);
++i;
break;
}
}
} catch (e) {
console.error(e.toString());
result = FunkObject(
kind: FunkEntity.error,
id: '',
domain: '',
);
}
return result;
}