1

I want to get a thumbnail image for videos from Rumble.

When getting images from Youtube I just do like this:

https://img.youtube.com/vi/f3ZccBBjmQg/0.jpg

Want to same from Rumble video url-

https://rumble.com/vxhedt-80000-matches-chain-reaction-domino-effect.html?mref=7ju1&mc=4w36m
iDeveloper
  • 2,339
  • 2
  • 24
  • 38
  • Have you checked [this post](https://stackoverflow.com/questions/31779150/creating-thumbnail-from-local-video-in-swift)? They create an url extension for creating a thumbnail on their own. – LoVo Apr 25 '22 at 06:35
  • Yes I checked, They are creating from a local video(Available in Device), But I want from Video URL – iDeveloper Apr 25 '22 at 06:39
  • @iDeveloper I really don't know about swift, but, if you're ok wiith web-scraping, you can search for the `meta` tag that has the `property="og:image"` key/value combination on the page; in your case, could be: `` – Marco Aurelio Fernandez Reyes Apr 25 '22 at 22:04
  • @MarcoAurelioFernandezReyes Thanks for suggestion but still I am looking for some native way, Because its not about single image thumbnail, It will be a dynamic list view of these types images – iDeveloper Apr 26 '22 at 05:10

1 Answers1

1

I checked the rumble webpage of the link you provided. I am not sure if there is a smarter/faster way but here is a way to get the thumbnailUrl from their html code.

func getThumbnailFromRumble() {
        let url = URL(string:"https://rumble.com/vxhedt-80000-matches-chain-reaction-domino-effect.html?mref=7ju1&mc=4w36m")!
        URLSession.shared.dataTask(with: url){ data, response, error in
                guard error == nil else { return }
                guard let httpURLResponse = response as? HTTPURLResponse,
                      httpURLResponse.statusCode == 200,
                      let data = data else {
                    return
                }
                
            let str = String(data: data, encoding: .utf8) // get the htm response as string
            let prefix = "\"thumbnailUrl\":" 
            let suffix = ",\"uploadDate\""   
            
            let matches = str?.match("(\(prefix)(...*)\(suffix))")
            if let thumbnailUrlMatch = matches?.first?.first {
                let thumbnailUrl = thumbnailUrlMatch
                    .replacingOccurrences(of: prefix, with: "") // remove prefix from urlstring
                    .replacingOccurrences(of: suffix, with: "") // remove suffix from urlstring
                    .replacingOccurrences(of: "\"", with: "") // remove escaping characters from urlstring
                
                if let url = URL(string: thumbnailUrl),
                   let data = try? Data(contentsOf: url) {
                    
                     let uiImage = UIImage(data: data)
                     // use the uiimage        
                }
            }
            
        }.resume()
    }

I use this extension to get the necessary string part from the html response

extension String {
    func match(_ regex: String) -> [[String]] {
        let nsString = self as NSString
        return (try? NSRegularExpression(pattern: regex, options: []))?.matches(in: self, options: [], range: NSMakeRange(0, nsString.length)).map { match in
            (0..<match.numberOfRanges).map { match.range(at: $0).location == NSNotFound ? "" : nsString.substring(with: match.range(at: $0)) }
        } ?? []
    }
}

Feel free to improve the code.

LoVo
  • 1,856
  • 19
  • 21
  • 1
    Thanks for your effort, but I am looking for some native way like youtube provide simple link to get video thumbnail, Just by passing video Id. – iDeveloper Apr 25 '22 at 09:41
  • Yeah, that's what i thought, so you probably need to check if they even provide that functionality. – LoVo Apr 25 '22 at 10:38