예제 #1
0
        static public TorrentLabel Ask()
        {
            TorrentLabel  selected = new TorrentLabel();
            GUIDialogMenu dlgMenu  = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlgMenu == null)
            {
                return(null);
            }

            dlgMenu.Reset();
            dlgMenu.SetHeading("Under which label?");
            foreach (TorrentLabel label in TorrentEngine.Instance().TorrentSession.Labels)
            {
                GUIListItem listItem = new GUIListItem();
                listItem.Label        = label.Name == "" ? "No label" : label.Name;
                listItem.AlbumInfoTag = label;
                dlgMenu.Add(listItem);
            }
            dlgMenu.DoModal(GUIWindowManager.ActiveWindow);
            if (dlgMenu.SelectedLabel == -1)
            {
                return(null);
            }
            selected.Name = dlgMenu.SelectedLabelText;
            return(selected);
        }
예제 #2
0
        protected override void OnPageLoad()
        {
            if (!TorrentEngine.Instance().IsConnected)
            {
                Log.Instance().Print("IsConnected = false");
                DisplayError("Unable to connect", "Connection error. Torrent functionality disabled.");
            }

            ListType           = "Torrents";
            TorrentView        = Configuration.Instance().Settings["TorrentView"] as string;
            SortOrder          = Configuration.Instance().Settings["SortOrder"] as string;
            FolderList.Visible = false;
            TorrentEngine.Instance().TorrentsUpdated += new TorrentsUpdated(_TorrentsUpdated);


            UpdateScreen();
            GUIPropertyManager.SetProperty("#MyTorrents.SeriesInfo", "no");
            GUIPropertyManager.SetProperty("#MyTorrents.TorrentDetails.Visible", "no");
            GUIPropertyManager.SetProperty("#MyTorrents.FolderBrowser.Visible", "no");
            GUIPropertyManager.SetProperty("#currentmodule", Configuration.Instance().Settings["Torrent.PluginName"] as string);
            GUIPropertyManager.SetProperty("#MyTorrents.Backdrop", "");
            base.OnPageLoad();
            if (_loadParameter != null)
            {
                ViewSearch.StartParametricSearch(_loadParameter);
                ListType = "Search";
                UnfocusMenu();
                GiveFocus(torrentList);
            }
        }
예제 #3
0
        public void StartSearch()
        {
            MyTorrents.Instance().torrentList.Visible = false;
            TorrentEngine.Instance().SearchCompleted += new SearchCompleted(_torrentEngine_SearchCompleted);
            VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD);

            keyboard.Reset();

            keyboard.Text = SearchString == null ? "" : SearchString;
            keyboard.DoModal(GUIWindowManager.ActiveWindow);

            if (!keyboard.IsConfirmed)
            {
                MyTorrents.Instance().torrentList.Visible = true;
                MyTorrents.ListType = "Torrents";
                return;
            }

            SearchString = keyboard.Text;

            GUIDialogMenu dlgMenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlgMenu == null)
            {
                return;
            }

            dlgMenu.Reset();

            dlgMenu.SetHeading("Which engine to use?");
            TorrentSearchEngine tse = null;

            try
            {
                tse = new TorrentSearchEngine(Configuration.Instance().Settings["TorrentSearch.Config"] as string);
            }
            catch
            {
                Log.Instance().Print("MyTorrents.xml config file loading failed!");
            }
            foreach (ITorrentSearch engine in tse.Engines)
            {
                GUIListItem listItem = new GUIListItem();
                listItem.Label = engine.Name;
                dlgMenu.Add(listItem);
            }
            dlgMenu.DoModal(GUIWindowManager.ActiveWindow);
            if (dlgMenu.SelectedLabel == -1)
            {
                MyTorrents.Instance().torrentList.Visible = true;
                MyTorrents.ListType = "Torrents";
                return;
            }
            _searchEngine = tse.Engines[dlgMenu.SelectedLabel];
            MyTorrents.Instance().torrentList.Clear();
            MyTorrents.Instance().torrentList.Visible = true;
            MyTorrents.Instance().torrentList.ListItems = SearchResults;

            UpdateSearchResults("Default");//
        }
예제 #4
0
        public void RSSDownload(RSSItem item)
        {
            GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

            dlg.SetHeading("Download this torrent?");

            dlg.SetLine(1, item.Title);

            dlg.DoModal(GUIWindowManager.ActiveWindow);

            if (!dlg.IsConfirmed)
            {
                return;
            }

            TorrentLabel label = DialogAskLabel.Ask();

            if (label != null)
            {
                bool ok = TorrentEngine.Instance().StartDownloading(item.Link, label.Name, true, "", "0", "", "");
                if (!ok)
                {
                    GUIDialogNotify notify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                    notify.Reset();
                    notify.SetHeading("Failed!");
                    notify.SetText("Unable to start download.");
                    notify.DoModal(GUIWindowManager.ActiveWindow);
                }
            }
        }
예제 #5
0
        //private bool _isLoading;

        private bool EstablishConnection(ConfigData _config)
        {
            bool result = TorrentEngine.Initialize(_config.Server, Convert.ToInt32(_config.Port), _config.User, _config.Password, _config.Backend);

            //TorrentEngine.Instance().TorrentsUpdated += new TorrentsUpdated(_TorrentsUpdated);
            DisplayTorrents(new List <Torrent>());
            return(result);
        }
예제 #6
0
        protected Notifier()
        {
            TorrentEngine _torrentEngine = TorrentEngine.Instance();

            _torrentEngine.TorrentAdded     += new TorrentAdded(_torrentSession_TorrentAdded);
            _torrentEngine.TorrentRemoved   += new TorrentRemoved(_torrentSession_TorrentRemoved);
            _torrentEngine.TorrentCompleted += new TorrentCompleted(_torrentSession_TorrentCompleted);
        }
예제 #7
0
        private void DownloadTorrent(RSSItem rssItem, string label)
        {
            bool started = TorrentEngine.Instance().StartDownloading(rssItem.Link, label, false, "", "0", "", "");

            if (!started)
            {
                Log.Instance().Print(string.Format("Could not start downloading {0}.", rssItem.Link));
            }
        }
예제 #8
0
        private void DisplayTorrents(List <Torrent> TorrentsAll)
        {
            long   downloadSpeed  = 0;
            int    downs          = 0;
            long   uploadSpeed    = 0;
            long   seeding        = 0;
            double avgProgress    = 0.0;
            int    unfinished     = 0;
            int    ActiveTorrents = 0;

            foreach (Torrent torrent in TorrentsAll)
            {
                if (torrent.Started())
                {
                    if (torrent.DownloadSpeed > 0 || torrent.UploadSpeed > 0)
                    {
                        ActiveTorrents++;
                    }

                    downloadSpeed += torrent.DownloadSpeed;
                    uploadSpeed   += torrent.UploadSpeed;

                    if (torrent.Progress >= 100)
                    {
                        //only seeding
                        seeding = seeding + 1;
                    }
                    else
                    {
                        downs++;
                    }
                }

                if (torrent.Progress < 100.0)
                {
                    avgProgress += torrent.Progress;
                    unfinished  += 1;
                }
            }
            UpdateScreen();
            GUIPropertyManager.SetProperty("#MyTorrents.IsConnected", TorrentEngine.Instance().IsConnected.ToString());
            GUIPropertyManager.SetProperty("#MyTorrents.CombinedDownloadSpeed", UnitConvert.TransferSpeedToString(downloadSpeed));
            GUIPropertyManager.SetProperty("#MyTorrents.CombinedUploadSpeed", UnitConvert.TransferSpeedToString(uploadSpeed));
            GUIPropertyManager.SetProperty("#MyTorrents.Downloads.Count", string.Format("{0}", downs));
            GUIPropertyManager.SetProperty("#MyTorrents.Uploads.Count", string.Format("{0}", seeding));
            GUIPropertyManager.SetProperty("#MyTorrents.Active.Count", string.Format("{0}", ActiveTorrents));

            //GUIPropertyManager.SetProperty("#MyTorrents.Ready.Count", string.Format("{0}", TorrentsAll.Count - TorrentsActive.Count));
            //GUIPropertyManager.SetProperty("#MyTorrents.Unfinished.Count", string.Format("{0}", unfinished));
            //GUIPropertyManager.SetProperty("#MyTorrents.AverageProgressOfUnfinished", string.Format("{0:F2}", avgProgress / unfinished));
            if (Notifier.Instance() != null && Notifier.Instance().IsNotificationBarAvailable() && (_config.Notify))
            {
                Notifier.Instance().ChangeText();
            }
        }
예제 #9
0
        public void SortButtonHandler()
        {
            GUIDialogMenu dlog = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlog == null)
            {
                return;
            }
            dlog.Reset();
            dlog.SetHeading("Choose sort order");
            dlog.Add("Default");
            dlog.Add("By Name ASC");
            dlog.Add("By Name DESC");
            dlog.Add("By Size ASC");
            dlog.Add("By Size DESC");
            if (TorrentEngine.Instance().TorrentsAll[0].AddedOn != 0)
            {
                dlog.Add("By Date Added ASC");
                dlog.Add("By Date Added DESC");
            }
            dlog.DoModal(GUIWindowManager.ActiveWindow);

            switch (dlog.SelectedLabelText)
            {
            case "Default":
                MyTorrents.SortOrder = "Default";
                break;

            case "By Name ASC":
                MyTorrents.SortOrder = "Name ASC";
                break;

            case "By Name DESC":
                MyTorrents.SortOrder = "Name DESC";
                break;

            case "By Size ASC":
                MyTorrents.SortOrder = "Size ASC";
                break;

            case "By Size DESC":
                MyTorrents.SortOrder = "Size DESC";
                break;

            case "By Date Added ASC":
                MyTorrents.SortOrder = "Date Added ASC";
                break;

            case "By Date Added DESC":
                MyTorrents.SortOrder = "Date Added DESC";
                break;
            }
        }
예제 #10
0
        public void FolderClickMenu(GUIListItem fldr, GUIListItem _selectedtorrent, TorrentLabel label)
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }

            dlg.Reset();
            dlg.SetHeading("Folder Options");
            dlg.Add("Set as download location");
            //dlg.Add("Add to favourite places");
            dlg.DoModal(GUIWindowManager.ActiveWindow);

            switch (dlg.SelectedLabelText)
            {
            case "Set as download location":
            {
                MyTorrents.Instance().HideFolderBrowser();

                if (MyTorrents.ListType == "SeriesInfo")
                {
                    SeriesItem item = _selectedtorrent.AlbumInfoTag as SeriesItem;

                    MyTorrents.Instance()._torrentWatchlist.GetSeriesList().Where(e => e.show.ID == item.show.ID).First().folder = fldr.Path + @"\" + fldr.Label;
                    GUIPropertyManager.SetProperty("#MyTorrents.SeriesInfo.Folder", fldr.Path + @"\" + fldr.Label);
                }
                else
                {
                    DefaultDir = TorrentEngine.Instance().TorrentSession.GetSettings("dir_active_download");
                    string response  = TorrentEngine.Instance().TorrentSession.GetResponse(string.Format("?action=setsetting&s=dir_active_download&v={0}", fldr.Path + @"\" + fldr.Label));
                    string response2 = TorrentEngine.Instance().TorrentSession.GetResponse("?action=setsetting&s=dir_active_download_flag&v=1");
                    TorrentSearch.TorrentMatch match = _selectedtorrent.AlbumInfoTag as TorrentSearch.TorrentMatch;


                    bool ok = TorrentEngine.Instance().StartDownloading(match.Url, label.Name, true, match.cookie, match.Id, _downloadoption, "");
                    if (!ok)
                    {
                        GUIDialogNotify notify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                        notify.Reset();
                        notify.SetHeading("Failed!");
                        notify.SetText("Unable to start download.");
                        notify.DoModal(GUIWindowManager.ActiveWindow);
                    }
                    string revert = TorrentEngine.Instance().TorrentSession.GetResponse(string.Format("?action=setsetting&s=dir_active_download&v={0}", DefaultDir));
                }
                break;
            }
            }
        }
예제 #11
0
        public void UpdateSearchResults(string sortOrder)
        {
            GUIDialogProgress dlg = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);

            dlg.Reset();
            dlg.SetHeading("Torrents");
            dlg.SetLine(1, "Fetching torrents...");
            dlg.SetPercentage(0);
            dlg.ShowProgressBar(true);
            dlg.StartModal(GUIWindowManager.ActiveWindow);

            _progressDlg = new ProgressUpdater();
            _progressDlg.SetAutoUpdate(1000, 20);

            TorrentEngine.Instance().SearchTorrent(_searchEngine.Name, _searchString, sortOrder, dlg);
        }
예제 #12
0
 public static bool Initialize(string host, int port, string username, string password, Backend backend)
 {
     try
     {
         _instance = new TorrentEngine(host, port, username, password, backend);
         _instance._torrentSession.Connect();
         _instance.IsConnected = true;
         Log.Instance().Print("instance connected");
         return(true);
     }
     catch (Exception ex)
     {
         Log.Instance().Print("Could not connect to " + host + ":" + port);
         _instance.IsConnected = false;
         return(false);
     }
 }
예제 #13
0
        void GUIWindowManager_OnActivateWindow(int windowId)
        {
            int[] windowIds = { 5680, 5679, 5678, 5681, 5682, 5683, 5684, 5685, 7658 };

            if (!windowIds.Contains(windowId))
            {
                //Another Window
                BackId = windowId;  //Keep reference to it as if next window is MyTorrents, Back button will take us here
                if (TorrentEngine.Instance() != null)
                {
                    TorrentEngine.Instance().UpdateTimer = 1000.0 * (Double.Parse(Configuration.Instance().Settings["Torrent.Timer.Outside"].ToString()));
                }
            }
            else
            {
                TorrentEngine.Instance().UpdateTimer = 1000.0 * (Double.Parse(Configuration.Instance().Settings["Torrent.Timer.Inside"].ToString()));
            }
        }
예제 #14
0
        private void UpdateTorrentList(bool timed)
        {
            if (torrentList == null)
            {
                return;
            }
            List <GUIListItem> CurItems = new List <GUIListItem>(torrentList.ListItems);

            foreach (Torrent torrent in TorrentEngine.Instance().TorrentSession.TorrentsAll)
            {
                if (torrent.Progress < 100.0)
                {
                    GUIListItem item = FindItemByHash(torrentList, torrent);
                    if (item == null)
                    {
                        item = new GUIListItem(string.Format("{0}", Ellipsis(torrent.Name, 75)));
                        item.AlbumInfoTag = torrent;
                        torrentList.Add(item);
                    }
                    else
                    {
                        CurItems.Remove(item);
                    }
                    item.Label2 = string.Format("{0} ({1:F2}%)", UnitConvert.SizeToString(torrent.Size), torrent.Progress);
                    //item.Label3 = ((T.fETA == "-1s") || (T.fETA == "0s")) ? "" : T.fETA.ToLower();
                }
            }
            foreach (var i in CurItems)
            {
                torrentList.ListItems.Remove(i);
            }

            if (torrentList.ListItems.Count == 0)
            {
                GUIPropertyManager.SetProperty("#MyTorrents.Count", "0");
                GUIListItem item = new GUIListItem();
                item.Label = "No torrents.";
                torrentList.Add(item);
            }
            else
            {
                GUIPropertyManager.SetProperty("#MyTorrents.Count", String.Format("{0}", torrentList.ListItems.Count));
            }
        }
예제 #15
0
        public void LabelButtonHandler()
        {
            GUIDialogMenu dlog = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlog == null)
            {
                return;
            }
            dlog.Reset();
            dlog.SetHeading("Choose label");
            dlog.Add("None");
            dlog.Add("No Label");
            foreach (TorrentLabel label in TorrentEngine.Instance().TorrentSession.Labels)
            {
                if (label.Name == "")
                {
                    continue;
                }
                GUIListItem l = new GUIListItem();
                l.Label        = label.Name;
                l.AlbumInfoTag = label.Name;
                dlog.Add(l);
            }

            dlog.DoModal(GUIWindowManager.ActiveWindow);
            switch (dlog.SelectedId)
            {
            case -1:
                return;

            case 1:
                MyTorrents.LabelFilter = null;
                break;

            case 2:
                MyTorrents.LabelFilter = "";
                break;

            default:
                MyTorrents.LabelFilter = dlog.SelectedLabelText;
                break;
            }
        }
예제 #16
0
        public void ShowTorrents()
        {
            if (torrentList == null)
            {
                return;
            }
            List <GUIListItem> tl = new List <GUIListItem>();
            var TA = TorrentEngine.Instance().GetTorrents(TorrentView, SortOrder, LabelFilter);

            foreach (Torrent torrent in TA)
            {
                GUIListItem item = new GUIListItem(string.Format("{0}", Ellipsis(torrent.Name, 75)));
                //GUIImage image = new GUIImage(5678);
                //item.Icon = image;
                //item.IconImage = System.IO.Path.Combine(GUIGraphicsContext.Skin, @"\Media\icon_empty_focus1.png");
                item.AlbumInfoTag = torrent;
                tl.Add(item);

                if (item.Label2 != string.Format("{0} ({1:F2}%)", UnitConvert.SizeToString(torrent.Size), torrent.Progress))
                {
                    item.Label2 = string.Format("{0} ({1:F2}%)", UnitConvert.SizeToString(torrent.Size), torrent.Progress);
                }
            }

            torrentList.ListItems = tl;

            if (torrentList.ListItems.Count == 0)
            {
                GUIPropertyManager.SetProperty("#MyTorrents.Count", "0");
                GUIListItem item = new GUIListItem();
                item.Label = "No items.";
                torrentList.Add(item);
            }
            else
            {
                GUIPropertyManager.SetProperty("#MyTorrents.Count", String.Format("{0}", torrentList.ListItems.Count));
            }
        }
