Skip to content

Instantly share code, notes, and snippets.

@kylehowells
Last active April 14, 2019 07:26
Show Gist options
  • Select an option

  • Save kylehowells/03d5cf4ff42be13f00f6 to your computer and use it in GitHub Desktop.

Select an option

Save kylehowells/03d5cf4ff42be13f00f6 to your computer and use it in GitHub Desktop.
Easily get the url of a YouTube video's different thumbnails
/**
What size and quailty youtube thumbnail you want.
- Zero: Player Background: (480x360 pixels) (same as High)
- One: Start: (120x90 pixels)
- Two: Middle: (120x90 pixels)
- Three: End: (120x90 pixels)
- Default: Normal: (120x90 pixels)
- Medium: Medium: (320x180 pixels)
- High: High: (480x360 pixels) (same as 0)
- Standard: SD: (640x480 pixels) (HQ videos only)
- Max: HD: (1920x1080 pixels) (HQ videos only)
*/
enum ThumbnailQuailty : String {
case Zero = "0.jpg"
case One = "1.jpg"
case Two = "2.jpg"
case Three = "3.jpg"
case Default = "default.jpg"
case Medium = "mqdefault.jpg"
case High = "hqdefault.jpg"
case Standard = "sddefault.jpg"
case Max = "maxresdefault.jpg"
/// All values sorted by image size (1,2,3 are the same size)
static let allValues = [Default, One, Two, Three, Medium, High, Zero, Standard, High]
}
func thumbnailURLString(videoID:String, quailty: ThumbnailQuailty = .Default) -> String {
//return "http://img.youtube.com/vi/\(videoID)/\(quailty.rawValue)"
return "http://i1.ytimg.com/vi/\(videoID)/\(quailty.rawValue)"
}
@kylehowells
Copy link
Author

@ilirvg
Copy link

ilirvg commented Jun 17, 2015

Can you please tell me how can I add the video ID in this function. Can you show me an exact example where u use a real youtube video.

Cheers,
Ilir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment