mirror of
				https://github.com/yattee/yattee.git
				synced 2025-10-30 12:11:59 +00:00 
			
		
		
		
	Added caption support for Piped backend (#867)
Co-authored-by: Ivan <ivanferrari@porch.com>
This commit is contained in:
		| @@ -591,7 +591,8 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { | ||||
|             dislikes: details["dislikes"]?.int, | ||||
|             streams: extractStreams(from: content), | ||||
|             related: extractRelated(from: content), | ||||
|             chapters: extractChapters(from: content) | ||||
|             chapters: extractChapters(from: content), | ||||
|             captions: extractCaptions(from: content) | ||||
|         ) | ||||
|     } | ||||
|  | ||||
| @@ -818,6 +819,24 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { | ||||
|             return Chapter(title: title, image: image, start: start) | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     private func extractCaptions(from content: JSON) -> [Captions] { | ||||
|         content["subtitles"].arrayValue.compactMap { details in | ||||
|             guard let url = details["url"].url, | ||||
|                   let code = details["code"].string, | ||||
|                   let label = details["name"].string, | ||||
|                   var components = URLComponents(url: url, resolvingAgainstBaseURL: false) | ||||
|             else { return nil } | ||||
|              | ||||
|             components.queryItems = components.queryItems?.map { item in | ||||
|                 item.name == "fmt" ? URLQueryItem(name: "fmt", value: "srt") : item | ||||
|             } | ||||
|              | ||||
|             guard let newUrl = components.url else { return nil } | ||||
|              | ||||
|             return Captions(label: label, code: code, url: newUrl) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private func contentItemsDictionary(from content: JSON) -> JSON { | ||||
|         if let key = Self.contentItemsKeys.first(where: { content.dictionaryValue.keys.contains($0) }), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Ivan0xFF
					Ivan0xFF