예제 #17
0
        public List <GUIListItem> GetTorrentDetails(Torrent utorrent)
        {
            List <GUIListItem> fileList = new List <GUIListItem>();

            SelectedHash = utorrent.Hash;
            if (utorrent == null)
            {
                //torrent got removed!
            }
            List <File> files = TorrentEngine.Instance().TorrentSession.GetFiles(utorrent.Hash);


            foreach (var file in files)
            {
                GUIListItem item = new GUIListItem();
                item.Label        = file.Filename;
                item.IconImage    = System.IO.Path.Combine(GUIGraphicsContext.Skin, @"\Media\icon_empty_focus1.png");
                item.AlbumInfoTag = file;
                fileList.Add(item);
                item.Label2 = string.Format("{0} ({1:F2}%)", UnitConvert.SizeToString(file.Filesize), (double)file.Downloaded / file.Filesize * 100.0);
            }


            GUIPropertyManager.SetProperty("#MyTorrents.Details.Name", utorrent.Name);
            GUIPropertyManager.SetProperty("#MyTorrents.Details.Progress", string.Format("{0:F2}", utorrent.Progress));
            GUIPropertyManager.SetProperty("#MyTorrents.Details.Ratio", string.Format("{0:F2}", (float)utorrent.Ratio * 0.001));
            GUIPropertyManager.SetProperty("#MyTorrents.Details.ETA", UnitConvert.TimeRemainingToString(utorrent.ETA));
            GUIPropertyManager.SetProperty("#MyTorrents.Details.UploadSpeed", UnitConvert.TransferSpeedToString(utorrent.UploadSpeed));
            GUIPropertyManager.SetProperty("#MyTorrents.Details.DownloadSpeed", UnitConvert.TransferSpeedToString(utorrent.DownloadSpeed));
            GUIPropertyManager.SetProperty("#MyTorrents.Details.Peers", string.Format("{0} ({1})", utorrent.PeersConnected, utorrent.PeersInSwarm));
            GUIPropertyManager.SetProperty("#MyTorrents.Details.Seeds", string.Format("{0} ({1})", utorrent.SeedsConnected, utorrent.SeedsInSwarm));
            GUIPropertyManager.SetProperty("#MyTorrents.Details.Size", UnitConvert.SizeToString(utorrent.Size));


            return(fileList);
        }
예제 #18
0
        protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
        {
            if (!TorrentEngine.Instance().IsConnected)
            {
                base.OnClicked(controlId, control, actionType);
                return;
            }
            if (controlId > 201 && controlId < 208 && controlId == 210)
            {
                GiveFocus(torrentList);
            }

            switch (control.GetID)
            {
            case 202:     //button_SwitchView
                UnfocusMenu();
                ViewTorrents.ViewButtonHandler();
                GiveFocus(torrentList);

                UpdateScreen();
                break;

            case 203:     //button_Sort
                UnfocusMenu();
                ViewTorrents.SortButtonHandler();
                GiveFocus(torrentList);

                UpdateScreen();
                break;

            case 204:     //button_SearchTorrents
                ListType = "Search";
                UnfocusMenu();
                ShowSearch();
                GiveFocus(torrentList);

                break;

            case 205:     //button_watchItemList
                ListType = "WatchList";
                UnfocusMenu();
                ShowTorrentWatch();
                GiveFocus(torrentList);
                break;

            case 206:     //button_RSS
                ListType = "RSS";
                UnfocusMenu();
                UpdateScreen();
                GiveFocus(torrentList);

                RSSChannelManager.Instance().UpdateChannels(true);
                break;

            case 207:     //button_Log
                ListType = "Log";
                ShowLog();
                UnfocusMenu();
                GiveFocus(torrentList);

                break;

            case 209:     //button_Settings
                //List<UTorrentSettings> settings = TorrentEngine.Instance().TorrentSession.GetSettings();
                break;

            case 210:     //button_Labels
                ViewTorrents.LabelButtonHandler();
                UnfocusMenu();
                GiveFocus(torrentList);
                UpdateScreen();
                break;

            case 208:     //TorrentList
                if (actionType == MediaPortal.GUI.Library.Action.ActionType.ACTION_SELECT_ITEM)
                {
                    switch (ListType)
                    {
                    case "Torrents":
                        Torrent torrent = torrentList.SelectedListItem.AlbumInfoTag as Torrent;
                        if (torrent != null)
                        {
                            ListType = "TorrentDetails";
                            UpdateScreen();
                        }
                        break;

                    case "Search":
                        ViewSearch.SearchItemClicked(torrentList.SelectedListItem.AlbumInfoTag as TorrentSearch.TorrentMatch);
                        break;

                    case "SelectedRSS":
                        ViewRSS.RSSDownload(torrentList.SelectedListItem.AlbumInfoTag as RSSItem);
                        break;

                    case "RSS":
                        ListType = "SelectedRSS";
                        ViewRSS.ShowSelectedRSS(torrentList.SelectedListItem.AlbumInfoTag as IRSSChannel);
                        UpdateScreen();
                        break;

                    case "WatchList":
                        ListType = "SeriesInfo";
                        UnfocusMenu();
                        torrentList.Visible = false;
                        GiveFocus(button_Quality);
                        ViewAutoGrabber.ShowSeries(torrentList.SelectedListItem.AlbumInfoTag);
                        button_IncludeSpecials.Selected  = (torrentList.SelectedListItem.AlbumInfoTag as SeriesItem).includespecials;
                        button_IncludeSpecials.IsFocused = false;
                        break;
                    }
                }
                break;

            case 501:     //FolderList
                if (actionType == MediaPortal.GUI.Library.Action.ActionType.ACTION_SELECT_ITEM)
                {
                    if (!FolderList.SelectedListItem.Selected)
                    {
                        FolderList.ListItems             = ViewFolders.GetGUIFolders(FolderList.SelectedListItem);
                        FolderList.SelectedListItemIndex = 0;
                    }
                    else
                    {
                        ViewFolders.FolderClickMenu(FolderList.SelectedListItem, torrentList.SelectedListItem, ViewSearch.label);
                    }
                }
                break;

            case 502:     //FileList
                if (ListType == "TorrentDetails")
                {
                    lock (UpdateLocker)
                    {
                        int  index        = FileList.SelectedListItemIndex;
                        File selectedfile = FileList.SelectedListItem.AlbumInfoTag as File;
                        ViewDetails.TorrentDetailsOnClick(selectedfile, index);
                    }
                }
                break;

            case 302:
            case 303:
            case 304:
            case 305:
            case 306:
            case 307:
                ViewAutoGrabber.OnClicked(control);
                break;
            }

            base.OnClicked(controlId, control, actionType);
        }
