From: <gre...@us...> - 2007-07-19 00:31:15
|
Revision: 745 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=745&view=rev Author: gregmac45 Date: 2007-07-18 17:30:46 -0700 (Wed, 18 Jul 2007) Log Message: ----------- Added Paths: ----------- trunk/plugins/SabNzbControl/ trunk/plugins/SabNzbControl/AssemblyInfo.cs trunk/plugins/SabNzbControl/GUISabNzb.cs trunk/plugins/SabNzbControl/MyClass.cs trunk/plugins/SabNzbControl/Runner/ trunk/plugins/SabNzbControl/Runner/AssemblyInfo.cs trunk/plugins/SabNzbControl/Runner/Main.cs trunk/plugins/SabNzbControl/Runner/Runner.csproj trunk/plugins/SabNzbControl/Runner/Runner.sln trunk/plugins/SabNzbControl/SabNzbControl.csproj trunk/plugins/SabNzbControl/SabNzbControl.sln trunk/plugins/SabNzbControl/bin/ trunk/plugins/SabNzbControl/bin/Debug/ trunk/plugins/SabNzbControl/bin/Debug/Core.DLL trunk/plugins/SabNzbControl/bin/Debug/SabNzbControl.dll trunk/plugins/SabNzbControl/bin/Debug/SabNzbControl.pdb trunk/plugins/SabNzbControl/bin/Debug/Utils.DLL trunk/plugins/SabNzbControl/obj/ trunk/plugins/SabNzbControl/obj/Debug/ trunk/plugins/SabNzbControl/obj/Debug/SabNzbControl.dll trunk/plugins/SabNzbControl/obj/Debug/SabNzbControl.pdb trunk/plugins/SabNzbControl/obj/SabNzbControl.csproj.FileList.txt Added: trunk/plugins/SabNzbControl/AssemblyInfo.cs =================================================================== --- trunk/plugins/SabNzbControl/AssemblyInfo.cs (rev 0) +++ trunk/plugins/SabNzbControl/AssemblyInfo.cs 2007-07-19 00:30:46 UTC (rev 745) @@ -0,0 +1,31 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("SabNzbControl")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SabNzbControl")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. +[assembly: ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("1.0.*")] Added: trunk/plugins/SabNzbControl/GUISabNzb.cs =================================================================== --- trunk/plugins/SabNzbControl/GUISabNzb.cs (rev 0) +++ trunk/plugins/SabNzbControl/GUISabNzb.cs 2007-07-19 00:30:46 UTC (rev 745) @@ -0,0 +1,721 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.XPath; +using System.ComponentModel; +using System.Net; +using System.Web; +using System.IO; +using System.Text.RegularExpressions; +using MediaPortal.GUI.Library; +using MediaPortal.Dialogs; +//using MediaPortal.Utils.Services; +using MediaPortal.Utils; +using MediaPortal.Player; + +namespace OnlineVideos +{ + public class GUIOnlineVideos : GUIWindow, ISetupForm + { + [SkinControlAttribute(2)] + protected GUIButtonControl btnViewAs = null; + [SkinControlAttribute(50)] + protected GUIFacadeControl facadeView = null; + //private ILog moLog; + protected View currentView = View.List; + private Dictionary<String, Site> moSiteList = new Dictionary<String, Site>(); + private String msSelectedSiteId; + private String msSelectedCategory; + private State _CurrentState = State.home; + private String msDownloadDir = Directory.GetCurrentDirectory()+"\\"; + private List<VideoInfo> moCurrentVideoList = new List<VideoInfo>(); + private String []msFilterArray; + private String msThumbLocation; + private int miSelectedIndex = 0; + private bool mbPlayFullscreen = true; + public enum State + { + home = 0, + categories = 1, + videos = 2 + } + public enum View + { + List = 0, + Icons = 1, + LargeIcons = 2, + FilmStrip = 3 + } + public class Site + { + public String name; + public String id; + public string username; + public string password; + public bool confirmAge; + public Dictionary<String, RssLink> RssList = new Dictionary<String, RssLink>(); + } + public class RssLink + { + public String name; + public Boolean isDynamic = false; + public String url; + } + public class VideoInfo + { + public String Title; + public String Description; + public String VideoUrl; + public String ImageUrl; + public int Length; + public String Tags; + public Object Other; + public VideoInfo() + { + Length = -1; + } + } + + public GUIOnlineVideos() + { + //ServiceProvider loServices = GlobalServiceProvider.Instance; + //moLog = loServices.Get<ILog>(); + } + public string PluginName() + { + + return "Online Videos"; + + } + + // Returns the description of the plugin is shown in the plugin menu + + public string Description() + { + + return "Youtube Plugin"; + + } + + // Returns the author of the plugin which is shown in the plugin menu + + public string Author() + { + + return "GregMac45"; + + } + + // show the setup dialog + + public void ShowPlugin() + { + + //MessageBox.Show("Nothing to configure, this is just an example"); + + } + + // Indicates whether plugin can be enabled/disabled + + public bool CanEnable() + { + + return true; + + } + + // get ID of windowplugin belonging to this setup + + public int GetWindowId() + { + + return GetID; + + } + + // Indicates if plugin is enabled by default; + + public bool DefaultEnabled() + { + + return true; + + } + + // indicates if a plugin has its own setup screen + + public bool HasSetup() + { + + return false; + + } + public override int GetID + { + get + { + return 4755; + } + set + { + } + } + + public override bool Init() + { + LoadSettings(); + return Load(GUIGraphicsContext.Skin + @"\myonlinevideos.xml"); + + } + public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) + { + strButtonText = PluginName(); + + strButtonImage = String.Empty; + + strButtonImageFocus = String.Empty; + + strPictureImage = String.Empty; + + return true; + } + public bool ShowDefaultHome() + { + return true; + } + protected override void OnPageLoad() + { + if (_CurrentState == State.home) + { + //_log.Info("onPageLoad state home"); + GUIPropertyManager.SetProperty("#header.label","Online Videos"); + DisplaySites(); + } + else if (_CurrentState == State.categories) + { + GUIPropertyManager.SetProperty("#header.label", moSiteList[msSelectedSiteId].name); + DisplayCategories(); + } + else + { + GUIPropertyManager.SetProperty("#header.label", moSiteList[msSelectedSiteId].name); + DisplayVideos(false); + facadeView.SelectedListItemIndex = miSelectedIndex; + } + base.OnPageLoad(); + } + protected override void OnShowContextMenu() + { + int liSelected = facadeView.SelectedListItemIndex-1; + if (liSelected < 0 || msSelectedSiteId=="99" || _CurrentState!=State.videos) + { + return; + } + + GUIListItem loListItem = facadeView.SelectedListItem; + GUIDialogMenu dlgSel = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); + dlgSel.Reset(); + if (dlgSel != null) + { + dlgSel.Add("Save"); // Save + if(msSelectedSiteId=="1"){ + dlgSel.Add("Related Videos"); // Related Videos + } + if(isSiteFavoriteEnabled()){ + if(msSelectedCategory.StartsWith("fav:") ==false){ + dlgSel.Add("Add to favorites"); + } + else{ + dlgSel.Add("Remove from favorites"); + } + } + } + dlgSel.DoModal(GetID); + int liSelectedIdx = dlgSel.SelectedId; + Log.Info("Selected id {0}",liSelectedIdx); + switch(liSelectedIdx){ + case 1: + SaveVideo(loListItem); + break; + case 2: + Log.Info("Getting related videos on {0} using tags:{1}",SiteUtilFactory.getSiteUtil(msSelectedSiteId),moCurrentVideoList[liSelected].Tags); + SiteUtilBase site = SiteUtilFactory.getSiteUtil(msSelectedSiteId); + Log.Info("VideoList before:"); + foreach(VideoInfo video in moCurrentVideoList){ + Log.Info(video.Title); + } + moCurrentVideoList = site.getRelatedVideos(moCurrentVideoList[liSelected].Tags); + Log.Info("VideoList after:"); + foreach(VideoInfo video in moCurrentVideoList){ + Log.Info(video.Title); + } + DisplayVideos(false); + break; + case 3: + SiteUtilBase siteUtil = SiteUtilFactory.getSiteUtil(msSelectedSiteId); + Site loSite = moSiteList [msSelectedSiteId]; + if(msSelectedCategory.StartsWith("fav:") == false){ + siteUtil.addFavorite(moCurrentVideoList[liSelected].VideoUrl,loSite.username,loSite.password); + }else{ + siteUtil.removeFavorite(moCurrentVideoList[liSelected].VideoUrl,loSite.username,loSite.password); + } + break; + } + base.OnShowContextMenu(); + } + public override void OnAction(Action action) + { + if (action.wID == Action.ActionType.ACTION_PREVIOUS_MENU) + { + if (_CurrentState == State.videos) + { + DisplayCategories(); + _CurrentState = State.categories; + return; + } + else if (_CurrentState == State.categories) + { + DisplaySites(); + _CurrentState = State.home; + return; + } + } + base.OnAction(action); + } + protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) + { + Log.Info("Onclicked action type:{0}",actionType); + if (control == facadeView) + { + + if (_CurrentState == State.home) + { + msSelectedSiteId = facadeView.SelectedListItem.Path; + GUIPropertyManager.SetProperty("#header.label", moSiteList[msSelectedSiteId].name); + DisplayCategories(); + _CurrentState = State.categories; + } + else if (_CurrentState == State.categories) + { + if (facadeView.SelectedListItemIndex == 0) + { + DisplaySites(); + _CurrentState = State.home; + } + else + { + msSelectedCategory = facadeView.SelectedListItem.Path; + DisplayVideos(true); + _CurrentState = State.videos; + } + } + else if (_CurrentState == State.videos) + { + ImageDownloader._stopDownload = true; + if (facadeView.SelectedListItemIndex == 0) + { + DisplayCategories(); + _CurrentState = State.categories; + } + else + { + miSelectedIndex = facadeView.SelectedListItemIndex; + //play the video + Play(moCurrentVideoList[facadeView.SelectedListItemIndex -1]); + } + } + } + else if (control == btnViewAs) + { + //bool shouldContinue = false; + //do + //{ + //shouldContinue = false; + switch (currentView) + { + case View.List: + currentView = View.Icons; + //if (!AllowView(CurrentView) || facadeView.ThumbnailView == null) + // shouldContinue = true; + //else + facadeView.View = GUIFacadeControl.ViewMode.SmallIcons; + break; + case View.Icons: + currentView = View.LargeIcons; + //if (!AllowView(CurrentView) || facadeView.ThumbnailView == null) + // shouldContinue = true; + //else + facadeView.View = GUIFacadeControl.ViewMode.LargeIcons; + //facadeView. + break; + case View.LargeIcons: + currentView = View.FilmStrip; + //if (!AllowView(CurrentView) || facadeView.FilmstripView == null) + // shouldContinue = true; + //else + facadeView.View = GUIFacadeControl.ViewMode.Filmstrip; + break; + case View.FilmStrip: + currentView = View.List; + //if (!AllowView(CurrentView) || facadeView.ListView == null) + // shouldContinue = true; + //else + facadeView.View = GUIFacadeControl.ViewMode.List; + break; + } + //} while (shouldContinue); + //SelectCurrentItem(); + GUIControl.FocusControl(GetID, controlId); + + string strLine = String.Empty; + View view = currentView; + switch (view) + { + case View.List: + strLine = GUILocalizeStrings.Get(101); + break; + case View.Icons: + strLine = GUILocalizeStrings.Get(100); + break; + case View.LargeIcons: + strLine = GUILocalizeStrings.Get(417); + break; + case View.FilmStrip: + strLine = GUILocalizeStrings.Get(733); + break; + } + GUIControl.SetControlLabel(GetID, btnViewAs.GetID, strLine); + + return; + }//if (control == btnViewAs) + base.OnClicked(controlId, control, actionType); + } + #region new methods + private void LoadSettings() + { + XmlDocument doc = new XmlDocument(); + try + { + doc.Load("OnlineVideoSettings.xml"); + XmlNode filter = doc.SelectSingleNode("//settings/filter"); + String lsFilter = filter.InnerText; + msFilterArray = lsFilter.Split(new char[] { ',' }); + if (msFilterArray.Length == 1 && msFilterArray[0] == "") + { + msFilterArray = null; + } + XmlNode thumbNode = doc.SelectSingleNode("//settings/thumbLocation"); + msThumbLocation = thumbNode.InnerText; + + //lsFilterArray + //Log.Write("filter value {0}",filter.InnerText); + + XmlNode root = doc.SelectSingleNode("//settings/sites/site"); + XmlNodeList nodeList; + nodeList = root.SelectNodes("//settings/sites/site"); + List<Site> loSiteList = new List<Site>(); + Site loSite; + XmlNodeList RssNodeList; + RssLink loRssData; + bool lbDonwloadDirSet = false; + foreach (XmlNode chileNode in nodeList) + { + loSite = new Site(); + + XmlNode node = chileNode.SelectSingleNode("name"); + loSite.name = node.InnerText; + + node = chileNode.SelectSingleNode("id"); + loSite.id = node.InnerText; + + node = chileNode.SelectSingleNode("user"); + if(node!=null) + loSite.username = node.InnerText; + + node = chileNode.SelectSingleNode("password"); + if(node!=null) + loSite.password = node.InnerText; + + node = chileNode.SelectSingleNode("confirmAge"); + if(node!=null) + loSite.confirmAge = node.InnerText == "yes"; + + //Console.WriteLine("site Node:{0}", loSite.ToString()); + RssNodeList = chileNode.SelectNodes("rss"); + foreach (XmlNode RssNode in RssNodeList) + { + loRssData = new RssLink(); + //node = chileNode.SelectSingleNode("d"); + + loRssData.name = RssNode.Attributes["name"].InnerText; + try{ + loRssData.isDynamic = RssNode.Attributes["dynamic"].InnerText.Equals("yes"); + Log.Info("Found a dynamic category for site {0}",loSite.name); + }catch(Exception){} + loRssData.url = RssNode.InnerText; + if (lbDonwloadDirSet==false && loSite.id == "99") + { + msDownloadDir = loRssData.url; + lbDonwloadDirSet = true; + } + //Console.WriteLine("rss Node:{0}", loRssData.ToString()); + loSite.RssList.Add(loRssData.name, loRssData); + } + moSiteList.Add(loSite.id, loSite); + } + } + catch (Exception e) + { + //moLog.Error(e); + Log.Error(e); + } + } + private void DisplaySites() + { + //facadeView.Clear(); + GUIControl.ClearControl(GetID, facadeView.GetID); + + GUIListItem loListItem; + foreach (Site loSite in moSiteList.Values) + { + loListItem = new GUIListItem(loSite.name); + loListItem.Path = loSite.id; + loListItem.IsFolder = true; + MediaPortal.Util.Utils.SetDefaultIcons(loListItem); + facadeView.Add(loListItem); + } + //GUIPropertyManager.SetProperty("#itemcount", facadeView.Count-1 + ""); + } + private void DisplayCategories() + { + // facadeView.Clear(); + GUIControl.ClearControl(GetID, facadeView.GetID); + + GUIListItem loListItem; + loListItem = new GUIListItem(".."); + loListItem.IsFolder = true; + MediaPortal.Util.Utils.SetDefaultIcons(loListItem); + facadeView.Add(loListItem); + Site loSite = moSiteList[msSelectedSiteId]; + SiteUtilBase loSiteUtil = SiteUtilFactory.getSiteUtil(msSelectedSiteId); + foreach (RssLink loCat in loSite.RssList.Values) + { + if (loCat.isDynamic) + { + Log.Info("Looking for dynamic categories for {0}",loCat.name); + List<RssLink> loNewCatList= loSiteUtil.getDynamicCategories(loCat.url); + Log.Info("Found {0} dynamic categoties.", loNewCatList.Count); + foreach (RssLink loNewCat in loNewCatList) + { + loListItem = new GUIListItem(loNewCat.name); + loListItem.Path = loNewCat.url; + loListItem.IsFolder = true; + MediaPortal.Util.Utils.SetDefaultIcons(loListItem); + facadeView.Add(loListItem); + } + } + else + { + loListItem = new GUIListItem(loCat.name); + loListItem.Path = loCat.url; + loListItem.IsFolder = true; + MediaPortal.Util.Utils.SetDefaultIcons(loListItem); + facadeView.Add(loListItem); + } + } + //GUIPropertyManager.SetProperty("#itemcount", facadeView.Count-1 + ""); + //SiteUtilBase loSiteUtil = SiteUtilFactory.getSiteUtil(msSelectedSiteId); + if (isSiteFavoriteEnabled()) + { + loListItem = new GUIListItem("Favorites"); + loListItem.Path = "fav:"+loSite.username; + loListItem.IsFolder = true; + MediaPortal.Util.Utils.SetDefaultIcons(loListItem); + facadeView.Add(loListItem); + //loSiteUtil.getSiteFavorites(); + } + } + private bool isSiteFavoriteEnabled(){ + Site loSite = moSiteList[msSelectedSiteId]; + SiteUtilBase loSiteUtil = SiteUtilFactory.getSiteUtil(msSelectedSiteId); + return (loSiteUtil.isSiteFavoritesEnabled() && String.IsNullOrEmpty(loSite.username) == false); + } + + private void DisplayVideos(bool fbRefresh) + { + List<VideoInfo> loListItems; + GUIListItem loListItem; + GUIControl.ClearControl(GetID, facadeView.GetID); + loListItem = new GUIListItem(".."); + loListItem.IsFolder = true; + MediaPortal.Util.Utils.SetDefaultIcons(loListItem); + facadeView.Add(loListItem); + + if (fbRefresh) + { + SiteUtilBase loSiteUtil = SiteUtilFactory.getSiteUtil(msSelectedSiteId); + + if (msSelectedCategory.Contains("{0}")) + { + String lsSearchStr = String.Empty; + GetUserInputString(ref lsSearchStr); + if (FilterOut(lsSearchStr)) + { + return; + } + lsSearchStr = lsSearchStr.Replace(" ", "+"); + msSelectedCategory = String.Format(msSelectedCategory, lsSearchStr); + } + loListItems = loSiteUtil.getVideoList(msSelectedCategory); + moCurrentVideoList.Clear(); + } + else + { + loListItems = moCurrentVideoList; + } + //facadeView.Clear(); + + //GUIListItem loListItem; + List<String> loImageUrlList = new List<string>(); + + foreach (VideoInfo loVideoInfo in loListItems) + { + loVideoInfo.Description = cleanString(loVideoInfo.Description); + if (FilterOut(loVideoInfo.Title) || FilterOut(loVideoInfo.Description)) + { + continue; + } + loListItem = new GUIListItem(loVideoInfo.Title); + loListItem.Path = loVideoInfo.VideoUrl; + facadeView.Add(loListItem); + loImageUrlList.Add(loVideoInfo.ImageUrl); + if (fbRefresh) + { + moCurrentVideoList.Add(loVideoInfo); + } + } + //GUIPropertyManager.SetProperty("#itemcount", facadeView.Count-1 +""); + + + BackgroundWorker worker = new BackgroundWorker(); + Object[] loParms = new Object[4]; + loParms[0] = facadeView; + loParms[1] = loImageUrlList; + loParms[2] = miSelectedIndex+""; + loParms[3] = msThumbLocation; + + worker.DoWork += new DoWorkEventHandler(ImageDownloader.DownloadImages); + worker.RunWorkerAsync(loParms); + + using (WaitCursor cursor = new WaitCursor()) + { + while (ImageDownloader._imagesDone == false) + { + GUIWindowManager.Process(); + } + facadeView.SelectedListItemIndex = miSelectedIndex; + } + + + } + private bool GetUserInputString(ref string sString) + { + VirtualKeyboard keyBoard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD); + keyBoard.Reset(); + keyBoard.IsSearchKeyboard = true; + keyBoard.Text = sString; + keyBoard.DoModal(GetID); // show it... + if (keyBoard.IsConfirmed) sString = keyBoard.Text; + return keyBoard.IsConfirmed; + } + private void Play(VideoInfo foListItem) + { + //foListItem. + Site loSite = moSiteList[msSelectedSiteId]; + String lsUrl = SiteUtilFactory.getSiteUtil(msSelectedSiteId).getUrl(foListItem,loSite); + if (mbPlayFullscreen) + { + g_Player.Play(lsUrl); + GUIGraphicsContext.IsFullScreenVideo = true; + GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO); + } + else + { + GUIWindowManager.ActivateWindow(4760); + String[] loParms = new String[2]; + loParms[0] = "1"; + loParms[1] = ""; + GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_PLAYBACK_STARTED, 4760, 4750, 0, 0, 0, loParms); + msg.Label = moSiteList[msSelectedSiteId].name; + msg.Label2 = foListItem.Title; + //Log.Write("itemid = {0}", foListItem.ItemId); + //Log.Write("url = {0}", lsUrl); + msg.Label3 = foListItem.Description; + msg.Label4 = lsUrl; + + GUIWindowManager.SendThreadMessage(msg); + } + } + private void SaveVideo(GUIListItem foListItem) + { + String lsUrl = SiteUtilFactory.getSiteUtil(msSelectedSiteId).getUrl(foListItem.Path); + WebClient loClient = new WebClient(); + loClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); + loClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted); + String lsFileName = msDownloadDir+foListItem.Label; + loClient.DownloadFileAsync(new Uri(lsUrl), lsFileName + ".flv", foListItem.Label); + } + + private void DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) + { + GUIDialogNotify loDlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); + loDlgNotify.SetText(e.UserState+" Download Complete"); + loDlgNotify.DoModal(GetID); + } + private bool FilterOut(String fsStr) + { + if (fsStr == String.Empty) + { + return false; + } + if (msFilterArray != null) + { + foreach (String lsFilter in msFilterArray) + { + if (fsStr.IndexOf(lsFilter, StringComparison.OrdinalIgnoreCase) >= 0) + { + Log.Info("Filtering out:{0}\n based on filter:{1}", fsStr, lsFilter); + return true; + //return false; + } + } + + } + return false; + } + private String cleanString(String fsStr) + { + if (fsStr != null) + { + // Strip \n's + fsStr = Regex.Replace(fsStr, @"(\n|\r)", "", RegexOptions.Multiline); + + // Remove whitespace (double spaces) + fsStr = Regex.Replace(fsStr, @" +", "", RegexOptions.Multiline); + + // Remove + fsStr = Regex.Replace(fsStr, @" ", " ", RegexOptions.Multiline); + + + // Replace <br/> with \n + fsStr = Regex.Replace(fsStr, @"< *br */*>", "\n", RegexOptions.IgnoreCase & RegexOptions.Multiline); + + // Remove remaining HTML tags + fsStr = Regex.Replace(fsStr, @"<[^>]*>", "", RegexOptions.Multiline); + } + return fsStr; + } + #endregion + } +} Added: trunk/plugins/SabNzbControl/MyClass.cs =================================================================== --- trunk/plugins/SabNzbControl/MyClass.cs (rev 0) +++ trunk/plugins/SabNzbControl/MyClass.cs 2007-07-19 00:30:46 UTC (rev 745) @@ -0,0 +1,418 @@ +/* + * Created by SharpDevelop. + * User: GZamor1 + * Date: 4/17/2007 + * Time: 10:04 AM + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using System.Net; +using System.Xml; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Collections.Generic; +using MediaPortal.GUI.Library; +//using MediaPortal.Dialogs; +using MediaPortal.Utils; + +namespace SabNzbControl +{ + /// <summary> + /// Description of MyClass. + /// </summary> + public class GUISabNzb : GUIWindow, ISetupForm + { + #region SkinControlAttributes + [SkinControlAttribute(2)] protected GUIButtonControl btnQueue = null; + [SkinControlAttribute(7)] protected GUIButtonControl btnHistory = null; + [SkinControlAttribute(8)] protected GUIButtonControl btnNewzbin = null; + /* + [SkinControlAttribute(3)] protected GUIButtonControl btnSearch = null; + [SkinControlAttribute(6)] protected GUIButtonControl btnFavorites = null; + [SkinControlAttribute(9)] protected GUIButtonControl btnBack = null; + [SkinControlAttribute(25)] protected GUIButtonControl btnPlayList = null; + [SkinControlAttribute(34)] protected GUIButtonControl btnNextPage = null; + [SkinControlAttribute(35)] protected GUIButtonControl btnPreviousPage = null; + [SkinControlAttribute(36)] protected GUIImage imgCountry = null; + [SkinControlAttribute(37)] protected GUIButtonControl btnGenre = null; + [SkinControlAttribute(38)] protected GUIButtonControl btnCountry = null; + [SkinControlAttribute(39)] protected GUIButtonControl btnMyPlaylists = null; + */ + [SkinControlAttribute(50)] protected GUIFacadeControl facadeView = null; + #endregion + #region member variables + private String _SabNzbHost = String.Empty; + private String _SabNzbPort = String.Empty; + private String _SabNzbUser = String.Empty; + private String _SabNzbPass = String.Empty; + private String _NewzbinUser = String.Empty; + private String _NewzbinPass = String.Empty; + private String _NewzbinBaseUrl = "http://v3.newzbin.com"; + private String _NewzbinSearchUrl = "/search/query/?q={0}&area={1}&fpn=p&searchaction=go&areadone={1}&ss={2}&feed=rss"; + private String _NewzbinLoginUrl = "/account/login/"; + private String _AreaEverything = "-1"; + private String _SabNzbContext = "/sabnzbd/"; + private String _SabNzbQueueUrl = "queue/"; + private String _SabNzbHistoryUrl = "history/"; + private CookieCollection _SabLoginCookies; + private CookieCollection _NewzbinLoginCookies; + #endregion + public class NzbReport{ + public String title; + public String id; + public String url; + public String size; + public String moreInfoUrl; + public String nfoUrl; + + } + public class SabEntry{ + public String title; + public String option; + public String uid; + public String remain; + public String total; + public String eta; + } + + public string PluginName() + { + + return "SabNZB Controller"; + + } + + // Returns the description of the plugin is shown in the plugin menu + + public string Description() + { + + return "SabNzbd Controller Plugin"; + + } + + // Returns the author of the plugin which is shown in the plugin menu + + public string Author() + { + + return "GregMac45"; + + } + + // show the setup dialog + + public void ShowPlugin() + { + + //MessageBox.Show("Nothing to configure, this is just an example"); + + } + + // Indicates whether plugin can be enabled/disabled + + public bool CanEnable() + { + + return true; + + } + + // get ID of windowplugin belonging to this setup + + public int GetWindowId() + { + + return GetID; + + } + + // Indicates if plugin is enabled by default; + + public bool DefaultEnabled() + { + + return true; + + } + + // indicates if a plugin has its own setup screen + + public bool HasSetup() + { + + return false; + + } + public override int GetID + { + get + { + return 4756; + } + set + { + } + } + + public override bool Init() + { + LoadSettings(); + return Load(GUIGraphicsContext.Skin + @"\mysabnzb.xml"); + + } + public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) + { + strButtonText = PluginName(); + + strButtonImage = String.Empty; + + strButtonImageFocus = String.Empty; + + strPictureImage = String.Empty; + + return true; + } + public bool ShowDefaultHome() + { + return true; + } + protected override void OnPageLoad() + { + + } + protected override void OnShowContextMenu() + { + + } + public override void OnAction(Action action){ + + } + protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) + { + if(control == btnQueue){ + + } + + } + + #region user methods + private void LoadSettings(){ + XmlDocument doc = new XmlDocument(); + try + { + doc.Load("SabNZBControlSettings.xml"); + XmlNode node = doc.SelectSingleNode("//settings/sabnzb/host"); + _SabNzbHost = node.InnerText; + + node = doc.SelectSingleNode("//settings/sabnzb/user"); + _SabNzbUser = node.InnerText; + + node = doc.SelectSingleNode("//settings/sabnzb/password"); + _SabNzbPass = node.InnerText; + + node = doc.SelectSingleNode("//settings/sabnzb/port"); + _SabNzbPort = node.InnerText; + + node = doc.SelectSingleNode("//settings/newzbin/user"); + _NewzbinUser = node.InnerText; + node = doc.SelectSingleNode("//settings/newzbin/password"); + _NewzbinPass = node.InnerText; + + }catch (Exception e) + { + //moLog.Error(e); + Log.Error(e); + } + } + private void showQueue(){ + try{ + if(isLoggedInToSab() ==false){ + SabLogin(); + } + String url = BuildSabUrl(_SabNzbQueueUrl); + String html = getHtml(url,"","","",ref _SabLoginCookies); + List<SabEntry> queue = parseSabQueue(html); + + }catch(Exception e){ + + Log.Error(e); + + } + } + private List<SabEntry> parseSabQueue(String html){ + Regex regex = new Regex("<tr class=\"(odd|even)\">.*?<option value=\"change_.*?pp=(?<option>[0-9])\" selected>.*?<td><a href=\"\\./SAB(.*?)/\">(?<title>.*?)</td>.*?<td[^>]*?>(?<remain>.*?)/(?<total>.*?)</td>.*?<td>(?<eta>.*?)</td>.*?<td>(?<age>.*?)</td>.*?</tr>", RegexOptions.Singleline); + MatchCollection matches = regex.Matches(html); + SabEntry queueItem; + List<SabEntry>queueList = new List<SabEntry>(); + foreach(Match match in matches){ + queueItem = new SabEntry(); + queueItem.eta = match.Groups["eta"].Value; + queueItem.title = match.Groups["title"].Value; + queueItem.option = match.Groups["option"].Value; + queueItem.remain = match.Groups["remain"].Value; + queueItem.total = match.Groups["total"].Value; + queueItem.uid = match.Groups["uid"].Value; + queueList.Add(queueItem); + } + return queueList; + } + private void showHistory(){ + try{ + if(isLoggedInToSab() ==false){ + SabLogin(); + } + String url = BuildSabUrl(_SabNzbHistoryUrl); + getHtml(url,ref _SabLoginCookies); + + }catch(Exception e){ + + Log.Error(e); + + } + } + private void searchNewzbin(String area){ + //prompt for query string + String q = "test"; + + if(isLoggedInToNewzbin() ==false){ + NewzbinLogin(); + } + String url = _NewzbinBaseUrl+String.Format(_NewzbinSearchUrl,q,_AreaEverything); + + String rss = getHtml(url,ref _NewzbinLoginCookies); + + + } + private bool SabLogin(){ + if(String.IsNullOrEmpty(_SabNzbUser)){ + return true; + } + String url = BuildSabUrl(_SabNzbContext); + CookieCollection cookies = new CookieCollection(); + if(_SabLoginCookies!=null){ + cookies.Add(_SabLoginCookies); + } + String postData = ""; + String lsResult = getHtml(url,_SabNzbUser,_SabNzbPass,postData,ref cookies); + if(lsResult.IndexOf("<title>Login</title>")>-1){ + _SabLoginCookies = cookies; + return true; + } + return false; + + } + private bool NewzbinLogin(){ + return NewzbinLogin("/"); + } + private bool NewzbinLogin(String nextUrl){ + if(String.IsNullOrEmpty(_NewzbinUser) || String.IsNullOrEmpty(_NewzbinPass)){ + return false; + } + String url = _NewzbinBaseUrl+_NewzbinLoginUrl; + String Postdata = "username={0}&password={1}&ret_url={2}&Submit=Login"; + CookieCollection cookies = new CookieCollection(); + if(_NewzbinLoginCookies!=null){ + cookies.Add(_NewzbinLoginCookies); + } + String lsResult = getHtml(url,_NewzbinUser,_NewzbinPass,Postdata,ref cookies); + if(lsResult.IndexOf("<a title=\"Log Out\" href=\"/account/logout/\">Log Out</a>")>-1){ + _NewzbinLoginCookies = cookies; + return true; + } + return false; + } + private String getHtml(String url,ref CookieCollection cookies){ + return getHtml(url,"","","",ref cookies); + } + private String getHtml(String url,String fsUser,String fsPassword,String fsPostData,ref CookieCollection cookies){ + HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url); + Request.Method = "POST"; + Request.ContentType = "application/x-www-form-urlencoded"; + Request.CookieContainer = new CookieContainer(); + Request.CookieContainer.Add(cookies); + + Stream RequestStream = Request.GetRequestStream(); + ASCIIEncoding ASCIIEncoding = new ASCIIEncoding(); + //Byte [] PostData = ASCIIEncoding.GetBytes("username=" + fsUser +"&password="+ fsPassword); + Byte [] PostData = ASCIIEncoding.GetBytes(fsPostData); + RequestStream.Write(PostData, 0, PostData.Length); + RequestStream.Close(); + HttpWebResponse response = (HttpWebResponse)Request.GetResponse(); + StreamReader Reader = new StreamReader(Request.GetResponse().GetResponseStream()); + String ResultHTML = Reader.ReadToEnd(); + response.Cookies = Request.CookieContainer.GetCookies(Request.RequestUri); + cookies = response.Cookies; + + return ResultHTML; + } + private bool isLoggedInToSab(){ + return _SabLoginCookies!=null && _SabLoginCookies["session_id"]!=null&&!_SabLoginCookies["session_id"].Expired ; + } + + private bool isLoggedInToNewzbin(){ + return _NewzbinLoginCookies!=null && _NewzbinLoginCookies["NzbSessionID"]!=null&&!_SabLoginCookies["NzbSessionID"].Expired ; + } + + + private String BuildSabUrl(String relativeUrl){ + + String url = String.Format("http://{0}:{1}{2}",_SabNzbHost,_SabNzbPort,relativeUrl); + return url; + + + } + public void parseNewzbinRss(String rssData){ + StringReader reader = new StringReader(rssData); + + XmlDocument doc = new XmlDocument(); + doc.Load(reader); + XmlNamespaceManager expr = new XmlNamespaceManager(doc.NameTable); + expr.AddNamespace("report=","http://www.newzbin.com/DTD/2007/feeds/report/"); + //Create the root XmlNode and generate an XmlNodeList from it. + XmlNode root = doc.SelectSingleNode("//rss/channel/item", expr); + XmlNodeList nodeList; + nodeList = root.SelectNodes("//rss/channel/item"); + //XmlAttributeCollection ac; + List<NzbReport> loRssItemList = new List<NzbReport>(); + NzbReport loRssItem; + //GUIListItem loListItem; + foreach (XmlNode chileNode in nodeList) + { + loRssItem = new NzbReport(); + + for (int i = 0; i < chileNode.ChildNodes.Count; i++) + { + XmlNode n = chileNode.ChildNodes[i]; + + switch (n.Name) + { + + case "title": + loRssItem.title = n.InnerText; + break; + case "link": + loRssItem.url = n.InnerText; + break; + case "report:id": + loRssItem.id = n.InnerText; + break; + case "report:moreinfo": + loRssItem.moreInfoUrl = n.InnerText; + break; + case "report:nfo": + loRssItem.url = n.InnerText; + break; + case "report:size": + loRssItem.size = n.InnerText; + break; + } + loRssItemList.Add(loRssItem); + } + } + } + #endregion + } +} Added: trunk/plugins/SabNzbControl/Runner/AssemblyInfo.cs =================================================================== --- trunk/plugins/SabNzbControl/Runner/AssemblyInfo.cs (rev 0) +++ trunk/plugins/SabNzbControl/Runner/AssemblyInfo.cs 2007-07-19 00:30:46 UTC (rev 745) @@ -0,0 +1,31 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("Runner")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Runner")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. +[assembly: ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("1.0.*")] Added: trunk/plugins/SabNzbControl/Runner/Main.cs =================================================================== --- trunk/plugins/SabNzbControl/Runner/Main.cs (rev 0) +++ trunk/plugins/SabNzbControl/Runner/Main.cs 2007-07-19 00:30:46 UTC (rev 745) @@ -0,0 +1,21 @@ +/* + * Created by SharpDevelop. + * User: GZamor1 + * Date: 4/23/2007 + * Time: 9:30 AM + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using System.Collections.Generic; + +namespace Runner +{ + class MainClass + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} \ No newline at end of file Added: trunk/plugins/SabNzbControl/Runner/Runner.csproj =================================================================== --- trunk/plugins/SabNzbControl/Runner/Runner.csproj (rev 0) +++ trunk/plugins/SabNzbControl/Runner/Runner.csproj 2007-07-19 00:30:46 UTC (rev 745) @@ -0,0 +1,34 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <ProjectGuid>{3344BB6A-77FC-449B-AADA-2C73E8045773}</ProjectGuid> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <OutputType>Exe</OutputType> + <RootNamespace>Runner</RootNamespace> + <AssemblyName>Runner</AssemblyName> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> + <OutputPath>bin\Debug\</OutputPath> + <DebugSymbols>True</DebugSymbols> + <DebugType>Full</DebugType> + <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> + <DefineConstants>DEBUG;TRACE</DefineConstants> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> + <OutputPath>bin\Release\</OutputPath> + <DebugSymbols>False</DebugSymbols> + <DebugType>None</DebugType> + <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> + <DefineConstants>TRACE</DefineConstants> + </PropertyGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="AssemblyInfo.cs" /> + <Compile Include="Main.cs" /> + </ItemGroup> +</Project> \ No newline at end of file Added: trunk/plugins/SabNzbControl/Runner/Runner.sln =================================================================== --- trunk/plugins/SabNzbControl/Runner/Runner.sln (rev 0) +++ trunk/plugins/SabNzbControl/Runner/Runner.sln 2007-07-19 00:30:46 UTC (rev 745) @@ -0,0 +1,18 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +# SharpDevelop 2.1.0.2429 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Runner", "Runner.csproj", "{3344BB6A-77FC-449B-AADA-2C73E8045773}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3344BB6A-77FC-449B-AADA-2C73E8045773}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3344BB6A-77FC-449B-AADA-2C73E8045773}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3344BB6A-77FC-449B-AADA-2C73E8045773}.Release|Any CPU.Build.0 = Release|Any CPU + {3344BB6A-77FC-449B-AADA-2C73E8045773}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection +EndGlobal Added: trunk/plugins/SabNzbControl/SabNzbControl.csproj =================================================================== --- trunk/plugins/SabNzbControl/SabNzbControl.csproj (rev 0) +++ trunk/plugins/SabNzbControl/SabNzbControl.csproj 2007-07-19 00:30:46 UTC (rev 745) @@ -0,0 +1,41 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <ProjectGuid>{4AD8C154-32DC-46FF-AE56-8EBF39948EF3}</ProjectGuid> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <OutputType>Library</OutputType> + <RootNamespace>SabNzbControl</RootNamespace> + <AssemblyName>SabNzbControl</AssemblyName> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> + <OutputPath>bin\Debug\</OutputPath> + <DebugSymbols>True</DebugSymbols> + <DebugType>Full</DebugType> + <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> + <DefineConstants>DEBUG;TRACE</DefineConstants> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> + <OutputPath>bin\Release\</OutputPath> + <DebugSymbols>False</DebugSymbols> + <DebugType>None</DebugType> + <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> + <DefineConstants>TRACE</DefineConstants> + </PropertyGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> + <ItemGroup> + <Reference Include="Core"> + <HintPath>..\..\MediaPortal\Core\bin\Release\Core.DLL</HintPath> + <SpecificVersion>False</SpecificVersion> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Xml" /> + <Reference Include="Utils"> + <HintPath>..\..\MediaPortal\Utils\bin\Release\Utils.DLL</HintPath> + <SpecificVersion>False</SpecificVersion> + </Reference> + </ItemGroup> + <ItemGroup> + <Compile Include="AssemblyInfo.cs" /> + <Compile Include="MyClass.cs" /> + </ItemGroup> +</Project> \ No newline at end of file Added: trunk/plugins/SabNzbControl/SabNzbControl.sln =================================================================== --- trunk/plugins/SabNzbControl/SabNzbControl.sln (rev 0) +++ trunk/plugins/SabNzbControl/SabNzbControl.sln 2007-07-19 00:30:46 UTC (rev 745) @@ -0,0 +1,18 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +# SharpDevelop 2.1.0.2429 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabNzbControl", "SabNzbControl.csproj", "{4AD8C154-32DC-46FF-AE56-8EBF39948EF3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4AD8C154-32DC-46FF-AE56-8EBF39948EF3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4AD8C154-32DC-46FF-AE56-8EBF39948EF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4AD8C154-32DC-46FF-AE56-8EBF39948EF3}.Release|Any CPU.Build.0 = Release|Any CPU + {4AD8C154-32DC-46FF-AE56-8EBF39948EF3}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection +EndGlobal Added: trunk/plugins/SabNzbControl/bin/Debug/Core.DLL =================================================================== (Binary files differ) Property changes on: trunk/plugins/SabNzbControl/bin/Debug/Core.DLL ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/plugins/SabNzbControl/bin/Debug/SabNzbControl.dll =================================================================== (Binary files differ) Property changes on: trunk/plugins/SabNzbControl/bin/Debug/SabNzbControl.dll ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/plugins/SabNzbControl/bin/Debug/SabNzbControl.pdb =================================================================== (Binary files differ) Property changes on: trunk/plugins/SabNzbControl/bin/Debug/SabNzbControl.pdb ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/plugins/SabNzbControl/bin/Debug/Utils.DLL =================================================================== (Binary files differ) Property changes on: trunk/plugins/SabNzbControl/bin/Debug/Utils.DLL ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/plugins/SabNzbControl/obj/Debug/SabNzbControl.dll =================================================================== (Binary files differ) Property changes on: trunk/plugins/SabNzbControl/obj/Debug/SabNzbControl.dll ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/plugins/SabNzbControl/obj/Debug/SabNzbControl.pdb =================================================================== (Binary files differ) Property changes on: trunk/plugins/SabNzbControl/obj/Debug/SabNzbControl.pdb ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/plugins/SabNzbControl/obj/SabNzbControl.csproj.FileList.txt =================================================================== --- trunk/plugins/SabNzbControl/obj/SabNzbControl.csproj.FileList.txt (rev 0) +++ trunk/plugins/SabNzbControl/obj/SabNzbControl.csproj.FileList.txt 2007-07-19 00:30:46 UTC (rev 745) @@ -0,0 +1,7 @@ +obj\Debug\ResolveAssemblyReference.cache +bin\Debug\SabNzbControl.dll +bin\Debug\SabNzbControl.pdb +bin\Debug\Core.DLL +bin\Debug\Utils.DLL +obj\Debug\SabNzbControl.dll +obj\Debug\SabNzbControl.pdb This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |