Apologies
You must be signed in to watch this lesson.
Episode Images and Extensions Refactor
Podcasts
This will be the final lesson on the Episodes feature where we'll discuss how to load images for each Podcast Episode. It can be a little tricky since there are individual episode images as well as an image for the entire podcast. Whenever we are not able to locate an episode image, we'll go ahead and use the podcast image url. After we get the image loading finished, I'll go over some very useful techniques in refactoring your code so that everything belongs in separate files. Enjoy.

Comments (12)
Tube
6 years ago
Many episode descriptions--e.g. Vector--are in html; so, tags are showing.
Brian Voong
6 years ago
Te-Jen Wu
6 years ago
Some episode images(e.g. Food on SermonAudio.com) are relative url not absolute url . How can we get the absolute url?
Brian Voong
6 years ago
Te-Jen Wu
6 years ago
Thanks a lot.
이동건
6 years ago
hello brian i set the ATC setting in info.plist like below Allow Arbitrary Loads in Web Content = YES Allow Arbitrary Loads = YES and everything is fine but i cannot load your podcast image i can print your image url http://i1.sndcdn.com/avatars-000403867065-5g5khr-original.jpg but it didn't show up what is the problem? this is my code : https://github.com/ehdrjsdlzzzz/Podcasts
이동건
6 years ago
after i change my info.plist like you <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>mzstatic.com</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSIncludesSubdomains</key> <true/> </dict> </dict> </dict> everything same i your podcast image ulr get the image url but cannot show up your podcast image
Brian Voong
6 years ago
이동건
6 years ago
I really appreciate you.
weare99
5 years ago
Hi Brian, I love your new Tutorial Series. Amazing work. You said a few tutorials ago that we will create a Singelton on the API Service Model. But in my opinion this is not a Singelton, because Singelton are only exists on Classes not Structs. Please let me now if I not right. Thanks Best regards from Germany
weare99
5 years ago
Sorry. It is a class in this series.
Brian Voong
5 years ago
albaqawi
5 years ago
Amazing answer as in CS community there is so much arguing on this and I love how you put it. thx :D
Talia
5 years ago
你好,Brian, 在链接到Episode页面时有些图片显示不出来,有些控制台显示已经加载,但是没显示图片,有些显示错误,-1200,-1022,-999,这是什么问题?应该怎么解决?还有,写在获取cell里的description的时候,偶尔遇到 <p>.....呈现出来,不是我们的问题,但是毕竟不好看,有没有办法解决?我英文说得不好,但是能看,你发英文没问题,谢谢你
Brian Voong
5 years ago
Hongjun BU
5 years ago
Issues solved.谢谢
vistoir
5 years ago
Hi Brian, Amazing tutorials. Just wondering if you know how to remove HTML tags from the RSS feeds, in your sample when you're searching for "Food" podcast, the "Good Food" episodes description contains something like this: "<p>New York Times columnist Melissa Clark explains the pressure cooker craze... </p>" Thanks a lot.
albaqawi
5 years ago
hi Visitor I managed to resolve it with the help of these 2 extensions on String and Data https://stackoverflow.com/questions/28124119/convert-html-to-plain-text-in-swift the answer from Leo was perfect with Swift 4 Xocde 10 syntax In code in Episode.swift All I had to change is this line self.description = feedItem.description?.html2String ?? "" It did not break any of existing project :D
SimonQ
5 years ago
Hey Brian, I noticed for some feeds when there are no images for the feedItems and we set those to the feed image it does not work. I've set break points and the imageUrl is there but, when we append to the episodes array, the episode object has an empty imageUrl. This happens to me on the Good Food podcast but for the Good Life Project it loads fine. What could the issue be?
Brian Voong
5 years ago
SimonQ
5 years ago
Just tested with a few other ones, the ones that don't work have this url: `http://www.kcrw.com/news-culture/shows/good-food-on-the-road/@@images/<some-uuid>.jpeg` i want to say that it may have something to do with the @@ symbols? It's so odd!
SimonQ
5 years ago
It's not even that, the image urls are not even getting set into the Episode object. The breakpoints point out that the imageUrl for the feedItem url is nil and it assigns the feed image url (which does exist) accordingly to the Episode object. But when it is appended it becomes empty again.
Brian Voong
5 years ago
Bensalem Ilyes
5 years ago
change self.imageUrl = feedItem.iTunes?.iTunesImage?.attributes?.href ?? "" to self.imageUrl = feedItem.iTunes?.iTunesImage?.attributes?.href in Episode Model
SimonQ
5 years ago
I downloaded the project, I tested it with another podcast called "Good financial cents". if you try it with that one you should get blank image results as well... It's a very odd bug and is frustrating that I'm having such a hard time figuring out this bug!
Ally Makongo
5 years ago
You can as well pass artworlUrl600 from EpisodesController since we have podcast object. I managed to do this cell.coverImageUrl = self.podcast?.artworkUrl600 where I define coverImageUrl in EpisodeCell. Is it okay to pass the two parameters? as this let episode = self.episodes[indexPath.row] cell.episode = episode cell.coverImageUrl = self.podcast?.artworkUrl600 Since all episodes will have same image url
Brian Voong
5 years ago
Ally Makongo
5 years ago
I realize, if different images are for episodes, then this will not work
keithcao
5 years ago
Brian 你好,我现在在广州,打开课程发现都打不开视频,显示player.vimep.com refuse to connect. 请问你有什么解决办法吗?
Brian Voong
5 years ago
joker45
5 years ago
because in the most cases the feedItem.iTunes?.iTunesImage?.attributes?.href (itunes:image) property is empty or just have "HTTP" and not HTTPS URL, i just added following fallback: Add to EpisodeCell.swift: var podcastArtworkUrl: String? And to the DidSet... ------------ let podcastOrEpisodeImageUrl = episode.imageUrl.isEmpty ? podcastArtworkUrl : episode.imageUrl guard let imageUrl = podcastOrEpisodeImageUrl else { return } let secureImageUrl = imageUrl.contains("https") ? imageUrl : imageUrl.replacingOccurrences(of: "http", with: "https") let url = URL(string: secureImageUrl) episodeImageView.sd_setImage(with: url, completed: nil) And in EpisodesController.swift near by "cellForRowAt"... cell.podcastArtworkUrl = podcast?.artworkUrl600 So if images from Episodes not exists you just get the image from the podcast...
Brian Voong
5 years ago
joker45
5 years ago
sometimes... you have to finsih the video before you post something... haha brian already explain a solution for fall back :) But.. if image url have not HTTPS i still have problems... but you can fix it if you deactivate / set AllowsInsecureHTTPLoads ... but in my case i did not do this and used the modifying trick of protocol from http to https (of course i know that this is not a really clean solution, because some http server dont have a https server... but in most case this solution works.
w33zel
4 years ago
Hi Brian, I put the HTTP to HTTPS thing into a URL extension like: extension URL { init?(httpToHttps url: String) { let secureUrl = url.contains("https") ? url : url.replacingOccurrences(of: "http", with: "https") self.init(string: secureUrl) } } so you can use it like: guard let imageUrl = URL(httpToHttps: episode.imageUrl ?? "") else { return } Just wanted to share my idea and also ask something. Because in general, it seems like HTTPS and podcasts is a really huge pain in the somewhere you don't wanna have pain in. So i wonder how "wrong" is it to just use this: <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key><true/> </dict> to allow HTTP requests? It would make things so much easier.  
HELP & SUPPORT