Esempio n. 1
0
        public int getPLFileCount(int listID, string filter = null)
        {
            int count = -1;

            try
            {
                Task t = Task.Run(() =>
                {
                    IMJPlaylistAutomation iList = jr.GetPlaylistByID(listID);
                    IMJFilesAutomation iFiles   = iList.GetFiles();
                    if (!string.IsNullOrEmpty(filter))
                    {
                        iFiles.Filter(filter);
                    }

                    count = iFiles.GetNumberFiles();
                });
                if (!t.Wait(1000))
                {
                    return(-2);  // timeout, slow playlist
                }
            }
            catch { }
            return(count);
        }
Esempio n. 2
0
        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--;
                }
            }
        }
Esempio n. 3
0
        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");
        }