Advertisement
gospod1978

YOUTUBEAPP

Apr 21st, 2020
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 4.84 KB | None | 0 0
  1. //
  2. //  VideoModel.swift
  3. //  VideoAppTest
  4. //
  5. //  Created by Mihail Gospodinov on 18/04/2020.
  6. //  Copyright © 2020 Mihail Gospodinov. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import Alamofire
  11.  
  12. class VideoModel: UIViewController {
  13.  
  14.     let API_KEY = "AIzaSyC6VqfD4g0IQcPONotrsoqCPiZ5EbiDkus"
  15.     let UPLOADS_PLAYLIST_ID = "PLLcWaXwA6Lx7Sx_7jy-ztY8xIxub49s8A"
  16.    
  17.     var videoArray = [Video]()
  18.    
  19.     func getFeedVedeos() {
  20.        
  21.         //fetch the videos dinamically through the YouTube Data Api
  22.         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
  23.            
  24.             if let JSON = response.result.value as? [String:Any] {
  25.  
  26.                var arrayOfVideos = [Video]()
  27.  
  28.                if let videos = JSON["items"] as? [[String:Any]] {
  29.  
  30.                   for video in videos {
  31.                         //print(video)
  32.                       let videoObj = Video()
  33.  
  34.                     // videoObj.videoId = ""
  35.                     if let videoId = video["snippet.resourceId.videoId"] as? String {
  36.                           videoObj.videoId = videoId
  37.                     //videoObj.videoId ="" - a dont't know why again stay empty?
  38.                       }
  39.                         // videoObj.videoTitle = ""
  40.                     if let videoTitle = video["snippet.title"] as? String {
  41.  
  42.                           videoObj.videoTitle = videoTitle
  43.                         //videoObj.videoTitle ="" - a dont't know why again stay empty?
  44.                       }
  45.                       if let videoDescription = video["snippet.description"] as? String {
  46.  
  47.                           videoObj.videoDescription = videoDescription
  48.                         //videoObj.videoDescription ="" - a dont't know why again stay empty?
  49.                       }
  50.                       if let videoThumbnailUrl = video["snippet.thumbnails.maxres.url"] as? String {
  51.  
  52.                           videoObj.videoThumbnailUrl = videoThumbnailUrl
  53.                             //videoObj.videoThumnailUrl ="" - a dont't know why again stay empty?
  54.                       }
  55.                    
  56.  
  57.                       arrayOfVideos.append(videoObj)
  58.                   }
  59.                
  60.                 self.videoArray = arrayOfVideos
  61.                
  62.                }
  63.             }
  64.            
  65.         }
  66.     }
  67.    
  68.     func getVideo() -> [Video] {
  69.         //Create empty videos objects
  70.         var videos = [Video]()
  71.        
  72.         //Create video object
  73.         let video1 = Video()
  74.        
  75.         //Assing properties
  76.         video1.videoId = "OS_I7HAd0eM"
  77.         video1.videoTitle = "Granny is Mr Bean!"
  78.         video1.videoDescription = "Welcome to Granny."
  79.  
  80.         //Append it to the video arrays
  81.         videos.append(video1)
  82.        
  83.         //Create video object
  84.         let video2 = Video()
  85.        
  86.         //Assing properties
  87.         video2.videoId = "YwkqZUePO-8"
  88.         video2.videoTitle = "ПРИЯТЕЛЯТ НА СТРАШНАТА УЧИТЕЛКА МАРИЙКА ?!?"
  89.         video2.videoDescription = "Welcome to Granny."
  90.  
  91.         //Append it to the video arrays
  92.         videos.append(video2)
  93.        
  94.         //Create video object
  95.         let video3 = Video()
  96.        
  97.         //Assing properties
  98.         video3.videoId = "neANKFhRmvY"
  99.         video3.videoTitle = "😴 ПРИСПАХМЕ ГРАНИ 😴 - Granny"
  100.         video3.videoDescription = "Welcome to Granny."
  101.  
  102.         //Append it to the video arrays
  103.         videos.append(video3)
  104.        
  105.         //Create video object
  106.         let video4 = Video()
  107.        
  108.         //Assing properties
  109.         video4.videoId = "WRVmbwMLJeg"
  110.         video4.videoTitle = "СТРАШНАТА УЧИТЕЛКА МАРИЙКА НА ФИТНЕС"
  111.         video4.videoDescription = "Welcome to Granny."
  112.  
  113.         //Append it to the video arrays
  114.         videos.append(video4)
  115.        
  116.         //Create video object
  117.         let video5 = Video()
  118.        
  119.         //Assing properties
  120.         video5.videoId = "VVJbLZvyEzQ"
  121.         video5.videoTitle = "СТРАШНАТА УЧИТЕЛКА МАРИЙКА СЕ РАЗБОЛЯ"
  122.         video5.videoDescription = "Welcome to Granny."
  123.  
  124.         //Append it to the video arrays
  125.         videos.append(video5)
  126.        
  127.         return videos
  128.     }
  129.    
  130.     override func viewDidLoad() {
  131.         super.viewDidLoad()
  132.  
  133.         // Do any additional setup after loading the view.
  134.     }
  135.    
  136.  
  137.     /*
  138.     // MARK: - Navigation
  139.  
  140.     // In a storyboard-based application, you will often want to do a little preparation before navigation
  141.     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  142.         // Get the new view controller using segue.destination.
  143.         // Pass the selected object to the new view controller.
  144.     }
  145.     */
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement