Untitled

mail@pastecode.io avatar
unknown
swift
a year ago
1.6 kB
5
Indexable
Never
//https://stackoverflow.com/questions/18953499/youtube-api-to-fetch-all-videos-on-a-channel   
   
   
    func checkTest(_ urlString: String) {
//        DispatchQueue.main.sync {
//            self.checkUrl(urlString: urlString)
//        }
        awaitedResult(urlString)
    }
    
    func awaitedResult(_ urlString: String) {
        Task {
            let result = await checkUrl(urlString: urlString)
            
//            let stream = try await YouTube(videoID: "0HHBe5V6B0").streams
//                .filter { $0.isProgressive && $0.subtype == "mp4" && $0.includesVideoTrack }
//                .highestResolutionStream()
//            print("url - item: \(stream?.url.absoluteString)")


        }
    }
    
    
    func checkUrl(urlString: String) async  {
        if let url = URL(string: urlString) {
            
                let video = YouTube(url: url)
            do {
                let streams = try await video.streams
//                    .filter { $0.isProgressive && $0.subtype == "mp4" }
                    .filter { $0.subtype == "mp4" && $0.includesVideoTrack }
//                    .filterVideoOnly()
//                                    .filter { $0.subtype == "mp4"}
                    .highestResolutionStream()
                
                print("url - item: \(streams?.url.absoluteString)")

                
//                
//                for item in streams  {
//                    print("url - item: \(item.url.absoluteString)")
//                }
            } catch {}
        }
    }