예제 #19
0
        public void SearchItemClicked(TorrentMatch match)
        {
            GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

            dlg.SetHeading("Download this torrent?");
            dlg.SetLine(1, match.Title);
            dlg.SetLine(2, UnitConvert.SizeToString(match.Size));
            //dlg.SetLine(3, item.Label3);

            dlg.DoModal(GUIWindowManager.ActiveWindow);

            if (!dlg.IsConfirmed)
            {
                return;
            }

            label = DialogAskLabel.Ask();
            if (label == null)
            {
                return;
            }
            Log.Instance().Print("label is " + label.Name);
            List <DownloadDir> predefined = TorrentEngine.Instance().TorrentSession.ListDirs();

            if (predefined == null)
            {
                //MyTorrents.Instance().DisplayError("Unable to connect", "Connection error. Please open your Torrent client before retrying.");
                //return;
            }
            GUIDialogMenu chooser = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (chooser == null)
            {
                return;
            }

            chooser.Reset();
            chooser.SetHeading("Download options");
            chooser.Add("No change");
            //foreach (DownloadDir dir in predefined)
            //{
            //    GUIListItem element = new GUIListItem();
            //    element.Label = dir.path;
            //    element.Label2 = String.Format("{0} MB Free", Convert.ToString(dir.available));
            //    chooser.Add(element);
            //}

            chooser.Add("Browse Folders");

            chooser.DoModal(GUIWindowManager.ActiveWindow);
            if (chooser.SelectedId == -1)
            {
                return;
            }

            int    selecteddirId = chooser.SelectedId;
            string selectedText  = chooser.SelectedLabelText;

            Log.Instance().Print("download option is " + selectedText);
            bool ok = false;
            // KAT hack
            string dowOption = "";

            if (_searchEngine.GetType() == typeof(TorrentSearch_Combiner))
            {
                Log.Instance().Print("Selected engine is Combiner");
                TorrentSearch_Combiner _eng = (TorrentSearch_Combiner)_searchEngine;
                if (_searchEngine.Parameters.ContainsKey("Options"))
                {
                    dowOption = _eng.Engines.Where(e => e.Name == match.tracker).First().Parameters["Options"].ToString().Replace("%id%", match.Id);
                }
            }
            else
            {
                if (_searchEngine.Parameters.ContainsKey("Options"))
                {
                    dowOption = _searchEngine.Parameters["Options"].ToString().Replace("%id%", match.Id);
                }
            }

            switch (selectedText)
            {
            case "Browse Folders":

                //FolderBrowser ViewFolders = new FolderBrowser(TorrentEngine.Instance().TorrentSession, label, match, dowOption);
                Log.Instance().Print("Loading file browser");
                MyTorrents.ListType = "FolderBrowser";
                MyTorrents.Instance().ShowFolderBrowser();
                break;

            case "No change":

                if (label != null)
                {
                    Log.Instance().Print("Starting torrent file downloading");

                    ok = TorrentEngine.Instance().StartDownloading(match.Url, label.Name, true, match.cookie, match.Id, dowOption, "");
                }
                break;

            default:

                if (label != null)
                {
                    Log.Instance().Print("Starting torrent file downloading");
                    ok = TorrentEngine.Instance().StartDownloading(match.Url, label.Name, true, match.cookie, match.Id, dowOption, String.Format("&download_dir={0}", selecteddirId - 2));
                }
                break;
            }

            /*
             * if (!ok)
             * {
             *  GUIDialogNotify notify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
             *  notify.Reset();
             *  notify.SetHeading("Failed!");
             *  notify.SetText("Unable to start download.");
             *  notify.DoModal(GUIWindowManager.ActiveWindow);
             *
             *  Log.Instance().Print("Downloading failed");
             * }
             * */
        }
예제 #20
0
 protected override void OnPageDestroy(int new_windowId)
 {
     TorrentEngine.Instance().TorrentsUpdated -= new TorrentsUpdated(_TorrentsUpdated);
     base.OnPageDestroy(new_windowId);
 }
예제 #21
0
 private void _TorrentsUpdated()
 {
     DisplayTorrents(TorrentEngine.Instance().TorrentsAll);
 }
