//I don't think this is used any more, but I need to check public VideoItems(string query, int maxItems = 24, int startItem = 0, bool search = false) { m_Choice = new Choice(); List = new ArrayListDataSet(); string data; //if (search) //{ // data = AmazonVideoRequest.searchPrime(query, maxItems, startItem); //} //else //{ // data = AmazonVideoRequest.getVideoItemsWithQuery(query, maxItems, startItem); //} data = AmazonVideoRequest.ExecuteQuery(query); JsonTextReader reader = new JsonTextReader(new StringReader(data)); JObject titles = JObject.Parse(data); foreach (JObject node in titles["message"]["body"]["titles"]) { List.Add(new VideoItem(node)); } m_Choice.Options = List; }
public string ExecuteQuery(string url, bool useCookie = true) { WebClientWithCookies client; if (useCookie) { var formatter = new BinaryFormatter(); CookieContainer cc = null; using (Stream s = File.OpenRead(AmazonVideoRequest.cookiePath())) cc = (CookieContainer)formatter.Deserialize(s); client = new WebClientWithCookies(cc); } else { client = new WebClientWithCookies(new CookieContainer()); } //generate a signature for this URL string sig = generate_signature(url); //add this signature as a header client.Headers.Add("x-android-sign", sig); //get the data Stream data = client.OpenRead(url); StreamReader reader = new StreamReader(data); string tmp = reader.ReadToEnd(); //Trace.WriteLine("********Query: " + url + "\r\n***********" + tmp); return(tmp); }
//This navigates to the relevant next step if this item is selected in VideoGallery.mcml //It generally just goes to VideoDetails unless it is a season. public void ViewDetails() { // Request additional metadata and process string detailData = AmazonVideoRequest.getVideoDetails(m_ASIN); JObject detailResults = JObject.Parse(detailData); processDetailData((JObject)detailResults["message"]["body"]["titles"][0]); switch (m_contentType) { case "MOVIE": Application.Current.GoToVideoDetails(this); break; case "SEASON": Application.Current.GoToSeasonDetails(this); break; case "SERIES": Application.Current.GoToVideoDetails(this); break; case "EPISODE": Application.Current.GoToVideoDetails(this); break; } }
//This navigates to the actual video viewer. //TODO: Move this into Application, and place the stub here to call it from Application. public void LaunchVideoViewer() { string flashVars = AmazonVideoRequest.getFlashVars(m_ASIN); string htmlexpath = Application.Current.viewerPath + "?ASIN=" + m_ASIN + flashVars; Application.Current.MediaCenterEnvironment.NavigateToPage(PageId.ExtensibilityUrl, htmlexpath); }
//This function generates the query and passes it to the current content, which is expected to be "search". This will //then bind the query to the video items, which will initiate the search public void DoSearch(string SearchText) { if (SearchText.Length >= Convert.ToInt32(Resources.MinimumSearchTextLength)) { CurrentContext.Query = AmazonVideoRequest.generateSearchUrl(SearchText); } else { CurrentContext.Query = ""; } }
//This function actually executes the query set above, and loops through the dataset, initializing each new item //with a separate json node. private void ExecuteQuery(string query, int maxItems = 24, int startItem = 0, bool search = false) { string data; data = AmazonVideoRequest.ExecuteQuery(query); JsonTextReader reader = new JsonTextReader(new StringReader(data)); JObject titles = JObject.Parse(data); m_Choice.Options.Clear(); foreach (JObject node in titles["message"]["body"]["titles"]) { m_Choice.Options.Add(new VideoItem(node)); } FirePropertyChanged("ListContent"); }
//This sends the username and password to amazon using the helper functions (which then create local cookies etc) public void DoLogin(string username, string password) { LoginProcessStatus = "Processing"; if (username == "" | password == "") { LoginProcessStatus = "Required"; return; } if (AmazonVideoRequest.login(username, password)) { GoToMainMenu(); return; } else { LoginProcessStatus = "Error"; return; //TODO: Need to put something in here to let user know it didn't work. } }
//I don't think this is used any more, but I need to check public static List <Category> getPrimeCategories() { List <Category> cats = new List <Category>(); string data = AmazonVideoRequest.getCategories(); JsonTextReader reader = new JsonTextReader(new StringReader(data)); JObject categories = JObject.Parse(data); //Get Prime Movie Categories foreach (JObject category in categories["message"]["body"]["categories"][1]["categories"][1]["categories"][2]["categories"]) { cats.Add(new Category((string)category["title"], (string)category["query"], null, 0)); } //Get Prime TV Categories foreach (JObject category in categories["message"]["body"]["categories"][1]["categories"][1]["categories"][3]["categories"]) { cats.Add(new Category((string)category["title"], (string)category["query"], null, 0)); } return(cats); }
private static void recurse(JToken category, Category parent) { string browseUrl = AmazonVideoRequest.GenerateVirtualBrowseUrlTemplate() + "&"; int index = 0; parent.hasChildren = (category["categories"] != null); if (parent.hasChildren) { //to prevent loading of dummy content, I am resetting query to blank for any parents. parent.Query = ""; foreach (JToken subcategory in category["categories"]) { string junk2 = subcategory.ToString(); Category subcatobj = new Category((string)subcategory["title"], browseUrl + (string)subcategory["query"], parent, index); subcatobj.CatDescription = (string)subcategory["description"]; parent.List.Add(subcatobj); parent.hasChildren = true; index++; recurse(subcategory, subcatobj); } parent.bindListToChoice(); } }
//This sets up an initial menu structure, and pulls the newest category information //then uses recurse to go through all the sub categories public static Category getCategoryStructure() { Category cat_root = new Category("", "", null, 0); Category cat_home = new Category("Home", "", cat_root, 0); cat_root.List.Add(cat_home); Category cat_prime = null; if (Resources.PrimeOnly.Equals("false")) { cat_prime = new Category("Prime Instant Video", "", cat_root, 1); cat_root.List.Add(cat_prime); } Category cat_movies = new Category("Movies", "", cat_root, 2); cat_root.List.Add(cat_movies); Category cat_tv = new Category("TV Shows", "", cat_root, 3); cat_root.List.Add(cat_tv); Category cat_search = new Category("Search", "", cat_root, 4); cat_root.List.Add(cat_search); Category cat_logout = new Category("Sign-out", "", cat_root, 5); cat_root.List.Add(cat_logout); cat_root.bindListToChoice(); string categoryData = AmazonVideoRequest.getCategories(); JsonTextReader reader = new JsonTextReader(new StringReader(categoryData)); JObject categories = JObject.Parse(categoryData); //System.Diagnostics.Debug.Print(categories.ToString()); //int catID = 0; cat_home.hasChildren = true; Category watchList = new Category("Your Watchlist", "", cat_home, 0); cat_home.List.Add(watchList); Category yourVideoLibrary = new Category("Your Video Library", AmazonVideoRequest.getLibraryRequest(), cat_home, 1); cat_home.List.Add(yourVideoLibrary); Category recentlyWatched = new Category("Recently Watched", "", cat_home, 2); cat_home.List.Add(recentlyWatched); Category yourTvShows = new Category("Your TV Shows", "", cat_home, 3); cat_home.List.Add(yourTvShows); cat_home.bindListToChoice(); int subCategoryIndex = 2; // Load 'Prime Instant Video' root category if (Resources.PrimeOnly.Equals("false")) { subCategoryIndex = 1; recurse(categories["message"]["body"]["categories"][1]["categories"][subCategoryIndex], cat_prime); } // Load 'Movies' root category recurse(categories["message"]["body"]["categories"][2]["categories"][subCategoryIndex], cat_movies); // Load 'TV Shows' root category recurse(categories["message"]["body"]["categories"][3]["categories"][subCategoryIndex], cat_tv); return(cat_root); }
//checks to see if there is a cookie //NOTE: This doesn't check to see if the login is actually valid. private bool LoggedIn() { return(AmazonVideoRequest.checkIfHaveLoginCookie()); }
//This clears the cookie file and takes the user back to the login page. public void Logout() { AmazonVideoRequest.clearLoginCookie(); GoToLoginPage(); }
public void processNodeData(JObject node) { //Debug.Print(node.ToString()); m_Command = new Command(); //set up default sizes for images Size movie_size = new Size(188, 250); Size tv_size = new Size(334, 250); processFormatNodes(node); m_Title = (string)node["title"]; m_Synopsis = (string)node["synopsis"]; amazonRating = new AmazonRating(); amazonRating.Count = (int)node["amazonRating"]["count"]; amazonRating.Rating = (float)node["amazonRating"]["rating"]; starsRatingImage = (amazonRating.Rating % 1 == 0) ? starsFullImage : starsHalfImage; m_RegulatoryRating = (string)node["regulatoryRating"]; m_trailerAvailable = (bool)node["trailerAvailable"]; m_contentType = (string)node["contentType"]; JObject runtime = (JObject)node["runtime"]; m_runtime = ""; if (runtime != null) { if (runtime["valueFormatted"] != null) { m_runtime = (string)node["runtime"]["valueFormatted"]; } } JObject releaseOrFirstAiringDate = (JObject)node["releaseOrFirstAiringDate"]; if (releaseOrFirstAiringDate != null) { if (releaseOrFirstAiringDate["valueFormatted"] != null) { m_firstAiringDate = (DateTime)node["releaseOrFirstAiringDate"]["valueFormatted"]; } } switch (m_contentType) { case "MOVIE": size = movie_size; break; case "SEASON": size = tv_size; string childquery = (string)node["childTitles"][0]["feedUrl"]; if (childquery.IndexOf("?") > 0) { //this must be a browse query, and therefore contains the full url but without the device keys. //need to replace the prefix and use the querystring. m_ChildTitleQuery = AmazonVideoRequest.generateUrl("catalog/Browse") + "&" + childquery.Split('?')[1]; } else { //this must have come from a search query. m_ChildTitleQuery = AmazonVideoRequest.generateUrl("catalog/Browse") + "&" + childquery + "&version=2"; } break; //So far, I have not yet seen Series or Episode, but I know they are options, so when we find one, we //will need to address it. case "SERIES": size = tv_size; m_ChildTitleQuery = (string)node["childTitles"][0]["feedUrl"]; break; case "EPISODE": size = tv_size; break; } m_ASIN = (string)node["titleId"]; //todo: fix this to work properly with the right image url //m_ImageUrl =(string)node["formats"][selectedFormat]["images"][1]["uri"];; //m_Image = new Image(m_ImageURL); m_Price = "Free!"; FirePropertyChanged("size"); FirePropertyChanged("Title"); FirePropertyChanged("Synopsis"); }