git.iko.soy/maciek134/podphoenix
on main help sign in
Fallback to feedurl to fetch cover art if podcast is not present in itunes (rev 162)
commit35f0cbb77f254ba650d99a19133c4aebea657192 authorNekhelesh Ramananthan <krnekhelesh@gmail.com> dateThu 8 Dec 2016, 22:58 (10 years ago) parentdae6654
1 file changed+47−1
app/ui/SettingsPage.qml+47−1
app/ui/SettingsPage.qml+47−1
@@ -339,7 +339,13 @@ pointing at invalid files have also been cleaned up.")
339339 }
340340
341341 function getPodcastCoverArt(name, feedUrl, image) {
342− var coverArt
342+ // Default first to iTunes to fetch cover art. Fallback to feed url if podcast cannot be
343+ // found in iTunes.
344+ getCoverArtItunes(name, feedUrl, image)
345+ }
346+
347+ function getCoverArtItunes(name, feedUrl, image) {
348+ var coverArt = ""
343349 var url = "https://itunes.apple.com/search?term=" + name + "&media=podcast&entity=podcast"
344350 var xhr = new XMLHttpRequest;
345351 xhr.open("GET", url);
@@ -359,11 +365,51 @@ pointing at invalid files have also been cleaned up.")
359365 }
360366 }
361367 }
368+
369+ // If the podcast is not found on iTunes, fallback to its feed url for fetching cover art
370+ if (coverArt == "") {
371+ getCoverArtFeedUrl(name, feedUrl, image)
372+ }
362373 }
363374 }
364375 xhr.send();
365376 }
366377
378+ function getCoverArtFeedUrl(name, feedUrl, image) {
379+ console.log("Fetching cover art from feed")
380+ var coverArt
381+ var xhr = new XMLHttpRequest;
382+ xhr.open("GET", feedUrl)
383+ xhr.onreadystatechange = function () {
384+ if (xhr.readyState === XMLHttpRequest.DONE) {
385+ var e = xhr.responseXML.documentElement;
386+
387+ for(var h = 0; h < e.childNodes.length; h++) {
388+ if(e.childNodes[h].nodeName === "channel") {
389+ var c = e.childNodes[h];
390+ for(var j = 0; j < c.childNodes.length; j++) {
391+ var nodeName = c.childNodes[j].nodeName;
392+ if (nodeName === "image") {
393+ var el = c.childNodes[j];
394+ for (var l = 0; l < el.attributes.length; l++) {
395+ if(el.attributes[l].nodeName === "href") {
396+ coverArt = el.attributes[l].nodeValue;
397+ if (coverArt) {
398+ fileManager.deleteFile(image);
399+ imageDownloader.addDownload(feedUrl, coverArt)
400+ }
401+ }
402+ }
403+ }
404+ }
405+ }
406+ }
407+ }
408+ }
409+
410+ xhr.send()
411+ }
412+
367413 function removeOrphans() {
368414 var filelist = fileManager.getDownloadedEpisodes()
369415