예제 #22
0
        public virtual void DoSearch()
        {
            Thread AutoSearch = new Thread(delegate()
            {
                try
                {
                    Log.Instance().Print(string.Format("Automatic search started [{0}]", this.show.Name));
                    Log.Instance().Print(string.Format("Unlocal Episodes [{0}]", this.show.AllUnlocal));
                    Log.Instance().Print(string.Format("Next unlocal Episode [{0}]", this.show.FirstUnlocal));

                    TorrentSearchEngine tse = new TorrentSearchEngine(Configuration.Instance().Settings["TorrentSearch.Config"] as string);
                    var watch = this;
                    ITorrentSearch _searchEngine = tse.Engines.Where(e => e.Name == watch.tracker).First();
                    string CleanTitle            = Regex.Replace(watch.show.OriginalName, "[^0-9a-zA-Z ]+", "");
                    TorrentMatchList matchlist   = _searchEngine.Search(CleanTitle, "Default", null);
                    Log.Instance().Print(string.Format("Search {0} on {1} Sort {2} Count {3}", CleanTitle, _searchEngine.Name, "Default", matchlist.Count));
                    switch (watch.type)
                    {
                    case "New episodes":
                        int t = 0;
                        Log.Instance().Print(string.Format("Searching for episode [{0}]", this.show.FirstUnlocal));
                        foreach (TorrentMatch m in matchlist)
                        {
                            if (m.Title.IndexOf(watch.show.FirstUnlocal) != -1 && m.Title.IndexOf(watch.quality) != -1 && m.Title.IndexOf(watch.source) != -1)
                            {
                                t++;
                                Log.Instance().Print(string.Format("Match {0}", m.Title));
                                bool ok = TorrentEngine.Instance().StartDownloading(m.Url, "", true, m.cookie, m.Id, "", "", watch.folder);
                            }
                        }
                        Log.Instance().Print(string.Format("[{0}] matches found", t));
                        break;

                    case "Missing episodes":
                        IEnumerable <string> eps = watch.show.AllUnlocal.Split('|').ToList();
                        eps     = (watch.includespecials ? eps : eps.Where(e => e.StartsWith("S00") == false).ToList());
                        var ccc = (from m in matchlist from ep in eps where m.Title.Contains(ep) select m).ToList();
                        foreach (TorrentMatch m in matchlist)
                        {
                            foreach (string ep in eps)
                            {
                                int y = 0;
                                Log.Instance().Print(string.Format("Searching for episode [{0}]", ep));
                                if (m.Title.Contains(ep) && m.Title.IndexOf(watch.quality) != -1 && m.Title.IndexOf(watch.source) != -1)
                                {
                                    y++;
                                    Log.Instance().Print(string.Format("Match {0}", m.Title));
                                    bool ok = TorrentEngine.Instance().StartDownloading(m.Url, "", true, m.cookie, m.Id, "", "", watch.folder);
                                }
                                Log.Instance().Print(string.Format("[{0}] matches found for episodes [{1}]", y, m.Title));
                            }
                        }
                        break;
                    }
                }
                catch { }
            })
            {
                IsBackground = true,
                Name         = "MyTorrents Autograbber"
            };

            AutoSearch.Start();
        }
