Skip to content

ezefranca/youtube-metadata-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

youtube-metadata-swift

Get YouTube metadata without YouTube API

How to get a video metadata from url

let vid = "https://youtu.be/TRqiFPpw2fY"
let req = YTMetadataRequester()
req.getMetadata(for: vid) { metadata in
    print(metadata)
} failed: { error in
    print(error.debugDescription)
}

Response

{
  title: 'Foo Fighters - The Sky Is A Neighborhood (Official Music Video)',
  author_name: 'foofightersVEVO',
  author_url: 'https://www.youtube.com/user/foofightersVEVO',
  type: 'video',
  height: 113,
  width: 200,
  version: '1.0',
  provider_name: 'YouTube',
  provider_url: 'https://www.youtube.com/',
  thumbnail_height: 360,
  thumbnail_width: 480,
  thumbnail_url: 'https://i.ytimg.com/vi/TRqiFPpw2fY/hqdefault.jpg',
  html: '<iframe width="200" height="113" src="https://www.youtube.com/embed/TRqiFPpw2fY?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
}
// MARK: -Metadata
struct Metadata: Codable {
    let authorName: String
    let authorURL: String
    let height: Int
    let html, providerName: String
    let providerURL: String
    let thumbnailHeight: Int
    let thumbnailURL: String
    let thumbnailWidth: Int
    let title, type, version: String
    let width: Int
}

How to use

You can use this code directly or get the ideia to use with your own Internet Lib (Alamofire, etc). It's a simple GET request to the embedded youtube URL.

Related

A npm module with the same purpose

License

This project is provided for educational purposes only. It is not affiliated with and has not been approved by Youtube.