Last active
April 14, 2019 07:26
-
-
Save kylehowells/03d5cf4ff42be13f00f6 to your computer and use it in GitHub Desktop.
Easily get the url of a YouTube video's different thumbnails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| 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)" | |
| } |
Author
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
Based on all the answers to this question: http://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api