예제 #23
0
        public void TorrentDetailsOnClick(File file, int FileIndex)
        {
            Torrent torrent = TorrentEngine.Instance().TorrentByHash(SelectedHash);

            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }
            dlg.Reset();
            dlg.SetHeading("File menu");
            Dictionary <string, int> prios = TorrentEngine.Instance().TorrentSession.FillPriorities();

            foreach (KeyValuePair <string, int> pair in prios)
            {
                if (file.Priority != pair.Value)
                {
                    if (pair.Key != "Do Not Download")
                    {
                        dlg.Add(string.Format("Set {0} Priority", pair.Key));
                    }
                    else
                    {
                        dlg.Add("Do Not Download");
                    }
                }
            }

            if (torrent.TorrentSavePath != null && file.Downloaded == file.Filesize && ValidateExtension(file.Filename))
            {
                dlg.Add("Play File");
            }
            if (torrent.StreamID != null)
            {
                dlg.Add("Stream File");
            }

            dlg.DoModal(GUIWindowManager.ActiveWindow);

            if (dlg.SelectedLabelText.IndexOf("Priority") != -1)
            {
                file.SetFilePriority(SelectedHash, FileIndex, prios[dlg.SelectedLabelText.Replace("Set", "").Replace(" Priority", "")]);
            }
            switch (dlg.SelectedLabelText)
            {
            case "Do Not Download":
            {
                file.SetFilePriority(SelectedHash, FileIndex, prios[dlg.SelectedLabelText]);
                break;
            };

            case "Play File":
            {
                g_Player.PlayBackEnded   += new g_Player.EndedHandler(OnPlayBackEnded);
                g_Player.PlayBackStopped += new g_Player.StoppedHandler(OnPlayBackStopped);
                g_Player.Play(System.IO.Path.Combine(torrent.TorrentSavePath, file.Filename));
                if (Utils.VideoExtensions.Contains(GetExtension(file.Filename)))
                {
                    g_Player.ShowFullScreenWindow();
                }
                break;
            };
                //case "Stream File":
                // {
                ////http://edalex.dydns.tv:8080/proxy?sid=8BE26CDB&file=0
                //string ClientLink = (TorrentEngine.Instance().TorrentSession as ITorrentClient).FullUrlWithAuth;
                //string FileLink = string.Format("{0}proxy?sid={1}&file={2}", ClientLink, torrent.StreamID, FileIndex);
                //Log.Instance().Print(ClientLink);
                //Log.Instance().Print(FileLink);
                //g_Player.PlayBackEnded += new g_Player.EndedHandler(OnPlayBackEnded);
                //g_Player.PlayBackStopped += new g_Player.StoppedHandler(OnPlayBackStopped);

                //if (Utils.VideoExtensions.Contains(GetExtension(file.Filename)))
                //{
                //    g_Player.PlayVideoStream(FileLink,file.Filename);
                //    g_Player.ShowFullScreenWindow();
                //    g_Player.FullScreen = true;
                //    //OnlineVideos.MediaPortal1.Player.PlayerFactory factory = new OnlineVideos.MediaPortal1.Player.PlayerFactory(PlayerType.Internal, FileLink);
                //    //((OnlineVideosPlayer)factory.PreparedPlayer).PrepareGraph();
                //    //(((OnlineVideosPlayer)factory.PreparedPlayer).BufferFile());
                //    //IPlayerFactory savedFactory = g_Player.Factory;
                //    //g_Player.Factory = factory;
                //    //g_Player.Play(FileLink, g_Player.MediaType.Video);
                //    //g_Player.Factory = savedFactory;

                //}
                //if (Utils.AudioExtensions.Contains(GetExtension(file.Filename)))
                //{
                //    g_Player.PlayAudioStream(FileLink);
                //}
                //break;


                // };
            }
        }
예제 #24
0
        public void TorrentsContextMenu(Torrent uTorrent)
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }

            dlg.Reset();
            dlg.SetHeading("Torrent details menu");
            if (uTorrent.Started())
            {
                dlg.Add("Stop");
            }
            else
            {
                dlg.Add("Start");
            }

            if (uTorrent.Paused())
            {
                dlg.Add("Resume");
            }
            else
            {
                dlg.Add("Pause");
            }


            dlg.Add("Remove");
            dlg.Add("Start All");
            dlg.Add("Stop All");
            dlg.Add("Pause All");
            dlg.Add("Resume All");

            dlg.DoModal(GUIWindowManager.ActiveWindow);

            Menu menu = new Menu();

            switch (dlg.SelectedLabelText)
            {
            case "Start":
            {
                TorrentEngine.Instance().TorrentSession.Start(uTorrent.Hash);;
                break;
            };

            case "Stop":
            {
                TorrentEngine.Instance().TorrentSession.Stop(uTorrent.Hash);;
                break;
            };

            case "Resume":
            {
                TorrentEngine.Instance().TorrentSession.Resume(uTorrent.Hash);
                break;
            };

            case "Pause":
            {
                TorrentEngine.Instance().TorrentSession.Pause(uTorrent.Hash);
                break;
            };

            case "Remove":
            {
                GUIDialogYesNo ask = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                ask.Reset();
                ask.SetHeading("Remove also files?");
                ask.SetLine(1, "Files are removed permanently.");
                ask.SetLine(2, "Cannot be undone.");
                ask.SetDefaultToYes(false);
                ask.DoModal(GUIWindowManager.ActiveWindow);

                if (ask.IsConfirmed)
                {
                    TorrentEngine.Instance().TorrentSession.Remove(uTorrent.Hash, true);
                }
                else
                {
                    TorrentEngine.Instance().TorrentSession.Remove(uTorrent.Hash, false);
                }
                break;
            };

            case "Start All":
            {
                TorrentEngine.Instance().TorrentSession.Start(TorrentEngine.Instance().TorrentSession.TorrentsAll);
                break;
            };

            case "Stop All":
            {
                TorrentEngine.Instance().TorrentSession.Stop(TorrentEngine.Instance().TorrentSession.TorrentsAll);
                break;
            };

            case "Pause All":
            {
                TorrentEngine.Instance().TorrentSession.Pause(TorrentEngine.Instance().TorrentSession.TorrentsAll);
                break;
            };

            case "Resume All":
            {
                TorrentEngine.Instance().TorrentSession.Resume(TorrentEngine.Instance().TorrentSession.TorrentsAll);
                break;
            };
            }
        }