public VideoDownloader(UrlFileCache bank, OpenuVideoData data, BackgroundWorker changesReporter) { this.cache = bank; this.data = data; durations = new ConcurrentBag <TimeSpan>(); this.changesReporter = changesReporter; }
private static string GetVidUrl(OpenuVideoData data, CookieContainer cookieJar) { var specificVidParams = String.Format("action=getplaylist&context={0}&playlistid={1}&course={2}", data.ContextId, data.VideoId, data.CourseId); var specificVidReq = (HttpWebRequest)WebRequest.Create("http://opal.openu.ac.il/mod/ouilvideocollection/actions.php"); specificVidReq.CookieContainer = cookieJar; specificVidReq.Method = "POST"; specificVidReq.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; specificVidReq.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0"; PutData(specificVidParams, specificVidReq); var response = (HttpWebResponse)specificVidReq.GetResponse(); if (response.StatusCode != HttpStatusCode.OK) { return(null); } var videoData = ResponseAsJson(response); JToken value; if (videoData.TryGetValue("media", out value)) { return(value["ar"].ToString()); } return(null); }
string requestPlaylist(OpenuVideoData data) { var playlistFile = cache.GetContent(data.formatPlaylistFile(), data.VideoId); if (playlistFile != null) { return(playlistFile); } HttpWebRequest req = (HttpWebRequest)WebRequest.Create(data.PlaylistUrl); req.AllowAutoRedirect = true; var response = (HttpWebResponse)req.GetResponse(); if (response.StatusCode != HttpStatusCode.OK) { return(null); } playlistFile = new StreamReader(response.GetResponseStream()).ReadToEnd(); cache.PutContent(data.formatPlaylistFile(), playlistFile, data.VideoId); return(playlistFile); }