diff --git a/vrtnu/vrtnu/VrtNuLayout.swift b/vrtnu/vrtnu/VrtNuLayout.swift index e9c24bb..86a82d1 100644 --- a/vrtnu/vrtnu/VrtNuLayout.swift +++ b/vrtnu/vrtnu/VrtNuLayout.swift @@ -24,7 +24,6 @@ struct Episode: Hashable, Comparable{ let title: String let season: Season let imageURL: URL - let metadataurl: URL let episodeurl: String @@ -66,7 +65,6 @@ struct Episode: Hashable, Comparable{ self.season = season self.imageURL = imageURL self.episodeurl = "https://www.vrt.be/vrtnu/a-z/" + season.show.showName + "/" + season.seasonName + "/" + episodeName - self.metadataurl = URL(string: episodeurl + ".mssecurevideo.json")! self.title = title } @@ -76,16 +74,18 @@ struct Episode: Hashable, Comparable{ } func getVideoJson() -> NSDictionary{ - //`requests.get('https://www.vrt.be/vrtnu/a-z/%s/%s/%s.mssecurevideo.json' % (show, season, episode)).json()` - - let msecjson = just.get(metadataurl).json! - let mssecdict = msecjson as! NSDictionary - print(msecjson) - let intmssecdict = mssecdict.allValues[0] as! NSDictionary - let videoid = intmssecdict.value(forKey: "videoid") as! String - let clientid = intmssecdict.value(forKey: "clientid") as! String + let episodedata = just.get(episodeurl).text! + let videoid = parseData(data:episodedata, regexPattern: "vid-[a-z0-9-]*") + print(videoid) + let pubid = parseData(data:episodedata, regexPattern: "pbs-pub-[a-z0-9-]*") + print(pubid) + let videoidd = pubid[0] + "$" + videoid[0] + print(videoidd) + // - var mediaurl = "https://media-services-public.vrt.be/vualto-video-aggregator-web/rest/external/v1/videos/" + videoid + let clientid = "vrtvideo" + + var mediaurl = "https://media-services-public.vrt.be/vualto-video-aggregator-web/rest/external/v1/videos/" + videoidd mediaurl = mediaurl + "?vrtPlayerToken=" mediaurl = mediaurl + self.season.show.vrtNu.getToken() + "&client=" mediaurl = mediaurl + clientid + "@PROD" @@ -135,6 +135,7 @@ struct Season: Hashable, Comparable{ func getEpisodes() -> [Episode]{ //`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))` + print("getting episodes for " + show.showName + " " + seasonName) let regexPattern = "vrtnu/a-z/" + show.showName + "/" + seasonName + "/([^\"]*)/" let imageregexPattern = "data-responsive-image=\".*(jpg|png)" let titleregexPattern = "\">(.*)(|
)" @@ -182,7 +183,7 @@ struct Show: Hashable, Comparable{ let vrtNu: VRTNu init(vrtNu: VRTNu, showName: String, title: String, imageURL: URL) { - self.showURL = URL(string: "https://www.vrt.be/vrtnu/a-z/" + showName)! + self.showURL = URL(string: "https://www.vrt.be/vrtnu/a-z/" + showName + "/")! self.showName = showName self.title = title //TODO: get image urls for shows @@ -191,18 +192,57 @@ struct Show: Hashable, Comparable{ } + /* func getEpisodes()-> [Episode]{ + # actually all episodes are already listed in the show's page, no need to get the individual episodes + print("getting episodes for" + showName) + let regexPattern = "link=\"/vrtnu/a-z/" + showName + "/(.*).html\">" + let seasondata = Just.get(showURL).text! + let output = parseData(data: seasondata, regexPattern: regexPattern) + + let imageregexPattern = "data-responsive-image=\".*(jpg|png)" + let titleregexPattern = "\">(.*)(|
)" + + let data = Just.get("https://www.vrt.be/vrtnu/a-z/" + show.showName + "/" + seasonName + ".lists.all-episodes/").text! + let output = parseData(data: data, regexPattern: regexPattern) + let imageoutput = parseData(data: data, regexPattern: imageregexPattern) + let titleoutput = parseData(data: data, regexPattern: titleregexPattern) + print(data) + + var episode: String + var myepisodes: [Episode] + myepisodes = [] + for i in 0 ..< titleoutput.count{ + // output always contains same url twice + episode = output[i * 2].replacingOccurrences(of: "vrtnu/a-z/" + show.showName + "/" + seasonName + "/", with: "").replacingOccurrences(of: "/", with: "") + print(episode) + print(seasonName) + let image = URL(string: imageoutput[i].replacingOccurrences(of: "https:", with: "").replacingOccurrences(of: "http:", with: "").replacingOccurrences(of: "data-responsive-image=\"", with: "https:"))! + let title = titleoutput[i].replacingOccurrences(of: "\">", with: "").replacingOccurrences(of: "
", with: "").replacingOccurrences(of: "", with: "") + myepisodes.append(Episode(season: self, episodeName: episode, title: title, imageURL: image)) + } + + myepisodes.sort() + return myepisodes + } + + + }*/ + func getSeasons() -> [Season]{ //`re.findall('value="#parsys_container_banner_%s_(.*)">' % show, requests.get('https://www.vrt.be/vrtnu/a-z/%s/' % show).text)` + let regexPattern = "value=\"#parsys_container_banner_(" + showName + "_)?(.*)\">" + print("getting seasons from " + showURL.absoluteString) + print("filtering with " + regexPattern) - let regexPattern = "value=\"#parsys_container_banner_" + showName + "_(.*)\">" let output = parseData(data: Just.get(showURL).text!, regexPattern: regexPattern) var season: String var myseasons: [Season] myseasons = [] for i in 0 ..< output.count{ - season = output[i].replacingOccurrences(of: "value=\"#parsys_container_banner_" - + showName + "_", with: "").replacingOccurrences(of: "\">", with: "") + print(output[i]) + season = output[i].replacingOccurrences(of: "value=\"#parsys_container_banner_", with: "") + .replacingOccurrences(of: showName + "_", with: "").replacingOccurrences(of: "\">", with: "") print(season) print(showName) myseasons.append(Season(show: self, seasonName: season, title: season)) @@ -283,6 +323,8 @@ struct VRTNu: Hashable { } func getShows() -> [Show]{ + print("getting shows") + let data = Just.get("https://www.vrt.be/vrtnu/a-z/").text! print(data)