コード例 #1
0
        private void comboLists_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (loading)
            {
                return;
            }
            currentPlaylist = comboLists.SelectedItem as JRPlaylist;
            state.Playlist  = currentPlaylist?.Name;
            if (currentPlaylist != null)
            {
                //if (currentPlaylist.Files == null)
                LoadPlaylist(currentPlaylist);
            }

            var files = currentPlaylist?.Files.OrderBy(f => f.ToString()).ToList();

            comboFiles.DataSource = files;
            if (files == null || files.Count == 0)
            {
                currentFile = null;
            }
            else
            {
                comboFiles.SelectedIndex = 0;
            }
        }
コード例 #2
0
        private void LoadPlaylist(ProgressInfo progress)
        {
            JRPlaylist pl = progress.args[0] as JRPlaylist;

            pl.Files            = new List <JRFile>();
            progress.totalItems = pl.Count;
            int i = 0;

            List <string> fields = new List <string>();

            foreach (var f in state.TableFields)
            {
                if (jrAPI.FieldMap.TryGetValue(f.ToLower(), out string name))
                {
                    fields.Add(name);
                }
            }

            foreach (var file in jrAPI.getFiles(pl, fields))
            {
                pl.Files.Add(file);
                progress.currentItem = ++i;
                progress.subtitle    = $"{file.Name} ({file.Year})";
                progress.Update(false);
            }
        }
コード例 #3
0
        // adds playlist filecount to each combobox entry
        private void drawCombobox(object cmb, DrawItemEventArgs args)
        {
            args.DrawBackground();
            if (args.Index < 0)
            {
                return;
            }

            JRPlaylist item = (JRPlaylist)this.comboLists.Items[args.Index];

            Rectangle r1 = args.Bounds;

            r1.Width = r1.Width - 40;
            using (SolidBrush sb = new SolidBrush(args.ForeColor))
            {
                args.Graphics.DrawString(item.FullName, args.Font, sb, r1);
            }

            bool isSlow = item.Count == -2;

            if (item.Count >= 0 || isSlow)
            {
                string    txt  = isSlow ? "slow!" : item.Count.ToString();
                SizeF     size = args.Graphics.MeasureString(txt, args.Font);
                Rectangle r2   = args.Bounds;
                r2.X     = args.Bounds.Width - (int)size.Width - 1;
                r2.Width = (int)size.Width + 1;

                Color color = isSlow ? Color.Red : Color.DarkCyan;
                using (SolidBrush sb = new SolidBrush(args.State.HasFlag(DrawItemState.Selected) ? Color.White : color))
                {
                    args.Graphics.DrawString(txt, args.Font, sb, r2);
                }
            }
        }
コード例 #4
0
ファイル: JRiverAPI.cs プロジェクト: zybexXL/Zelda
        public IEnumerable <JRFile> getFiles(JRPlaylist playlist, List <string> fields = null, string filter = null, int start = 0, int step = 1)
        {
            IMJPlaylistAutomation pl    = jr.GetPlaylistByID(playlist.ID);
            IMJFilesAutomation    files = pl.GetFiles();

            if (!string.IsNullOrWhiteSpace(filter))
            {
                files.Filter(filter);
            }
            int num = files.GetNumberFiles();

            playlist.Count = num;
            for (int i = start; i < num; i += step)
            {
                var file = files.GetFile(i);
                if (file != null)
                {
                    yield return(getFieldValues(file, fields));
                }
                else
                {
                    playlist.Count--;
                }
            }
        }
コード例 #5
0
        private void LoadPlaylist(JRPlaylist list, ProgressUI progress = null)
        {
            if (progress == null)
            {
                progress = new ProgressUI($"Loading playlist '{list.Name}'", LoadPlaylist, false, list);
            }
            progress.ShowDialog(this);

            LoadDataTable();
        }
コード例 #6
0
        DataTable getDataTable(JRPlaylist playlist)
        {
            // create table and columns
            DataTable dt = new DataTable();

            dt.Columns.Add("File", typeof(JRFile));
            foreach (var tab in expressionTabs)
            {
                dt.Columns.Add(tab.ID);
            }
            foreach (string field in state.TableFields)
            {
                dt.Columns.Add(field);
            }
            dt.Columns.Add("API");

            var index = new Dictionary <JRFile, DataRow>();

            // add rows
            foreach (var file in playlist.Files.OrderBy(f => f.ToString()))
            {
                List <object> items = new List <object>();
                items.Add(file);
                foreach (var tab in expressionTabs)
                {
                    items.Add(string.Empty);
                }
                foreach (string field in state.TableFields)
                {
                    if (!jrAPI.FieldMap.TryGetValue(field.ToLower(), out string fname))
                    {
                        fname = field;
                    }

                    items.Add(file[fname.ToLower()]);
                }
                if (settings.ShowAPICallTime)
                {
                    items.Add(string.Empty);
                }
                index[file] = dt.Rows.Add(items.ToArray());
            }
            rowIndex = index;
            return(dt);
        }
