Exemplo n.º 1
0
 private void btnPlaylistDeleteEntry_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         MusicFolderEntry item = (MusicFolderEntry)(sender as FrameworkElement).DataContext;
         int index             = lvPlaylist.Items.IndexOf(item);
         KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(new KodiRemoveItemFromPlaylist(MyInfo.CurrentPlaylistId, index)));
         foreach (MusicFolderEntry listitem in MyInfo.PlaylistEntries)
         {
             if (listitem.file == item.file)
             {
                 MyInfo.PlaylistEntries.Remove(listitem);
                 break;
             }
         }
         lvPlaylist.ItemsSource = null;
         BindingOperations.SetBinding(lvPlaylist, ListView.ItemsSourceProperty, new Binding()
         {
             Source = MyInfo.PlaylistEntries, Mode = BindingMode.OneWay
         });
         lvPlaylist.ScrollIntoView(item);
     }
     catch (Exception ex)
     {
         LogMessage("Error " + ex.ToString());
     }
 }
Exemplo n.º 2
0
        private async Task <Boolean> SyncPlaylistWithKodi(Int32 PlaylistId)
        {
            KodiPlayListItemsRequest  ItemsInList = new KodiPlayListItemsRequest(PlaylistId);
            KodiPlayListItemsResponse Response    = await KodiCommand.GetPlaylistItems(MyInfo.KodiServer, ItemsInList);

            if (Response.result.items != null && Response.result.items.Count() > 0)
            {
                MyInfo.PlaylistEntries.Clear();
                //Pull in existing items
                foreach (KodiPlayListItem I in Response.result.items)
                {
                    MusicFolderEntry E = new MusicFolderEntry()
                    {
                        Line1Display = I.title, file = I.file, Line2Display = I.file, Track = I.track
                    };
                    if (I.artist != null && I.artist.Count() > 0)
                    {
                        E.Line2Display = I.artist[0];
                    }
                    this.MyInfo.PlaylistEntries.Add(E);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            MusicFolderEntry E = (MusicFolderEntry)value;

            if (E.IsChecked)
            {
                return("/Assets/musiccheck.png");
            }
            if (!E.file.ToString().ToLower().EndsWith(".mp3"))
            {
                return("/Assets/music_folder.png");
            }
            else
            {
                return("/Assets/music.png");
            }
        }
Exemplo n.º 4
0
        private void MP3DisplayFromArtistPath(String Folder, String Label, MusicFolderEntry E)
        {
            String[] Parts;
            Int32    TrackNumber = 0;
            Boolean  HasTrackNumber;

            Label = Label.Replace(".mp3", "").Replace("_", "");
            if (Label.Contains("-"))
            {
                Parts          = Label.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                HasTrackNumber = Int32.TryParse(Parts[0].Trim().Replace(".", ""), out TrackNumber);
                if (HasTrackNumber)
                {
                    E.Track = TrackNumber.ToString();
                    if (Parts[1].Trim().Length < 4)
                    {
                        for (int i = 1; i < Parts.Length; i++)
                        {
                            E.Line1Display += " " + Parts[i];
                        }
                    }
                    else
                    {
                        E.Line1Display = Parts[1];
                    }
                }
                else
                {
                    E.Line1Display = Parts[0];
                }
            }
            else
            {
                HasTrackNumber = Int32.TryParse(Label.Substring(0, 2), out TrackNumber);
                if (HasTrackNumber)
                {
                    E.Track        = TrackNumber.ToString();
                    E.Line1Display = Label.Substring(2).Replace(".", "");
                }
                else
                {
                    E.Line1Display = Label;
                }
            }
        }
Exemplo n.º 5
0
        private async Task ProcessFirstRunAsync(MusicFolderEntry Entry)
        {
            try
            {
                List <String> Commands;

                Boolean PlaylistExists = await SyncPlaylistWithKodi(MyInfo.CurrentPlaylistId); //Does a playlist with entries exist in Kodi?

                KodiAddFileToPlayList AddRequest = new KodiAddFileToPlayList(MyInfo.CurrentPlaylistId, Entry.file);
                if ((!PlaylistExists || MyInfo.PlaylistEntries.Count == 0))
                {
                    //If playlist id does not exist or has no entries, then create it.
                    Commands = new List <string>();
                    Commands.Add(HelperMethods.SerializeObject(new KodiClearPlayList(MyInfo.CurrentPlaylistId)));
                    Commands.Add(HelperMethods.SerializeObject(AddRequest));
                    Commands.Add(HelperMethods.SerializeObject(new KodiOpenPlayList(MyInfo.CurrentPlaylistId, 0)));
                    await KodiCommand.SendKodiCommandsInOrderAsync(MyInfo.KodiServer, Commands);

                    this.MyInfo.PlaylistEntries.Add(Entry);
                }
                else
                {
                    //Playlist exists and may have entries, add file to end and resync
                    await KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(AddRequest));
                    await SyncPlaylistWithKodi(MyInfo.CurrentPlaylistId);

                    //If something is not already playing then start playlist at currently added file
                    KodiActivePlayersResponse Resp = await KodiCommand.GetActivePlayers(MyInfo.KodiServer);

                    if (Resp.result == null || Resp.result.Length == 0)
                    {
                        await KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(new KodiOpenPlayList(MyInfo.CurrentPlaylistId, this.MyInfo.PlaylistEntries.Count())));
                    }
                }

                //Set repeat mode to true
                await Task.Factory.StartNew(() => KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(new KodiSetRepeat(MyInfo.CurrentPlayerId, "all"))));
            }
            catch (Exception ex)
            {
                ShowErrorMessageAsync(ex);
            }
            this.FirstRun = false;
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        private async void btnListViewEntry_ClickAsync(object sender, RoutedEventArgs e)
        {
            MusicFolderEntry Entry = ((HomeScreen.MusicFolderEntry)((Windows.UI.Xaml.FrameworkElement)sender).DataContext);

            if (Entry.filetype.ToLower() == "directory")
            {
                MyInfo.MediaFolders.NextFolder(Entry.file);
                LoadFileEntries();
            }

            if (Entry.filetype.ToLower() == "file")
            {
                //Update the screen - This provides visual feedback but is not kept in sync during folder browsing
                Windows.UI.Xaml.Controls.Button TheButton   = ((Windows.UI.Xaml.Controls.Button)sender);
                Windows.UI.Xaml.Controls.Image  ButtonImage = ((Windows.UI.Xaml.Controls.Image)TheButton.Content);
                ButtonImage.Source = new BitmapImage(new Uri(this.BaseUri, "/Assets/musiccheck.png"));
                if (this.FirstRun)
                {
                    //First song you clicked on since the app started
                    ProcessFirstRunAsync(Entry);
                }
                else
                {
                    //Is something playing?
                    KodiActivePlayersResponse Response = await KodiCommand.GetActivePlayers(MyInfo.KodiServer);

                    if (Response.result.Length == 0)
                    {
                        ProcessFirstRunAsync(Entry);
                    }
                    else
                    {
                        //Add file to end of playing list...
                        KodiAddFileToPlayList AddRequest = new KodiAddFileToPlayList(MyInfo.CurrentPlaylistId, Entry.file);
                        Task.Factory.StartNew(() => KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(AddRequest)));
                        this.MyInfo.PlaylistEntries.Add(Entry);
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void MP3DisplayFromCollectionPath(String Folder, String Label, MusicFolderEntry E)
        {
            String[] Parts;
            Int32    TrackNumber = 0;

            Label = Label.Replace(".mp3", "");
            if (Folder.ToLower().Contains("billboard")) //Billboard top hits folder is all years..
            {
                if (Label.Substring(2, 1) == "_" && Int32.TryParse(Label.Substring(3, 3), out TrackNumber))
                {
                    E.Track = TrackNumber.ToString();
                    Parts   = Label.Substring(6).Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                }
                else
                {
                    Parts = Label.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                }
            }
            else
            {
                Parts = Label.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
            }
            if (Parts.Length > 0)
            {
                E.Line1Display = Parts[0];
                if (Parts.Length > 1)
                {
                    E.Line2Display = Parts[1] + " ";
                    for (int i = 2; i < Parts.Length; i++)
                    {
                        E.Line2Display += " " + Parts[i];
                    }
                }
            }
            else
            {
                E.Line1Display = Label;
            }
        }
Exemplo n.º 9
0
        public Boolean FormatFolderEntry(String Folder, KodiFileEntry KodiVersion, MusicFolderEntry MyVersion)
        {
            if (KodiVersion.file.EndsWith(".jpg") || KodiVersion.file.EndsWith(".txt"))
            {
                return(false);
            }
            if (Folder.ToLower().EndsWith("music/") && KodiVersion.file.ToLower().Contains("excluded"))
            {
                return(false);
            }

            switch (KodiVersion.filetype.ToLower())
            {
            case "directory":
                MyVersion.file         = KodiVersion.file;
                MyVersion.filetype     = KodiVersion.filetype;
                MyVersion.Line1Display = KodiVersion.label;
                MyVersion.Line2Display = String.Empty;
                MyVersion.HasInfo      = true;
                break;

            case "file":
                MyVersion.file         = KodiVersion.file;
                MyVersion.filetype     = KodiVersion.filetype;
                MyVersion.Line2Display = KodiVersion.label;

                if (!String.IsNullOrEmpty(KodiVersion.title))
                {
                    //If the title property is populated from Kodi, "metadata exists"
                    MyVersion.Line1Display = KodiVersion.title;
                    MyVersion.HasInfo      = true;
                }
                else
                {
                    //If the title property is not populated from Kodi, hack it out from the filename
                    try
                    {
                        MyVersion.Line1Display = KodiVersion.label;
                        MyVersion.HasInfo      = false;
                        if (Folder.ToLower().Contains("/artists"))
                        {
                            MP3DisplayFromArtistPath(Folder, KodiVersion.label, MyVersion);
                        }
                        else
                        {
                            MP3DisplayFromCollectionPath(Folder, KodiVersion.label, MyVersion);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogMessage("Error formatting " + ex.ToString());
                    }
                }

                //If we have a track use it...
                if (!String.IsNullOrWhiteSpace(KodiVersion.track))
                {
                    MyVersion.Track = KodiVersion.track;
                }

                if (KodiVersion.artist != null && KodiVersion.artist.Count() > 0)
                {
                    MyVersion.Line2Display = KodiVersion.artist[0];
                }

                break;

            default:
                return(false);
            }

            return(true);
        }