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;
|
|
|
|
|
2023-01-29 17:18:41 -05:00
|
|
|
case 'albums':
|
2023-01-26 16:35:58 -05:00
|
|
|
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;
|
|
|
|
}
|