コード例 #7
0
        private bool GetPlayLists(bool startup = false)
        {
            var progressUI = new ProgressUI("Connecting to MediaCenter...", ConnectJRiver, false);

            if (startup)
            {
                progressUI.StartPosition = FormStartPosition.CenterScreen;
            }

            progressUI.ShowDialog(this);

            if (!jrAPI.Connected)
            {
                progressUI.Close();
                MessageBox.Show("Cannot connect to MediaCenter, please make sure it's installed on this PC", "No MediaCenter!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (jrAPI.Playlists.Count == 0)
            {
                string filtered = !string.IsNullOrEmpty(settings.PlaylistFilter) ? "\nPlease check the Playlist Filter in settings." : "";
                MessageBox.Show($"Failed to load list of Playlists from MediaCenter!{filtered}", "No playlists", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            lblStatus.Text = $"Connected to MediaCenter v{jrAPI.Version} - {jrAPI.Library}";
            loading        = true;

            // update datagrid column/field list
            List <string> columns = new List <string>();

            foreach (var f in state.TableFields)
            {
                if (jrAPI.FieldDisplayNames.Contains(f, StringComparer.InvariantCultureIgnoreCase))
                {
                    columns.Add(f);
                }
            }
            state.TableFields = columns;

            // load current playlist files
            comboLists.DataSource = jrAPI.Playlists.OrderBy(p => p.Path).ThenBy(p => p.ToString()).ToList();
            JRPlaylist list = null;

            if (currentPlaylist != null)
            {
                list = jrAPI.Playlists.Where(p => p.Name == currentPlaylist.Name).FirstOrDefault();
            }
            if (startup && settings.ReloadPlaylist && state.Playlist != null)
            {
                list = jrAPI.Playlists.Where(p => p.Name == state.Playlist).FirstOrDefault();
            }
            if (list == null)
            {
                list = jrAPI.Playlists.Where(p => p.Name == "Recently Played").FirstOrDefault();
            }
            if (list == null)
            {
                list = jrAPI.Playlists.FirstOrDefault();
            }

            loading = false;
            comboLists.SelectedItem = list;

            return(true);
        }
コード例 #8
0
ファイル: JRiverAPI.cs プロジェクト: zybexXL/Zelda
        public IEnumerable <JRPlaylist> getPlaylists(string filter = null, bool countFiles = true)
        {
            Playlists = new List <JRPlaylist>();
            DateTime      limit    = DateTime.Now.AddSeconds(10);                   // max playlist loadtime
            List <string> plFilter = filter?.Split(';').Select(f => f.Trim()).Where(f => !string.IsNullOrEmpty(f)).ToList();

            if (plFilter != null && plFilter.Count == 0)
            {
                plFilter = null;
            }

            try
            {
                IMJPlaylistsAutomation iList = jr.GetPlaylists();
                int count = iList.GetNumberPlaylists();

                Logger.Log($"getPlaylists: loading {count} playlists");
                for (int i = 0; i < count; i++)
                {
                    if (countFiles && DateTime.Now > limit)
                    {
                        countFiles = false;                                             // disable getPLFileCount() if it's taking too long
                    }
                    IMJPlaylistAutomation list = iList.GetPlaylist(i);

                    if (list.Get("type") == "1")
                    {
                        continue;                               // 0 = playlist, 1 = playlist group, 2 = smartlist
                    }
                    string name     = list.Name ?? "playlist";
                    string fullname = $"{list.Path}\\{name}";
                    if (plFilter != null && plFilter.All(f => fullname.IndexOf(f, StringComparison.CurrentCultureIgnoreCase) < 0))
                    {
                        continue;
                    }

                    var playlist = new JRPlaylist(list.GetID(), name, -1, list.Path);

                    // get file count - except for "audio - task - missing files" which may take a loooong time (isMissing() slowness)
                    if (countFiles && !name.ToLower().Contains("missing files"))
                    {
                        playlist.Count = getPLFileCount(playlist.ID);
                        if (playlist.Count < 0)
                        {
                            Logger.Log($"Warning - Slow playlist! Can't get filecount for playlist '{list.Name}'");
                        }
                        //else Logger.Log($"      playlist {i} has {fcount} files");
                    }
                    if (playlist.Count != 0)
                    {
                        Playlists.Add(playlist);
                        yield return(playlist);
                    }
                }
            }
            finally
            {
                Playlists = Playlists.OrderBy(p => p.Name.ToLower()).ToList();
            }
            Logger.Log("getPlaylists: finished");
        }