Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // VideoModel.swift
- // VideoAppTest
- //
- // Created by Mihail Gospodinov on 18/04/2020.
- // Copyright © 2020 Mihail Gospodinov. All rights reserved.
- //
- import UIKit
- import Alamofire
- class VideoModel: UIViewController {
- let API_KEY = "AIzaSyC6VqfD4g0IQcPONotrsoqCPiZ5EbiDkus"
- let UPLOADS_PLAYLIST_ID = "PLLcWaXwA6Lx7Sx_7jy-ztY8xIxub49s8A"
- var videoArray = [Video]()
- func getFeedVedeos() {
- //fetch the videos dinamically through the YouTube Data Api
- Alamofire.request("https://www.googleapis.com/youtube/v3/playlistItems", method: .get, parameters: ["part":"snippet", "playlistId":UPLOADS_PLAYLIST_ID, "key":API_KEY], encoding: URLEncoding.default, headers: nil).responseJSON { (response) in
- if let JSON = response.result.value as? [String:Any] {
- var arrayOfVideos = [Video]()
- if let videos = JSON["items"] as? [[String:Any]] {
- for video in videos {
- //print(video)
- let videoObj = Video()
- // videoObj.videoId = ""
- if let videoId = video["snippet.resourceId.videoId"] as? String {
- videoObj.videoId = videoId
- //videoObj.videoId ="" - a dont't know why again stay empty?
- }
- // videoObj.videoTitle = ""
- if let videoTitle = video["snippet.title"] as? String {
- videoObj.videoTitle = videoTitle
- //videoObj.videoTitle ="" - a dont't know why again stay empty?
- }
- if let videoDescription = video["snippet.description"] as? String {
- videoObj.videoDescription = videoDescription
- //videoObj.videoDescription ="" - a dont't know why again stay empty?
- }
- if let videoThumbnailUrl = video["snippet.thumbnails.maxres.url"] as? String {
- videoObj.videoThumbnailUrl = videoThumbnailUrl
- //videoObj.videoThumnailUrl ="" - a dont't know why again stay empty?
- }
- arrayOfVideos.append(videoObj)
- }
- self.videoArray = arrayOfVideos
- }
- }
- }
- }
- func getVideo() -> [Video] {
- //Create empty videos objects
- var videos = [Video]()
- //Create video object
- let video1 = Video()
- //Assing properties
- video1.videoId = "OS_I7HAd0eM"
- video1.videoTitle = "Granny is Mr Bean!"
- video1.videoDescription = "Welcome to Granny."
- //Append it to the video arrays
- videos.append(video1)
- //Create video object
- let video2 = Video()
- //Assing properties
- video2.videoId = "YwkqZUePO-8"
- video2.videoTitle = "ПРИЯТЕЛЯТ НА СТРАШНАТА УЧИТЕЛКА МАРИЙКА ?!?"
- video2.videoDescription = "Welcome to Granny."
- //Append it to the video arrays
- videos.append(video2)
- //Create video object
- let video3 = Video()
- //Assing properties
- video3.videoId = "neANKFhRmvY"
- video3.videoTitle = "😴 ПРИСПАХМЕ ГРАНИ 😴 - Granny"
- video3.videoDescription = "Welcome to Granny."
- //Append it to the video arrays
- videos.append(video3)
- //Create video object
- let video4 = Video()
- //Assing properties
- video4.videoId = "WRVmbwMLJeg"
- video4.videoTitle = "СТРАШНАТА УЧИТЕЛКА МАРИЙКА НА ФИТНЕС"
- video4.videoDescription = "Welcome to Granny."
- //Append it to the video arrays
- videos.append(video4)
- //Create video object
- let video5 = Video()
- //Assing properties
- video5.videoId = "VVJbLZvyEzQ"
- video5.videoTitle = "СТРАШНАТА УЧИТЕЛКА МАРИЙКА СЕ РАЗБОЛЯ"
- video5.videoDescription = "Welcome to Granny."
- //Append it to the video arrays
- videos.append(video5)
- return videos
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- }
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement