Added OPML support
This commit is contained in:
@@ -179,6 +179,19 @@
|
||||
<div class="verticalSection">
|
||||
<h2 class="sectionTitle">Podcast Subscriptions</h2>
|
||||
|
||||
<!-- OPML Import/Export -->
|
||||
<div class="opml-actions" style="margin-bottom: 1em; display: flex; gap: 0.5em; align-items: center;">
|
||||
<button is="emby-button" type="button" id="btnExportOpml" class="raised emby-button">
|
||||
<span class="material-icons" style="margin-right: 0.25em;">download</span>
|
||||
<span>Export OPML</span>
|
||||
</button>
|
||||
<button is="emby-button" type="button" id="btnImportOpml" class="raised emby-button">
|
||||
<span class="material-icons" style="margin-right: 0.25em;">upload</span>
|
||||
<span>Import OPML</span>
|
||||
</button>
|
||||
<input type="file" id="opmlFileInput" accept=".opml,.xml" style="display: none;" />
|
||||
</div>
|
||||
|
||||
<!-- Add Podcast Form -->
|
||||
<div class="add-podcast-form">
|
||||
<div class="inputContainer">
|
||||
@@ -410,6 +423,102 @@
|
||||
addPodcast();
|
||||
}
|
||||
});
|
||||
|
||||
// Export OPML
|
||||
document.querySelector('#btnExportOpml').addEventListener('click', function() {
|
||||
Dashboard.showLoadingMsg();
|
||||
|
||||
fetch(ApiClient.getUrl('Jellypod/opml/export'), {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': ApiClient.accessToken() ? ('MediaBrowser Token="' + ApiClient.accessToken() + '"') : ''
|
||||
}
|
||||
})
|
||||
.then(function(response) {
|
||||
if (!response.ok) {
|
||||
throw new Error('Export failed');
|
||||
}
|
||||
return response.blob();
|
||||
})
|
||||
.then(function(blob) {
|
||||
Dashboard.hideLoadingMsg();
|
||||
|
||||
// Create download link
|
||||
var url = window.URL.createObjectURL(blob);
|
||||
var a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'jellypod-subscriptions-' + new Date().toISOString().split('T')[0] + '.opml';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
})
|
||||
.catch(function(err) {
|
||||
Dashboard.hideLoadingMsg();
|
||||
Dashboard.alert('Export failed: ' + err.message);
|
||||
});
|
||||
});
|
||||
|
||||
// Import OPML - trigger file picker
|
||||
document.querySelector('#btnImportOpml').addEventListener('click', function() {
|
||||
document.querySelector('#opmlFileInput').click();
|
||||
});
|
||||
|
||||
// Handle file selection
|
||||
document.querySelector('#opmlFileInput').addEventListener('change', function(e) {
|
||||
var file = e.target.files[0];
|
||||
if (!file) return;
|
||||
|
||||
// Reset input so same file can be selected again
|
||||
e.target.value = '';
|
||||
|
||||
Dashboard.showLoadingMsg();
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
// Use fetch for multipart/form-data upload
|
||||
fetch(ApiClient.getUrl('Jellypod/opml/import'), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': ApiClient.accessToken() ? ('MediaBrowser Token="' + ApiClient.accessToken() + '"') : ''
|
||||
},
|
||||
body: formData
|
||||
})
|
||||
.then(function(response) {
|
||||
if (!response.ok) {
|
||||
return response.text().then(function(text) {
|
||||
throw new Error(text || 'Import failed');
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(function(result) {
|
||||
Dashboard.hideLoadingMsg();
|
||||
loadPodcasts();
|
||||
|
||||
var message = 'Import complete!\n\n' +
|
||||
'Imported: ' + result.importedCount + '\n' +
|
||||
'Skipped (already subscribed): ' + result.skippedCount + '\n' +
|
||||
'Failed: ' + result.failedCount;
|
||||
|
||||
if (result.errors && result.errors.length > 0) {
|
||||
message += '\n\nFailed feeds:\n';
|
||||
result.errors.slice(0, 5).forEach(function(err) {
|
||||
message += '- ' + (err.title || err.feedUrl) + ': ' + err.error + '\n';
|
||||
});
|
||||
if (result.errors.length > 5) {
|
||||
message += '... and ' + (result.errors.length - 5) + ' more';
|
||||
}
|
||||
}
|
||||
|
||||
Dashboard.alert(message);
|
||||
})
|
||||
.catch(function(err) {
|
||||
Dashboard.hideLoadingMsg();
|
||||
Dashboard.alert('Import failed: ' + err.message);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user