created working app with art auth system
This commit is contained in:
parent
4e27608cf7
commit
c004962c41
|
@ -41,8 +41,8 @@ struct SeasonView: View {
|
||||||
var season: Season
|
var season: Season
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView(){
|
NavigationView(){
|
||||||
List(season.episodes, id:\.self){ episode in
|
List(season.getEpisodes(), id:\.self){ episode in
|
||||||
NavigationLink(destination: VideoView(url: episode.video.hlsUrl)){
|
NavigationLink(destination: VideoView(episode: episode)){
|
||||||
VStack{
|
VStack{
|
||||||
Text(episode.name)
|
Text(episode.name)
|
||||||
AsyncImage(url: episode.imageurl,placeholder: {
|
AsyncImage(url: episode.imageurl,placeholder: {
|
||||||
|
@ -57,9 +57,11 @@ struct SeasonView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VideoView: View {
|
struct VideoView: View {
|
||||||
var url: URL
|
var episode: Episode
|
||||||
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
let url = episode.getVideo().hlsUrl
|
||||||
let player = AVPlayer(url: url);
|
let player = AVPlayer(url: url);
|
||||||
VideoPlayer(player: player).fixedSize()
|
VideoPlayer(player: player).fixedSize()
|
||||||
};
|
};
|
||||||
|
@ -68,7 +70,8 @@ struct VideoView: View {
|
||||||
}
|
}
|
||||||
struct ContentView_Previews: PreviewProvider {
|
struct ContentView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
SeasonView(season: VRTNu().shows[0].getSeasons()[0])
|
//SeasonView(season: VRTNu().shows[0].getSeasons()[0])
|
||||||
|
ContentView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,41 +10,172 @@ import Foundation
|
||||||
|
|
||||||
struct Episode: Hashable{
|
struct Episode: Hashable{
|
||||||
let name: String
|
let name: String
|
||||||
let video: Video
|
let season: Season
|
||||||
|
|
||||||
|
|
||||||
|
lazy var video: Video = {
|
||||||
|
let just = JustOf<HTTP>()
|
||||||
|
//`requests.get('https://www.vrt.be/vrtnu/a-z/%s/%s/%s.mssecurevideo.json' % (show, season, episode)).json()`
|
||||||
|
let url = "https://www.vrt.be/vrtnu/a-z/" + season.show.showName + "/" + season.seasonName + "/" + name + ".mssecurevideo.json"
|
||||||
|
let msecjson = just.get(url).json!
|
||||||
|
let mssecdict = msecjson as! NSDictionary
|
||||||
|
print(msecjson)
|
||||||
|
print(mssecdict.allValues[0])
|
||||||
|
let intmssecdict = mssecdict.allValues[0] as! NSDictionary
|
||||||
|
print(intmssecdict)
|
||||||
|
let videoid = intmssecdict.value(forKey: "videoid") as! String
|
||||||
|
let clientid = intmssecdict.value(forKey: "clientid") as! String
|
||||||
|
|
||||||
|
/*
|
||||||
|
get login token
|
||||||
|
```
|
||||||
|
session = requests.session()
|
||||||
|
username = urllib.parse.quote('<vrtnu username here>', safe='')
|
||||||
|
password = urllib.parse.quote('<vrtnu password here>', safe='')
|
||||||
|
auth_data = {
|
||||||
|
'APIKey': '3_0Z2HujMtiWq_pkAjgnS2Md2E11a1AwZjYiBETtwNE-EoEHDINgtnvcAOpNgmrVGy',
|
||||||
|
'targetEnv': 'jssdk',
|
||||||
|
'loginID': username,
|
||||||
|
'password': password,
|
||||||
|
'authMode': 'cookie',
|
||||||
|
}
|
||||||
|
auth_info = requests.post('https://accounts.eu1.gigya.com/accounts.login', data=auth_data).json()
|
||||||
|
# When requesting a token, no actual token is returned, but the
|
||||||
|
# necessary cookies are set.
|
||||||
|
session.post('https://token.vrt.be',
|
||||||
|
headers={
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Referer': 'https://www.vrt.be/vrtnu/',
|
||||||
|
},
|
||||||
|
data=json.dumps({
|
||||||
|
'uid': auth_info['UID'],
|
||||||
|
'uidsig': auth_info['UIDSignature'],
|
||||||
|
'ts': auth_info['signatureTimestamp'],
|
||||||
|
'email': auth_info['profile']['email'],
|
||||||
|
}).encode('utf-8'))
|
||||||
|
token = session.post('https://media-services-public.vrt.be/vualto-video-aggregator-web/rest/external/v1/tokens', headers={'Content-Type': 'application/json'}, data=b'').json()['vrtPlayerToken']
|
||||||
|
```*/
|
||||||
|
let username = "testuser"
|
||||||
|
let password = "testpw"
|
||||||
|
let auth_data = [
|
||||||
|
"ApiKey": "3_0Z2HujMtiWq_pkAjgnS2Md2E11a1AwZjYiBETtwNE-EoEHDINgtnvcAOpNgmrVGy",
|
||||||
|
"targetEnv": "jssdk",
|
||||||
|
"loginID": username,
|
||||||
|
"password": password,
|
||||||
|
"authMode": "cookie",
|
||||||
|
]
|
||||||
|
let auth_json = just.post("https://accounts.eu1.gigya.com/accounts.login", data: auth_data).json!
|
||||||
|
let auth_info = auth_json as! NSDictionary
|
||||||
|
// no token is returnd but necessary cookies are set
|
||||||
|
just.post("https://token.vrt.be", json:[
|
||||||
|
"uid": auth_info.value(forKey: "UID"),
|
||||||
|
"uidsig": auth_info.value(forKey: "UIDSignature"),
|
||||||
|
"ts": auth_info.value(forKey: "signatureTimestamp"),
|
||||||
|
//"email": auth_info.value(forKey: "profile"['email'],
|
||||||
|
"email": username
|
||||||
|
],
|
||||||
|
headers: [
|
||||||
|
"Conetnt-Type": "application/json",
|
||||||
|
"Referer": "https://www.vrt.be/vrtnu/",
|
||||||
|
]
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
///token = session.post('https://media-services-public.vrt.be/vualto-video-aggregator-web/rest/external/v1/tokens', headers={'Content-Type': 'application/json'}, data=b'').json()['vrtPlayerToken']
|
||||||
|
|
||||||
|
let tokenjson = just.post("https://media-services-public.vrt.be/vualto-video-aggregator-web/rest/external/v1/tokens", headers:["Content-Type": "application/json"]).json!
|
||||||
|
let tokendict = tokenjson as! NSDictionary
|
||||||
|
let token = tokendict.value(forKey: "vrtPlayerToken") as! String
|
||||||
|
|
||||||
|
|
||||||
|
var mediaurl = "https://media-services-public.vrt.be/vualto-video-aggregator-web/rest/external/v1/videos/" + videoid
|
||||||
|
mediaurl = mediaurl + "?vrtPlayerToken="
|
||||||
|
mediaurl = mediaurl + token + "&client="
|
||||||
|
mediaurl = mediaurl + clientid + "@PROD"
|
||||||
|
print(mediaurl)
|
||||||
|
let videojson = just.get(mediaurl).json!
|
||||||
|
let videodict = videojson as! NSDictionary
|
||||||
|
let duration = videodict.value(forKey: "duration") as! Double
|
||||||
|
let title = videodict.value(forKey: "title") as! String
|
||||||
|
let targetURLs = videodict.value(forKey: "targetUrls") as! [NSDictionary]
|
||||||
|
let videourl = targetURLs[0].value(forKey: "url") as! String
|
||||||
|
//session.get('https://media-services-public.vrt.be/vualto-video-aggregator-web/rest/external/v1/videos/%s?vrtPlayerToken=%s&client=%s@PROD' %(video_id, token, clientid)).json()
|
||||||
|
return Video(hlsUrl: URL(string: videourl)!,
|
||||||
|
title: title,
|
||||||
|
duration: duration)
|
||||||
|
}()
|
||||||
let imageurl: URL
|
let imageurl: URL
|
||||||
|
|
||||||
init(episodeurl: URL){
|
init(season: Season, episodeName: String){
|
||||||
self.name = "test"
|
self.name = episodeName
|
||||||
self.video = Video(hlsUrl: URL(string: "https://remix-cf.lwc.vrtcdn.be/remix/ecd69313-4a39-4297-95b1-aede167725b7/remix.ism/.m3u8")!,
|
self.season = season
|
||||||
title: "best of dinges",
|
|
||||||
duration: 2946)
|
|
||||||
self.imageurl = URL(string: "https://images.vrt.be/w320hx/2019/05/02/dbc03914-6cbc-11e9-abcc-02b7b76bf47f.jpg")!
|
self.imageurl = URL(string: "https://images.vrt.be/w320hx/2019/05/02/dbc03914-6cbc-11e9-abcc-02b7b76bf47f.jpg")!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getVideo() -> Video{
|
||||||
|
var lazyself = self
|
||||||
|
return lazyself.video
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getData(url: URL, regexPattern: String) -> [String]{
|
||||||
|
let data = Just.get(url).text!
|
||||||
|
print(data)
|
||||||
|
let range = NSRange(location: 0, length: data.count)
|
||||||
|
let regex = try! NSRegularExpression(pattern: regexPattern)
|
||||||
|
let matches = regex.matches(in: data, range: range)
|
||||||
|
let nsString = data as NSString
|
||||||
|
let output = Array(Set(matches.map {nsString.substring(with: $0.range)}))
|
||||||
|
print(output)
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
struct Season: Hashable{
|
struct Season: Hashable{
|
||||||
static func == (lhs: Season, rhs: Season) -> Bool {
|
static func == (lhs: Season, rhs: Season) -> Bool {
|
||||||
return lhs.seasonUrl == rhs.seasonUrl
|
return lhs.seasonUrl == rhs.seasonUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
let title: String
|
let title: String
|
||||||
let showName: String
|
let show: Show
|
||||||
let seasonName: String
|
|
||||||
let seasonUrl: URL
|
let seasonUrl: URL
|
||||||
let episodes: [Episode]
|
let seasonName: String
|
||||||
|
|
||||||
init(showName: String, seasonName: String, title: String){
|
lazy var episodes: [Episode] = {
|
||||||
self.showName = showName
|
//`set(re.findall('vrtnu/a-z/%s/%s/([^"]*)/' %(show, season),requests.get('https://www.vrt.be/vrtnu/a-z/%s/%s.lists.all-episodes/' % (show, season)).text))`
|
||||||
|
|
||||||
|
let regexPattern = "vrtnu/a-z/" + show.showName + "/" + seasonName + "/([^\"]*)/"
|
||||||
|
let output = getData(url: URL(string: "https://www.vrt.be/vrtnu/a-z/" + show.showName + "/" + seasonName + ".lists.all-episodes/")!, regexPattern: regexPattern)
|
||||||
|
|
||||||
|
var episode: String
|
||||||
|
var myepisodes: [Episode]
|
||||||
|
myepisodes = []
|
||||||
|
for i in 0 ..< output.count{
|
||||||
|
episode = output[i].replacingOccurrences(of: "vrtnu/a-z/" + show.showName + "/" + seasonName + "/", with: "").replacingOccurrences(of: "/", with: "")
|
||||||
|
print(episode)
|
||||||
|
print(seasonName)
|
||||||
|
myepisodes.append(Episode(season: self, episodeName: episode))
|
||||||
|
}
|
||||||
|
|
||||||
|
return myepisodes
|
||||||
|
|
||||||
|
|
||||||
|
}()
|
||||||
|
|
||||||
|
init(show: Show, seasonName: String, title: String){
|
||||||
|
self.show = show
|
||||||
self.title = title
|
self.title = title
|
||||||
self.seasonName = seasonName
|
self.seasonName = seasonName
|
||||||
print(seasonName)
|
print(seasonName)
|
||||||
print(showName)
|
print(show.showName)
|
||||||
self.seasonUrl = URL(string: "https://www.vrt.be/vrtnu/a-z/" + showName + "/" + seasonName)!
|
self.seasonUrl = URL(string: "https://www.vrt.be/vrtnu/a-z/" + show.showName + "/" + seasonName)!
|
||||||
self.episodes = [
|
|
||||||
Episode(episodeurl: URL(string: "https://www.vrt.be/vrtnu/a-z/het-peulengaleis/2005-hm/het-peulengaleis-s2005-hma1/")!)
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getEpisodes() -> [Episode]{
|
||||||
|
var mutableself = self
|
||||||
|
return mutableself.episodes
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Show: Hashable{
|
struct Show: Hashable{
|
||||||
|
@ -57,18 +188,10 @@ struct Show: Hashable{
|
||||||
let title: String
|
let title: String
|
||||||
lazy var seasons: [Season] = {
|
lazy var seasons: [Season] = {
|
||||||
//`re.findall('value="#parsys_container_banner_%s_(.*)">' % show, requests.get('https://www.vrt.be/vrtnu/a-z/%s/' % show).text)`
|
//`re.findall('value="#parsys_container_banner_%s_(.*)">' % show, requests.get('https://www.vrt.be/vrtnu/a-z/%s/' % show).text)`
|
||||||
let seasonsdata = Just.get(showUrl).text!
|
|
||||||
print(seasonsdata)
|
let regexPattern = "value=\"#parsys_container_banner_" + showName + "_(.*)\">"
|
||||||
|
let output = getData(url: showUrl, regexPattern: regexPattern)
|
||||||
|
|
||||||
let range = NSRange(location: 0, length: seasonsdata.count)
|
|
||||||
let regex = try! NSRegularExpression(pattern: "value=\"#parsys_container_banner_"
|
|
||||||
+ showName + "_(.*)\">")
|
|
||||||
let seasons = regex.matches(in: seasonsdata, range: range)
|
|
||||||
let nsString = seasonsdata as NSString
|
|
||||||
|
|
||||||
let output = Array(Set(seasons.map {nsString.substring(with: $0.range)}))
|
|
||||||
|
|
||||||
print(output)
|
|
||||||
var season: String
|
var season: String
|
||||||
var myseasons: [Season]
|
var myseasons: [Season]
|
||||||
myseasons = []
|
myseasons = []
|
||||||
|
@ -77,7 +200,7 @@ struct Show: Hashable{
|
||||||
+ showName + "_", with: "").replacingOccurrences(of: "\">", with: "")
|
+ showName + "_", with: "").replacingOccurrences(of: "\">", with: "")
|
||||||
print(season)
|
print(season)
|
||||||
print(showName)
|
print(showName)
|
||||||
myseasons.append(Season(showName: showName, seasonName: season, title: season))
|
myseasons.append(Season(show: self, seasonName: season, title: season))
|
||||||
}
|
}
|
||||||
return myseasons
|
return myseasons
|
||||||
}()
|
}()
|
||||||
|
@ -120,18 +243,10 @@ struct VRTNu {
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
print("init")
|
print("init")
|
||||||
//TODO: fetch shows
|
let regexPattern = "/a-z/(.*).relevant"
|
||||||
let showsdata = Just.get("https://www.vrt.be/vrtnu/a-z/").text!
|
|
||||||
//print(showsdata)
|
|
||||||
let range = NSRange(location: 0, length: showsdata.count)
|
|
||||||
|
|
||||||
let regex = try! NSRegularExpression(pattern: "/a-z/(.*).relevant")
|
let output = getData(url: URL(string: "https://www.vrt.be/vrtnu/a-z/")!, regexPattern: regexPattern)
|
||||||
let shows = regex.matches(in: showsdata, range: range)
|
|
||||||
let nsString = showsdata as NSString
|
|
||||||
|
|
||||||
let output = Array(Set(shows.map {nsString.substring(with: $0.range)}))
|
|
||||||
|
|
||||||
//print(output)
|
|
||||||
var show: String
|
var show: String
|
||||||
var myshows: [Show]
|
var myshows: [Show]
|
||||||
myshows = []
|
myshows = []
|
||||||
|
|
Loading…
Reference in New Issue