From: <gre...@us...> - 2007-09-04 07:32:34
|
Revision: 891 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=891&view=rev Author: gregmac45 Date: 2007-09-04 00:32:31 -0700 (Tue, 04 Sep 2007) Log Message: ----------- Added page with all available trailers for movie Modified Paths: -------------- trunk/plugins/OnlineVideos/Source/OnlineVideos/GUIOnlineVideos.cs trunk/plugins/OnlineVideos/Source/OnlineVideos/ImageDowloader.cs trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesTrailerUtil.cs trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/AppleTrailers.cs trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/HDHelper.cs trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/ItmsHelper.cs trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/RegexParsers.cs trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/TrailerIndex.cs trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/TrailerStream.cs trunk/plugins/OnlineVideos/Source/OnlineVideos/SiteUtilBase.cs Modified: trunk/plugins/OnlineVideos/Source/OnlineVideos/GUIOnlineVideos.cs =================================================================== --- trunk/plugins/OnlineVideos/Source/OnlineVideos/GUIOnlineVideos.cs 2007-09-03 19:59:11 UTC (rev 890) +++ trunk/plugins/OnlineVideos/Source/OnlineVideos/GUIOnlineVideos.cs 2007-09-04 07:32:31 UTC (rev 891) @@ -23,13 +23,17 @@ { [SkinControlAttribute(2)] protected GUIButtonControl btnViewAs = null; + [SkinControlAttribute(3)] + protected GUIButtonControl btnNext = null; + [SkinControlAttribute(4)] + protected GUIButtonControl btnPrevious = null; [SkinControlAttribute(50)] protected GUIFacadeControl facadeView = null; [SkinControlAttribute(1)] protected GUIImage logoImage = null; - [SkinControlAttribute(4)] - protected GUITextControl txtDesc = null; + //[SkinControlAttribute(4)] + //protected GUITextControl txtDesc = null; //private ILog moLog; protected View currentView = View.Icons; @@ -42,6 +46,7 @@ private State _CurrentState = State.home; private String msDownloadDir = Directory.GetCurrentDirectory()+"\\"; private List<VideoInfo> moCurrentVideoList = new List<VideoInfo>(); + private List<VideoInfo> moCurrentTrailerList = new List<VideoInfo>(); private String []msFilterArray; private String msThumbLocation; private int miSelectedIndex = 0; @@ -212,6 +217,7 @@ if (_CurrentState == State.home) { DisplaySites(); + SwitchView(); //currentView = View.List; //ChangeFacadeView(); @@ -228,7 +234,7 @@ else{ DisplayVideoDetails(moSelectedVideo); } - UpdateViewSate(); + UpdateViewState(); //base.OnPageLoad(); } protected override void OnShowContextMenu() @@ -299,7 +305,7 @@ } public override void OnAction(Action action) { - if (action.wID == Action.ActionType.ACTION_PREVIOUS_MENU) + if (action.wID == Action.ActionType.ACTION_PREVIOUS_MENU && _CurrentState!= State.home ) { OnShowPreviousMenu2(); return; @@ -366,10 +372,10 @@ { miSelectedIndex = facadeView.SelectedListItemIndex; //play the video - Play(moCurrentVideoList[facadeView.SelectedListItemIndex -1]); + Play(moCurrentTrailerList[facadeView.SelectedListItemIndex -1]); } } - UpdateViewSate(); + UpdateViewState(); } else if (control == btnViewAs) { @@ -378,7 +384,19 @@ //do //{ //shouldContinue = false; - } + } + else if (control == btnNext) + { + moCurrentVideoList = SiteUtilFactory.getSiteUtil(msSelectedSiteId).getNextPageVideos(); + DisplayVideos(false); + UpdateViewState(); + } + else if (control == btnPrevious) + { + moCurrentVideoList = SiteUtilFactory.getSiteUtil(msSelectedSiteId).getPreviousPageVideos(); + DisplayVideos(false); + UpdateViewState(); + } base.OnClicked(controlId, control, actionType); } @@ -393,7 +411,7 @@ } else if (_CurrentState == State.videos) { - Log.Info("Set the stopDownload to true 2"); + Log.Info("Set the stopDownload to true 3"); ImageDownloader._stopDownload = true; DisplayCategories(); @@ -406,13 +424,15 @@ //Log.Info("Set the stopDownload to true 2"); ImageDownloader._stopDownload = true; - DisplayVideos(true); + DisplayVideos(false); SwitchView(); btnViewAs.Visible = true; _CurrentState = State.videos; } + DisplayVideoInfo(null); + UpdateViewState(); } public override bool OnMessage(GUIMessage message) { @@ -493,18 +513,50 @@ cat.url = "favorites"; loSite.RssList.Add("dynamic",cat); moSiteList.Add("100",loSite); + + if (!String.IsNullOrEmpty(settings.msDownloadDir)) + { + try{ + if (System.IO.Directory.Exists(settings.msDownloadDir)==false) + { + + System.IO.Directory.CreateDirectory(msDownloadDir); + + } + } + catch (Exception e) + { + Log.Error("Failed to create download dir"); + Log.Error(e); + } + //add a downloaded videos site + loSite = new SiteSettings(); + loSite.id = "99"; + loSite.name = "Downloaded Videos"; + loSite.enabled = true; + cat = new RssLink(); + cat.name = "All"; + cat.url = settings.msDownloadDir; + loSite.RssList.Add(cat.name, cat); + moSiteList.Add("99", loSite); + } + try + { + Log.Info("checking existance of thumb dir:" + settings.msThumbLocation); + if (System.IO.Directory.Exists(settings.msThumbLocation)==false) + { + Log.Info("Thumb dir does not exist."); + System.IO.Directory.CreateDirectory(settings.msThumbLocation); + Log.Info("thumb dir created"); + } + } + catch (Exception e) + { + Log.Error("Failed to create thumb dir"); + Log.Error(e); + } + - //add a downloaded videos site - loSite = new SiteSettings(); - loSite.id = "99"; - loSite.name = "Downloaded Videos"; - loSite.enabled = true; - cat = new RssLink(); - cat.name = "All"; - cat.url = settings.msDownloadDir; - loSite.RssList.Add(cat.name,cat); - moSiteList.Add("99",loSite); - } private void DisplaySites() { @@ -655,7 +707,7 @@ } //GUIPropertyManager.SetProperty("#itemcount", facadeView.Count-1 +""); - ImageDownloader.getImages(loImageUrlList,msThumbLocation,facadeView); + ImageDownloader.getImages(loImageUrlList,OnlineVideoSettings.getInstance().msThumbLocation,facadeView); // Log.Info("Getting images"); // BackgroundWorker worker = new BackgroundWorker(); // @@ -698,7 +750,7 @@ moSelectedVideo = foVideo; SiteUtilBase loSiteUtil = SiteUtilFactory.getSiteUtil(msSelectedSiteId); List<VideoInfo> loVideoList= loSiteUtil.getOtherVideoList(foVideo); - moCurrentVideoList.Clear(); + moCurrentTrailerList.Clear(); GUIControl.ClearControl(GetID, facadeView.GetID); GUIListItem loListItem = new GUIListItem(".."); loListItem.IsFolder = true; @@ -711,7 +763,7 @@ { liIdx++; loVideoInfo.Description = cleanString(loVideoInfo.Description); - + moSelectedVideo.Description = loVideoInfo.Description; loListItem = new GUIListItem(loVideoInfo.Title); loListItem.Label2 = loVideoInfo.Title2; loListItem.Path = loVideoInfo.VideoUrl; @@ -722,11 +774,11 @@ facadeView.Add(loListItem); //loListItem.RetrieveArt = true; //loImageUrlList.Add(loVideoInfo.ImageUrl); - moCurrentVideoList.Add(loVideoInfo); + moCurrentTrailerList.Add(loVideoInfo); } facadeView.View = GUIFacadeControl.ViewMode.List; btnViewAs.Visible = false; - DisplayVideoInfo(loVideoList[0]); + //DisplayVideoInfo(loVideoList[0]); //strLine = GUILocalizeStrings.Get(101); } @@ -858,28 +910,81 @@ } return fsStr; } - private void UpdateViewSate(){ + private void UpdateViewState(){ switch(_CurrentState){ case State.home: GUIPropertyManager.SetProperty("#header.label","OnlineVideos"); GUIPropertyManager.SetProperty("#header.image",""); - DisplayVideoInfo(null); + GUIControl.HideControl(GetID,btnNext.GetID); + GUIControl.HideControl(GetID,btnPrevious.GetID); + GUIControl.HideControl(GetID, 23); + GUIControl.HideControl(GetID, 24); + GUIControl.HideControl(GetID, 25); + GUIControl.HideControl(GetID, 58); + GUIControl.HideControl(GetID, 59); + DisplayVideoInfo(null); break; case State.categories: GUIPropertyManager.SetProperty("#header.label","Categories"); GUIPropertyManager.SetProperty("#header.image","OnlineVidlogo"+msSelectedSiteId+".jpeg"); + GUIControl.HideControl(GetID,btnNext.GetID); + GUIControl.HideControl(GetID,btnPrevious.GetID); + GUIControl.HideControl(GetID, 23); + GUIControl.HideControl(GetID, 24); + GUIControl.HideControl(GetID, 25); + GUIControl.HideControl(GetID, 58); + GUIControl.HideControl(GetID, 59); DisplayVideoInfo(null); break; case State.videos: GUIPropertyManager.SetProperty("#header.label",msSelectedCategoryName); GUIPropertyManager.SetProperty("#header.image","OnlineVidlogo"+msSelectedSiteId+".jpeg"); - DisplayVideoInfo(null); + GUIControl.ShowControl(GetID,btnNext.GetID); + GUIControl.HideControl(GetID, 23); + GUIControl.HideControl(GetID, 24); + GUIControl.HideControl(GetID, 25); + GUIControl.HideControl(GetID, 58); + GUIControl.HideControl(GetID, 59); + + SiteUtilBase loSiteUtil = SiteUtilFactory.getSiteUtil(msSelectedSiteId); + if (loSiteUtil.hasNextPage()) + { + GUIControl.EnableControl(GetID,btnNext.GetID); + } + else + { + GUIControl.DisableControl(GetID,btnNext.GetID); + } + GUIControl.ShowControl(GetID,btnPrevious.GetID); + if (loSiteUtil.hasPreviousPage()) + { + GUIControl.EnableControl(GetID, btnPrevious.GetID); + } + else + { + GUIControl.DisableControl(GetID,btnPrevious.GetID); + } + DisplayVideoInfo(null); break; case State.info: GUIPropertyManager.SetProperty("#header.label",moSelectedVideo.Title); GUIPropertyManager.SetProperty("#header.image","OnlineVidlogo"+msSelectedSiteId+".jpeg"); - //DisplayVideoInfo(); + GUIControl.HideControl(GetID,btnNext.GetID); + GUIControl.HideControl(GetID,btnPrevious.GetID); + + GUIControl.ShowControl(GetID, 23); + GUIPropertyManager.SetProperty("#movieposter", ImageDownloader.downloadPoster(moSelectedVideo.ImageUrl.Replace("_m", "_l"),moSelectedVideo.Title,OnlineVideoSettings.getInstance().msThumbLocation)); + GUIPropertyManager.SetProperty("#movietitle", moSelectedVideo.Title); + GUIPropertyManager.SetProperty("#trailerdesc", moSelectedVideo.Description); + //Log.Info("trailer desc:{0}", moSelectedVideo.Description); + GUIControl.ShowControl(GetID, 24); + GUIControl.ShowControl(GetID, 25); + GUIControl.ShowControl(GetID, 58); + GUIControl.ShowControl(GetID, 59); + + + DisplayVideoInfo(null); break; } } @@ -946,8 +1051,11 @@ } protected void SwitchView() { - if (facadeView == null) - return; + if (facadeView == null) + { + //Log.Info("SwitchView - facadeview is null"); + return; + } string strLine = String.Empty; switch (currentView) Modified: trunk/plugins/OnlineVideos/Source/OnlineVideos/ImageDowloader.cs =================================================================== --- trunk/plugins/OnlineVideos/Source/OnlineVideos/ImageDowloader.cs 2007-09-03 19:59:11 UTC (rev 890) +++ trunk/plugins/OnlineVideos/Source/OnlineVideos/ImageDowloader.cs 2007-09-04 07:32:31 UTC (rev 891) @@ -127,6 +127,20 @@ } */ #endregion + public static string downloadPoster(String fsUrl, String fsMovieName,string fsLocation) + { + + String lsPosterLocation = fsLocation + fsMovieName + "_p.jpg"; + if (System.IO.File.Exists(lsPosterLocation) == false) + { + WebClient client = new WebClient(); + Log.Info("downloading Poster image :" + fsUrl); + client.DownloadFile(fsUrl, lsPosterLocation); + } + return lsPosterLocation; + } + + public static void getImages(List<String> imageUrlList,String ThumbLocation,GUIFacadeControl facadeView){ Log.Info("Getting images"); BackgroundWorker worker = new BackgroundWorker(); Modified: trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesTrailerUtil.cs =================================================================== --- trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesTrailerUtil.cs 2007-09-03 19:59:11 UTC (rev 890) +++ trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesTrailerUtil.cs 2007-09-04 07:32:31 UTC (rev 891) @@ -85,12 +85,14 @@ List<OnlineVideos.GUIOnlineVideos.VideoInfo> videoList = new List<OnlineVideos.GUIOnlineVideos.VideoInfo>(); TrailerInfo trailer = (TrailerInfo)video.Other; trailer = AppleTrailers.GetTrailerUrls(trailer); - Console.WriteLine("Found {0} trailer urls",trailer.trailers.Count); + //Log.Info("getOtherVideoList overview:" + trailer.Overview); + //Console.WriteLine("Found {0} trailer urls",trailer.trailers.Count); GUIOnlineVideos.VideoInfo newVideo; foreach (String name in trailer.trailers.Keys){ newVideo = loadVideoInfo(trailer); newVideo.Title = name; - newVideo.VideoUrl = trailer.trailers[name]; + newVideo.VideoUrl = trailer.trailers[name]; + Log.Info("added video url={0}", newVideo.VideoUrl); videoList.Add(newVideo); } return videoList; @@ -98,9 +100,12 @@ public override String getUrl(GUIOnlineVideos.VideoInfo video,GUIOnlineVideos.SiteSettings foSite) { TrailerInfo trailer = (TrailerInfo)video.Other; - trailer = AppleTrailers.ProcessTrailer(trailer,OnlineVideoSettings.getInstance().AppleTrailerSize); - Log.Info("Trailer quality set to {0}",OnlineVideoSettings.getInstance().AppleTrailerSize); - Console.WriteLine("Found {0} trailer urls",trailer.TrailerStreamCollection.Count); + Log.Info("requesting to get url for " + video.VideoUrl); + trailer.Url = new Uri("http://movies.apple.com" + video.VideoUrl); + Log.Info("Trailer quality set to {0}", OnlineVideoSettings.getInstance().AppleTrailerSize); + trailer = AppleTrailers.ProcessTrailer(trailer,OnlineVideoSettings.getInstance().AppleTrailerSize); + + //Console.WriteLine("Found {0} trailer urls",trailer.TrailerStreamCollection.Count); return trailer.TrailerStreamCollection[0].Uri.ToString(); } public List<GUIOnlineVideos.VideoInfo> getAllTrailers(){ @@ -176,5 +181,44 @@ return newVideo; } + public override bool hasNextPage() + { + if (AppleTrailers.currentPage == null || AppleTrailers.currentPage.NextPageUri == null) + { + //Log.Info("current page is null or next page uri is null"); + return false; + } + //Log.Info("{0}",AppleTrailers.currentPage.NextPageUri); + Log.Info(AppleTrailers.currentPage.NextPageUri.ToString()); + return String.IsNullOrEmpty(AppleTrailers.currentPage.NextPageUri.ToString()) == false; + } + public override List<GUIOnlineVideos.VideoInfo> getNextPageVideos() + { + List<GUIOnlineVideos.VideoInfo> trailerList = new List<GUIOnlineVideos.VideoInfo>(); + if (hasNextPage()) + { + trailerList = getVideoList(AppleTrailers.currentPage.NextPageUri.ToString()); + } + return trailerList; + } + public override List<GUIOnlineVideos.VideoInfo> getPreviousPageVideos() + { + List<GUIOnlineVideos.VideoInfo> trailerList = new List<GUIOnlineVideos.VideoInfo>(); + if (hasPreviousPage()) + { + trailerList = getVideoList(AppleTrailers.currentPage.BackPageUri.ToString()); + } + return trailerList; + + } + public override bool hasPreviousPage() + { + if (AppleTrailers.currentPage == null || AppleTrailers.currentPage.BackPageUri == null) + { + return false; + } + return String.IsNullOrEmpty(AppleTrailers.currentPage.BackPageUri.ToString()) == false; + } + } } Modified: trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/AppleTrailers.cs =================================================================== --- trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/AppleTrailers.cs 2007-09-03 19:59:11 UTC (rev 890) +++ trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/AppleTrailers.cs 2007-09-04 07:32:31 UTC (rev 891) @@ -18,7 +18,9 @@ public class AppleTrailers { public static List<ITMSClient.TrailerInfo> trailers = new List<ITMSClient.TrailerInfo>(); + public static ITMSClient.TrailerIndex currentPage; + /* public static string casturl; public static string TempXML = string.Empty; @@ -54,18 +56,20 @@ public static bool tview = false; public static bool cview = false; public static bool mview = false; - + */ public static bool _workerCompleted = false; - public static string PosterUrl = string.Empty; + //public static string PosterUrl = string.Empty; // mediaportal.xml - public static string server = string.Empty; + //public static string server = string.Empty; public void HandleHttpError(object sender, ITMSClient.HTTPErrorEventArgs e){ } public static void GetAppleTrailersRSS(object sender, DoWorkEventArgs e) { + currentPage = null; + _workerCompleted = false; //.+=new ITMSClient.HTTPErrorEventHandler(HandleHttpError); //loListItem.OnItemSelected+= new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnVideoItemSelected); @@ -77,12 +81,12 @@ if (xmlContent.IsValid) { - //Log.Info("xml is valid"); - ITMSClient.TrailerIndex indexPage = new ITMSClient.TrailerIndex("test", xmlContent); - RSSTitle = "Apple HD Trailers"; + Log.Info("xml is valid"); + currentPage = new ITMSClient.TrailerIndex("test", xmlContent); + //RSSTitle = "Apple HD Trailers"; //trailers.Add(indexPage.TrailerInfoCollection.); //Log.Info("FOund {0} trailers.", indexPage.TrailerInfoCollection.Count); - foreach (ITMSClient.TrailerInfo trailerInfo in indexPage.TrailerInfoCollection) + foreach (ITMSClient.TrailerInfo trailerInfo in currentPage.TrailerInfoCollection) { /* ITMSClient.TrailerInfo trailer = ProcessTrailer(trailerInfo); @@ -96,15 +100,15 @@ } - pageUri = indexPage.NextPageUri; + //pageUri = indexPage.NextPageUri; } - else - { - pageUri = null; - } + //else + //{ + // pageUri = null; + //} _workerCompleted = true; - foundt = true; - tview = true; + //foundt = true; + //tview = true; } @@ -120,7 +124,7 @@ { ITMSClient.TrailerInfo trailerInfo = (ITMSClient.TrailerInfo)obj; - //Log.Info("Processing Trailer {0}",trailerInfo.Title); + Log.Info("Processing Trailer {0}",trailerInfo.Title); // Lookup the trailer in the media library string key = trailerInfo.Title.GetHashCode().ToString(); // Populate the rest of the meta data Modified: trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/HDHelper.cs =================================================================== --- trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/HDHelper.cs 2007-09-03 19:59:11 UTC (rev 890) +++ trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/HDHelper.cs 2007-09-04 07:32:31 UTC (rev 891) @@ -32,6 +32,7 @@ /// </summary> public sealed class HDHelper { + /* private const string URI = "http://www.apple.com/trailers/"; static public Hashtable GetAvailableMovies() @@ -51,13 +52,13 @@ ITMSContent content = ITMSHelper.GetITMSPage(trailerPage); switch (size) { - case TrailerSize.HD480p: + case TrailerSize.h480p: regex = new Regex("HREF=\"(?<url>.+?_480p.mov)\""); break; - case TrailerSize.HD720p: + case TrailerSize.h720p: regex = new Regex("HREF=\"(?<url>.+?_720p.mov)\""); break; - case TrailerSize.HD1080p: + case TrailerSize.h1080p: regex = new Regex("HREF=\"(?<url>.+?_1080p.mov)\""); break; } @@ -65,6 +66,7 @@ string url = regex.Match(content.Xml).Groups["url"].Value; return new Uri(content.WebResponse.ResponseUri, url); } + */ } Modified: trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/ItmsHelper.cs =================================================================== --- trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/ItmsHelper.cs 2007-09-03 19:59:11 UTC (rev 890) +++ trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/ItmsHelper.cs 2007-09-04 07:32:31 UTC (rev 891) @@ -37,7 +37,7 @@ #region Constants // The iTunes server won't talk to us unless we pretend to be a bona-fide iTunes client private const string USER_AGENT = "User-Agent: iTunes/6.0 (Windows)"; - private static Hashtable HighDef = HDHelper.GetAvailableMovies(); + //private static Hashtable HighDef = HDHelper.GetAvailableMovies(); #endregion @@ -52,8 +52,9 @@ //String desc; if (field.Success) { - //Log.Info("got the movie details for {0}",trailerInfo.Title); + //Log.Info("got the movie overview {0}",trailerInfo.Title); trailerInfo.Overview = field.Groups["overview"].Value.Replace("\r\n", " ").Replace('\u0092', '\'').Replace('\u0093', '"').Replace('\u0094', '"'); + //Log.Info("got the movie overview {0}", trailerInfo.Overview); } String name; String url; @@ -82,6 +83,7 @@ /// <returns></returns> static public TrailerInfo PopulateTrailerDetails(TrailerInfo trailerInfo, ITMSClient.TrailerSize desiredSize) { + Log.Info("pop details for " + trailerInfo.Url); //Log.Info("Populating Trailer details for {0}", trailerInfo.Title); string[] MONTHS = new string[]{"January","February","March","April","May","June","July","August","September","October","November","December"}; //const string DIRECTOR = "(dir.)"; @@ -90,6 +92,7 @@ StringBuilder actors = new StringBuilder("|"); ITMSContent infoPage = GetITMSPage(trailerInfo.Url); + Log.Info("got itms page for " + trailerInfo.Url); //Log.Info(infoPage.Xml); if (infoPage.IsValid) { @@ -151,9 +154,9 @@ trailerInfo.Actors = actors.ToString(); */ trailerInfo.TrailerStreamCollection = new TrailerStreamCollection(); - + /* // WARNING: HACK CODE FOR HIGHDEF TRAILERS - if (desiredSize >= TrailerSize.HD480p) + if (desiredSize >= TrailerSize.h480p) { if (HighDef.Contains(trailerInfo.Title)) { @@ -168,16 +171,18 @@ } } // END HACK CODE - + */ // Get movie trailer streams if (desiredSize != TrailerSize.None && trailerInfo.TrailerStreamCollection.Count == 0) { foreach (Capture url in fields.Groups["urls"].Captures) { //Log.Info("Found stream url:{0}", url); - TrailerStreamCollection tsc = GetTrailerStreamCollection(new Uri(infoPage.WebResponse.ResponseUri, url.Value)); + //TrailerStreamCollection tsc = GetTrailerStreamCollection(new Uri(infoPage.WebResponse.ResponseUri, url.Value)); + TrailerStreamCollection tsc = GetTrailerStreamCollection(infoPage); TrailerStream myStream = GetDesiredTrailerStream(tsc, desiredSize); + Log.Info("Addinf stream to collection:" + myStream.Uri); trailerInfo.TrailerStreamCollection.Add(myStream); //trailerInfo.TrailerStreamCollection = tsc; } @@ -229,6 +234,7 @@ static public ITMSContent GetITMSPage(Uri uri, DateTime ifModifiedSince) { + //Log.Info("GetItmsPage witrh uri:" + uri); const int TIMEOUT = 30000; // 30 seconds StreamReader sReader = null; HttpWebRequest request = null; @@ -236,7 +242,7 @@ ITMSContent content = null; //Log.Debug("GetITMSPage: " + uri.AbsoluteUri); - //Log.Info("GetITMSPage: " + uri.AbsoluteUri); + Log.Info("GetITMSPage: " + uri.AbsoluteUri); try { request = (HttpWebRequest) HttpWebRequest.Create(uri); @@ -297,6 +303,11 @@ /// <returns></returns> private static TrailerStream GetDesiredTrailerStream(TrailerStreamCollection trailerStreams, TrailerSize desiredSize) { + Log.Info("GetDesiredTrailerStream - desiredSize=" + desiredSize); + foreach (TrailerStream stream1 in trailerStreams) + { + Log.Info("GetDesiredTrailerStream - size available:" + stream1.Size); + } //Log.Info("getting desired Trailer size of {0}", desiredSize); // Find the largest desired size supported by the available streams while (trailerStreams.ContainsKey(desiredSize) == false && desiredSize > 0) @@ -329,11 +340,13 @@ /// </summary> /// <param name="trailerInfo">Trailer info.</param> /// <returns></returns> - private static TrailerStreamCollection GetTrailerStreamCollection(Uri url) + //private static TrailerStreamCollection GetTrailerStreamCollection(Uri url) + private static TrailerStreamCollection GetTrailerStreamCollection(ITMSContent trailerPage) { + //Log.Info("GetTrailerStreamCollection url:" + url); TrailerStreamCollection streamCollection = new TrailerStreamCollection(3); - ITMSContent trailerPage = GetITMSPage(url); + //ITMSContent trailerPage = GetITMSPage(url); if (trailerPage.IsValid) { string type = String.Empty; Modified: trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/RegexParsers.cs =================================================================== --- trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/RegexParsers.cs 2007-09-03 19:59:11 UTC (rev 890) +++ trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/RegexParsers.cs 2007-09-04 07:32:31 UTC (rev 891) @@ -3,107 +3,131 @@ namespace ITMSClient { - /// <summary> - /// Regular expression parsers for iTunes movie XML pages - /// </summary> - internal sealed class RegexParsers - { - /// <summary> - /// Used to find the link to the next index page from the current index page - /// Returns the url and page number - /// </summary> - internal static Regex indexNextPageRegex = new Regex( - @"\<GotoURL url=""(?<url>index_(?<pagenum>\d{1,3})\.xml)""\>\s*\<TextView[^/]*?\<B\>More", - RegexOptions.Singleline - | RegexOptions.ExplicitCapture - | RegexOptions.Compiled - ); + /// <summary> + /// Regular expression parsers for iTunes movie XML pages + /// </summary> + internal sealed class RegexParsers + { + /// <summary> + /// Used to find the link to the next index page from the current index page + /// Returns the url and page number + /// </summary> + internal static Regex indexNextPageRegex = new Regex( + @"\<GotoURL url=""(?<url>\w*_(?<pagenum>\d{1,3})\.xml)""\>\s*\<TextView[^/]*?\<B\>More", + RegexOptions.Singleline + | RegexOptions.ExplicitCapture + | RegexOptions.Compiled + ); + internal static Regex indexBackPageRegex = new Regex( + @"\<GotoURL url=""(?<url>\w*_(?<pagenum>\d{1,3})\.xml)""\>\s*\<TextView[^/]*?\<B\>Back", + RegexOptions.Singleline + | RegexOptions.ExplicitCapture + | RegexOptions.Compiled + ); - /// <summary> - /// Used to pull the title, studio and url link for each movie trailer on the index page - /// </summary> - internal static Regex indexDetailsRegex = new Regex( - //"<GotoURL[^>]+url=\"(?<url>/moviesxml/[^\"]+?/index.xml)\">\\s*<B>(?<title>[^<]+)</B>.+?" - //+ "<GotoURL[^>]+>\\s*(?<studio>.+?)\\s*</GotoURL>", + /// <summary> + /// Used to pull the title, studio and url link for each movie trailer on the index page + /// </summary> + internal static Regex indexDetailsRegex = new Regex( + //"<GotoURL[^>]+url=\"(?<url>/moviesxml/[^\"]+?/index.xml)\">\\s*<B>(?<title>[^<]+)</B>.+?" + //+ "<GotoURL[^>]+>\\s*(?<studio>.+?)\\s*</GotoURL>", //"<GotoURL[^>]+url=\"(?<url>/moviesxml/[^\"]+?/index.xml)\">\\s*<[^>]+><B>(?<title>[^<]+)</B>[^>]+>(?>\\s+[^>]+>)+\\s+<GotoURL[^>]+>\\s*<[^>]+>(?<studio>.+?)\\s*</SetFontStyle>", //"<GotoURL[^>]+url=\"(?<url>/moviesxml/[^\"]+?/index.xml)\">\\s*<[^>]+><B>(?<title>[^<]+)</B>[^>]+>.+?<GotoURL[^>]+>\\s*<[^>]+>(?<studio>.+?)\\s*</GotoURL>", @"<PictureView[^.]+ url=""(?<poster>[^""]*.jpg)"".+?<GotoURL[^>]+url=""(?<url>/moviesxml/[^""]+?/index.xml)"">\s*<[^>]+><B>(?<title>[^<]+)</B>[^>]+>.+?<GotoURL[^>]+>\s*<[^>]+>(?<studio>.+?)\s*</GotoURL>", - RegexOptions.Singleline - | RegexOptions.ExplicitCapture - | RegexOptions.Compiled - ); + RegexOptions.Singleline + | RegexOptions.ExplicitCapture + | RegexOptions.Compiled + ); - /// <summary> - /// Used to capture all the movie details from the movie details index.xml page - /// </summary> - internal static Regex moviedetailsRegex1 = new Regex( - @"<PictureView.+?url=""(?<poster>[^""]+)"".+?" + internal static Regex indexDetailsRegex2 = new Regex( + "<GotoURL url=\"(?<url>[^\"]*)\".+?\\s*<PictureView.+?url=\"(" + + "?<poster>[^\"]+)\".+?[^>]+>.+?[^>]+>.+?[^>]+>.+?[^>]+>.+?[^>" + + "]+>.+?\\s*<b>(?<title>[^<]+)</b>.+?[^>]+>.+?[^>]+>.+?[^>]+>." + + "+?[^>]+>.+?\\s*(?<studio>.+?)\\s*</", + RegexOptions.Singleline + | RegexOptions.ExplicitCapture + | RegexOptions.Compiled + ); + internal static Regex indexBoxOfficeRegex = new Regex( + "<GotoURL target=\"[^\"]*\" url=\"(?<url>[^\"]*)\".+?\\s*[^>]" + + "+>.+?[^>]+>.+?[^>]+>.+?[^>]+>.+?[^>]+>.+?[^>]+>.+?[^>]+>\\s*" + + "<b>(?<title>[^<]+)</b>(?<poster>)(?<studio>)", +RegexOptions.Singleline + | RegexOptions.ExplicitCapture + | RegexOptions.Compiled + ); + + /// <summary> + /// Used to capture all the movie details from the movie details index.xml page + /// </summary> + internal static Regex moviedetailsRegex1 = new Regex( + @"<PictureView.+?url=""(?<poster>[^""]+)"".+?" + @"<TextView[^>]*>\s*[^>]+>\s*<b>(?<title>[^<]+?)</b>.+?" + @"<TextView[^>]*>\s*[^>]+>\s*(?<copyright>[^<]+?)\s*<.+?" + @"<TextView[^>]*>\s*[^>]+>\s*(?<overview>[^<]*?)\s*<", - RegexOptions.Singleline - | RegexOptions.ExplicitCapture - | RegexOptions.Compiled - ); + RegexOptions.Singleline + | RegexOptions.ExplicitCapture + | RegexOptions.Compiled + ); - internal static Regex moviedetailsRegex2 = new Regex( - //@"Release:\s*(?<release>[^<]+?)\s*<.+?" - //+ @"<TextView[^>]*>(\s*<GotoURL[^>]*>(?<genres>[^<]+)</GotoURL>,?){0,}\s*</TextView>.+?" - //+ @"Rating:\s*(?<rating>.+?)\s*<.+?" - //+ @"(<TextView[^>]*>\s*(?<cast>[^<]*?)\s*</TextView>.+?){0,}</VBoxView>.+?" - // @"(<GotoURL[^>]+url=""(?<urls>/moviesxml/[^>]+?/index.xml)"">\s*<TextView.+?){0,}</Document>", + internal static Regex moviedetailsRegex2 = new Regex( + //@"Release:\s*(?<release>[^<]+?)\s*<.+?" + //+ @"<TextView[^>]*>(\s*<GotoURL[^>]*>(?<genres>[^<]+)</GotoURL>,?){0,}\s*</TextView>.+?" + //+ @"Rating:\s*(?<rating>.+?)\s*<.+?" + //+ @"(<TextView[^>]*>\s*(?<cast>[^<]*?)\s*</TextView>.+?){0,}</VBoxView>.+?" + // @"(<GotoURL[^>]+url=""(?<urls>/moviesxml/[^>]+?/index.xml)"">\s*<TextView.+?){0,}</Document>", "<GotoURL[^>]+url=\"(?<urls>/moviesxml/[^\"]+)[^>]*>\\s*<TextView", - RegexOptions.Singleline - | RegexOptions.ExplicitCapture - | RegexOptions.Compiled - ); + RegexOptions.Singleline + | RegexOptions.ExplicitCapture + | RegexOptions.Compiled + ); - internal static Regex dateRegex = new Regex( - @"(?<month>\w+) (?<day>\d+).+?(?<year>(19|20)\d\d)", - RegexOptions.ExplicitCapture - | RegexOptions.Compiled - ); + internal static Regex dateRegex = new Regex( + @"(?<month>\w+) (?<day>\d+).+?(?<year>(19|20)\d\d)", + RegexOptions.ExplicitCapture + | RegexOptions.Compiled + ); - /// <summary> - /// Used to find the different sizes of Quicktime trailer movies available from - /// the trailer size selection page - /// Returns the url and the size of the movie - /// </summary> - internal static Regex streamRegex = new Regex( - //@"<GotoURL.+?url=""(?<url>.*?(?<size>(small|medium|large|fullscreen))\.xml)""", + /// <summary> + /// Used to find the different sizes of Quicktime trailer movies available from + /// the trailer size selection page + /// Returns the url and the size of the movie + /// </summary> + internal static Regex streamRegex = new Regex( + //@"<GotoURL.+?url=""(?<url>.*?(?<size>(small|medium|large|fullscreen))\.xml)""", @"<key>episodeURL</key><string>(?<url>[^<]*(?<size>h[\d]*p*)[w]*\.mov)", - RegexOptions.ExplicitCapture - | RegexOptions.Compiled - ); - - //Used to find the multiple trailer urls - internal static Regex trailerLinkRegex = new Regex( - "<HBoxView[^>]*>\\s*<GotoURL\\starget=\"main\"\\surl=\"(?<url>[^\"]*)[^=]*=[^=]*=\"(?<name>[^\"]*)", - RegexOptions.Singleline - | RegexOptions.ExplicitCapture - | RegexOptions.Compiled - ); - + RegexOptions.ExplicitCapture + | RegexOptions.Compiled + ); - /// <summary> - /// Used to pull the type and length of the Quicktime trailer movies available from - /// the trailer size selection page - /// </summary> - internal static Regex streamDetailsRegex = new Regex( - @"<b>(?<type>.+?)\s\((?<minutes>\d{0,2}):(?<seconds>\d{2})\)?</b>", - RegexOptions.ExplicitCapture - | RegexOptions.Compiled - ); + //Used to find the multiple trailer urls + internal static Regex trailerLinkRegex = new Regex( + "<HBoxView[^>]*>\\s*<GotoURL\\starget=\"main\"\\surl=\"(?<url>[^\"]*)[^=]*=[^=]*=\"(?<name>[^\"]*)", + RegexOptions.Singleline + | RegexOptions.ExplicitCapture + | RegexOptions.Compiled + ); - /// <summary> - /// Used to find the actual Quicktime movie on the final movie playback page - /// Returns the url of the .mov file - /// </summary> - internal static Regex movRegex = new Regex( - @"\<MovieView.+?url=""(?<url>.+?\.mov)""", - RegexOptions.ExplicitCapture - | RegexOptions.Compiled - ); - } + /// <summary> + /// Used to pull the type and length of the Quicktime trailer movies available from + /// the trailer size selection page + /// </summary> + internal static Regex streamDetailsRegex = new Regex( + @"<b>(?<type>.+?)\s\((?<minutes>\d{0,2}):(?<seconds>\d{2})\)?</b>", + RegexOptions.ExplicitCapture + | RegexOptions.Compiled + ); + + /// <summary> + /// Used to find the actual Quicktime movie on the final movie playback page + /// Returns the url of the .mov file + /// </summary> + internal static Regex movRegex = new Regex( + @"\<MovieView.+?url=""(?<url>.+?\.mov)""", + RegexOptions.ExplicitCapture + | RegexOptions.Compiled + ); + + } } Modified: trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/TrailerIndex.cs =================================================================== --- trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/TrailerIndex.cs 2007-09-03 19:59:11 UTC (rev 890) +++ trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/TrailerIndex.cs 2007-09-04 07:32:31 UTC (rev 891) @@ -33,6 +33,7 @@ protected ITMSContent _content = null; protected TrailerInfoCollection _trailers = null; protected Uri _nextPageUri = null; + protected Uri _backPageUri = null; protected string _sectionName; #region Constructor @@ -78,17 +79,45 @@ { get { + if (_nextPageUri == null) { + Match nextPage = RegexParsers.indexNextPageRegex.Match(Content.Xml); - if (nextPage.Success) - this._nextPageUri = new Uri(Content.WebResponse.ResponseUri, nextPage.Groups["url"].Value); - else - this._nextPageUri = null; + + if (nextPage.Success) + { + this._nextPageUri = new Uri(Content.WebResponse.ResponseUri, nextPage.Groups["url"].Value); + Log.Info("Found next page"); + } + else + this._nextPageUri = null; } return _nextPageUri; } } + public Uri BackPageUri + { + get + { + Log.Info("backPage uri requested"); + if (_backPageUri == null) + { + Log.Info("backPage currently null"); + Match backPage = RegexParsers.indexBackPageRegex.Match(Content.Xml); + Log.Info("backPage regex performed"); + if (backPage.Success) + { + Log.Info("backPage regex successful"); + this._backPageUri = new Uri(Content.WebResponse.ResponseUri, backPage.Groups["url"].Value); + Log.Info("TrailerIndex.BackPageUri - Found previous page"); + } + else + this._backPageUri = null; + } + return _backPageUri; + } + } /// <summary> /// Gets the count of trailers on the page @@ -112,21 +141,48 @@ protected void ParseIndexPage() { Log.Info("Parsing index page"); - MatchCollection movieItemCollection = RegexParsers.indexDetailsRegex.Matches(Content.Xml); - _trailers = new TrailerInfoCollection(movieItemCollection.Count); - Debug.Assert(movieItemCollection.Count > 0, "No movies found in index page xml"); + MatchCollection movieItemCollection = RegexParsers.indexDetailsRegex.Matches(Content.Xml); + if (movieItemCollection.Count == 0) + { + movieItemCollection = RegexParsers.indexDetailsRegex2.Matches(Content.Xml); + + if (movieItemCollection.Count == 0) + { + movieItemCollection = RegexParsers.indexBoxOfficeRegex.Matches(Content.Xml); + if (movieItemCollection.Count == 0) + { + Log.Info("No movies found in index page xml"); + return; + } + } + + } + _trailers = new TrailerInfoCollection(movieItemCollection.Count); + Log.Info("ParseIndexPage - Found {0} trailers.", movieItemCollection.Count); foreach (Match movieItem in movieItemCollection) { + Log.Info("ParseIndexPage - success ={0}", movieItem.Success); Debug.Assert(movieItem.Success); TrailerInfo trailerInfo = new TrailerInfo(); trailerInfo.Url = new Uri(Content.WebResponse.ResponseUri, movieItem.Groups["url"].Value); + Log.Info("ParseIndexPage - url set"); trailerInfo.Title = movieItem.Groups["title"].Value; - trailerInfo.Studio = movieItem.Groups["studio"].Value; - trailerInfo.PosterUrl = new Uri(movieItem.Groups["poster"].Value); + Log.Info("ParseIndexPage - title set"); + if (movieItem.Groups["studio"] != null) + { + trailerInfo.Studio = movieItem.Groups["studio"].Value; + Log.Info("ParseIndexPage - studio set"); + } + if (movieItem.Groups["poster"] != null && !String.IsNullOrEmpty(movieItem.Groups["poster"].Value)) + { + trailerInfo.PosterUrl = new Uri(movieItem.Groups["poster"].Value); + Log.Info("ParseIndexPage - poster set"); + } trailerInfo.Section = this._sectionName; //Console.WriteLine("Adding trailer {0}", trailerInfo.Title); _trailers.Add(trailerInfo); + Log.Info("ParseIndexPage - trailer added to list"); } } #endregion Modified: trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/TrailerStream.cs =================================================================== --- trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/TrailerStream.cs 2007-09-03 19:59:11 UTC (rev 890) +++ trunk/plugins/OnlineVideos/Source/OnlineVideos/ItunesUtils/TrailerStream.cs 2007-09-04 07:32:31 UTC (rev 891) @@ -12,9 +12,9 @@ //Medium, //Large, //Fullscreen, - HD480p, - HD720p, - HD1080p + h480p, + h720p, + h1080p } /// <summary> Modified: trunk/plugins/OnlineVideos/Source/OnlineVideos/SiteUtilBase.cs =================================================================== --- trunk/plugins/OnlineVideos/Source/OnlineVideos/SiteUtilBase.cs 2007-09-03 19:59:11 UTC (rev 890) +++ trunk/plugins/OnlineVideos/Source/OnlineVideos/SiteUtilBase.cs 2007-09-04 07:32:31 UTC (rev 891) @@ -85,6 +85,24 @@ { return ""; } + + public virtual bool hasNextPage() + { + return false; + } + public virtual List<GUIOnlineVideos.VideoInfo> getNextPageVideos() + { + return new List<GUIOnlineVideos.VideoInfo>(); + } + public virtual bool hasPreviousPage() + { + return false; + } + public virtual List<GUIOnlineVideos.VideoInfo> getPreviousPageVideos() + { + return new List<GUIOnlineVideos.VideoInfo>(); + } + //public virtual bool addFavorite(String fsId,String fsUserName,String fsPassword){ public virtual void AddFavorite(GUIOnlineVideos.VideoInfo foVideo,String fsSiteId){ //return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |