Пример #1
0
        public static async Task <KodiFileResponse> GetDirectoryContents(String KodiBaseURL, KodiDirectoryRequest Request)
        {
            KodiFileResponse Response = new KodiFileResponse();

            try
            {
                String JsonRequest = HelperMethods.SerializeObject(Request);
                String JsonResult  = await SendKodiCommandAsync(KodiBaseURL, JsonRequest);

                DataContractJsonSerializer ser    = new DataContractJsonSerializer(Response.GetType());
                System.IO.MemoryStream     stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonResult));
                Response = (KodiFileResponse)ser.ReadObject(stream);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            return(Response);
        }
Пример #2
0
        public async Task <List <MusicFolderEntry> > GetFolderEntries(String Folder)
        {
            List <MusicFolderEntry> Entries = new List <MusicFolderEntry>();

            try
            {
                if (MyInfo.FolderCache.Exists(Folder))
                {
                    Entries = MyInfo.FolderCache.FromCache(Folder);
                }
                else
                {
                    KodiDirectoryRequest Req = new KodiDirectoryRequest()
                    {
                        id = 1
                    };
                    Req._params.directory = Folder;
                    //Use folder structure at the top, then library structure as we get deeper
                    if (!MyInfo.MediaFolders.ShouldDisplayWithFolderStructure)
                    {
                        Req._params.media = "music";
                    }
                    KodiFileResponse FileList = await KodiCommand.GetDirectoryContents(MyInfo.KodiServer, Req);

                    foreach (KodiFileEntry E in FileList.result.files)
                    {
                        MusicFolderEntry M = new MusicFolderEntry();
                        if (FormatFolderEntry(Folder, E, M))
                        {
                            Entries.Add(M);
                        }
                    }
                    MyInfo.FolderCache.ToCache(Folder, Entries);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Could not get folders from Kodi", ex);
            }
            return(Entries);
        }