来自 Google Drive Swift 的 iOS Stream 视频 [英] iOS Stream video from Google drive Swift
问题描述
我正在构建一个 iOS 应用程序,来自 Google 的 Stream 视频驱动视频链接如下
I'm building an iOS app that Stream's video from Google drive the videos link looks like this
https://drive.google.com/file/d/0B2Kri7-TaAFJSlJ4UTJuSElGamM/预览
从上面的 URL 获取流链接的唯一方法是解码 webView HTML
The only way to get the Stream Link from the URL above is by Decoding the webView HTML
let myURLString = "https://drive.google.com/file/d/0B2Kri7-TaAFJSlJ4UTJuSElGamM/preview"
if let myURL = NSURL(string: myURLString) {
do {
let myHTMLString = try String(contentsOfURL: myURL, encoding: NSUTF8StringEncoding)
print("HTML : \(myHTMLString)")
} catch {
print("Error : \(error)")
}
} else {
print("Error: \(myURLString) doesn't URL")
}
这样做之后,我得到了 webView 的 HTML
after doing that i get the HTML for the webView
问题是:
我在 HTML 中寻找的是fmt_stream_map",其中包含我也需要的所有流媒体链接 流视频,但我不知道如何访问并获取来自它的 Steam 链接.
What I'm looking for in the HTML is this "fmt_stream_map" this contain is all the Streaming Links that I need too Stream the video but I don't know how to access it and get the Steam Links from it.
PS:我正在与一位 Android 开发人员合作,他告诉我他使用了这个 解决问题的方法,但他无法向我解释,我也不知道 java
PS: I'm Working with an Android Developer and he told me he used this method to solve the issue but he couldn't explain it to me and I don't know java
推荐答案
我使用的方法解决了这个问题:
I fixed the problem using the method :
let myURLString = "https://drive.google.com/file/d/0B1XhqDeOfqG7UWZSaG1ZbFFhSzQ/preview"
if let myURL = NSURL(string: myURLString) {
do {
let myHTMLString = try String(contentsOfURL: myURL, encoding: NSUTF8StringEncoding)
let t = myHTMLString
if let rangeOfZero = t.rangeOfString("plid", options: NSStringCompareOptions.BackwardsSearch) {
let suffix = String(t.characters.suffixFrom(rangeOfZero.endIndex))
// print(suffix)
let input = "\(suffix)"
let detector = try! NSDataDetector(types: NSTextCheckingType.Link.rawValue)
let matches = detector.matchesInString(input, options: [], range: NSRange(location: 0, length: input.utf8.count))
// print(matches)
for match in matches {
let url = (input as NSString).substringWithRange(match.range)
linksA.append(url)
}
theLink()
} else {
print("noooo")
}
} catch {
print("Error : \(error)")
}
} else {
print("Error: \(myURLString) doesn't URL")
}
之后您需要使用此方法解码流媒体链接:
afther that you need to decode the streaming link using this method :
func theLink() {
/// /[u]00../g
let firstElement = linksA.first
let t = firstElement!.stringByReplacingOccurrencesOfString(",35", withString: "")
let deUrl = t.characters.split{$0 == "|"}.map(String.init)
let link = deUrl[0]
// the link needs to be decoded
let i = link.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
let p = i!.stringByReplacingOccurrencesOfString("%5Cu", withString: "")
// you can see how the link should look like here :
// http://ddecode.com/hexdecoder/?results=d82d4e564eccc1a6b96ee7c5c1e1c3b2
// %252C : ,
// 003d : =
// 0026 : &
let re = p.stringByReplacingOccurrencesOfString("003d", withString: "=")
let y = re.stringByReplacingOccurrencesOfString("0026", withString: "&")
let c = y.stringByReplacingOccurrencesOfString("%252C", withString: ",")
print(c) }
您可以在此处
这篇关于来自 Google Drive Swift 的 iOS Stream 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!