marty-suzuki / URLEmbeddedView

URLEmbeddedView automatically caches the object that is confirmed the Open Graph Protocol.
MIT License
650 stars 72 forks source link

Not able to show thumbnails of youtube links. #77

Open sarathdev opened 5 years ago

sarathdev commented 5 years ago

Not able to show thumbnails of youtube links. We had a discussion about the same issue for showing for youtube links that are starting with "m.youtube.com". Now what is happening is if we copy a link from youtube player the link what we are getting is entirely different from all the previous links what we handling. Adding the code that I'm using to show the URL embedded view below

if sosFeedPostDesc.extractURLs() is URL{
                if  let extractedUrls = sosFeedPostDesc.extractURLs() {
                    let url: URL
                    if (extractedUrls as AnyObject).host?.contains("m.youtube.com") == true {
                        var components = URLComponents(string: (extractedUrls as AnyObject).absoluteString as! String)
                        components?.host = "www.youtube.com"
                        if let _url = components?.url {
                            url = _url
                        } else {
                            url = extractedUrls as! URL
                        }
                    } else {
                        url = extractedUrls as! URL
                    }

                    cell.urlPreviewViewHeightConstraint.constant = 60
                    print("Exrtracted URL: \(url.absoluteString) Index:\(indexPath.row)")

                    let embeddedView = URLEmbeddedView()
                    //                    embeddedView.loadURL(url.absoluteString)
                    embeddedView.load(urlString: url.absoluteString)
                    embeddedView.borderColor = .clear
                    embeddedView.cornerRaidus = 0
                    embeddedView.frame = CGRect(x: 0, y:0, width: cell.frame.width - 20, height: 60)
                    embeddedView.didTapHandler = { [weak self] _, url in
                        guard let url = url else { return }
                        self?.present(SFSafariViewController(url: url), animated: true, completion: nil)
                    }
                    for view in cell.urlEmbededViewOutlet.subviews {
                        if let ev = view as? URLEmbeddedView {
                            ev.cancelLoading()
                            ev.removeFromSuperview()
                        }
                    }

                    cell.urlEmbededViewOutlet.addSubview(embeddedView)

                }
            }
            else{
                for view in cell.urlEmbededViewOutlet.subviews {
                    if let ev = view as? URLEmbeddedView {
                        ev.cancelLoading()
                        ev.removeFromSuperview()
                    }
                }
                cell.urlPreviewViewHeightConstraint.constant = 0
            }

Added the entire code in the descrition. Please suggest if you found any edits in existing code as well. Waiting for to hear from you. Thanks in advance :)

sarathdev commented 5 years ago

39 #41 @marty-suzuki Please help me to resolve this issue asap adding a sample link that copied from youtube app in phone "https://youtu.be/f_UWq8lXfYo". Thanks in advance