Skip to content

Commit

Permalink
fix: metadata lookup failure handling
Browse files Browse the repository at this point in the history
Update `add` method in `lib/screens/settings/audio_sources.dart` to handle metadata lookup failures.

* **Metadata Fetching:**
  - Wrap `MetadataFetch.extract` call with a try/catch block to handle potential exceptions.
  - Assign `null` to `metadata` if an exception occurs.
  - Use the URL hostname as the title if metadata lookup fails.

* **Audio Source Addition:**
  - Update the `addSource` method to use the title derived from metadata or URL hostname.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/muxable/rtchat?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
kevmo314 committed Aug 26, 2024
1 parent 0a0b59b commit 69afcea
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/screens/settings/audio_sources.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,22 @@ class _AudioSourcesScreenState extends State<AudioSourcesScreen> {
if (_formKey.currentState!.validate()) {
// fetch the title for the page.
final url = _textEditingController.text;
final metadata = await MetadataFetch.extract(url);
Metadata? metadata;
try {
metadata = await MetadataFetch.extract(url);
} catch (e) {
metadata = null;
}

final title = metadata?.title ?? Uri.parse(url).host;

if (!mounted) return;
final model = Provider.of<AudioModel>(context, listen: false);
if (!await AudioChannel.hasPermission()) {
if (!mounted) return;
await model.showAudioPermissionDialog(context);
}
await model
.addSource(AudioSource(metadata?.title, Uri.parse(url), false));
await model.addSource(AudioSource(title, Uri.parse(url), false));

if (!mounted) return;
_textEditingController.clear();
Expand Down

0 comments on commit 69afcea

Please sign in to comment.