public async Task <List <VideoModel> > GetPlaylistVideos(PlaylistModel playlist)
        {
            var context    = _context;
            var playlistId = playlist.ID;

            return(await context.VideosTable.Where(x => x.Playlist_ID == playlistId).ToListAsync());
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Description")] PlaylistModel playlistModel, string[] selectedSongs)
        {
            if (id != playlistModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    playlistModel.LastUpdated = DateTime.Now;
                    _context.Update(playlistModel);

                    await UpdatePlaylistSongs(selectedSongs, playlistModel);

                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlaylistModelExists(playlistModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(playlistModel));
        }
Пример #3
0
        private void PlayerOnPlaybackStopped(object sender, StoppedEventArgs e)
        {
            Logger.Debug("Playback stopped");

            if (PlaybackState != PlaybackState.Playing)
            {
                return;
            }

            if (_currentPlaylist == PlaylistModel.Null)
            {
                PlaybackState = PlaybackState.Stopped;
                return;
            }

            var result = _currentPlaylist.GetNextTrack();

            if (!result.IsSuccess)
            {
                Logger.Debug("No next track available");

                PlaybackState = PlaybackState.Stopped;
                _currentPlaylist.CurrentTrack = TrackModel.Null;
                _currentPlaylist = PlaylistModel.Null;

                return;
            }

            Play(_currentPlaylist, result.Data);
        }
        public void AddSelectedSongToPlaylist(PlaylistModel playlist)
        {
            if (playlist == null)
            {
                return;
            }
            if (SelectedSong == null)
            {
                return;
            }

            if (SelectedSong.FilePath.Substring(0, 1) == StorageManager.SelectedDrive.Configuration.RootDirectory.Substring(0, 1))
            {
                if (!playlist.Songs.Contains(SelectedSong))
                {
                    playlist.Songs.Add(SelectedSong);
                }

                playlist.Save();
            }
            else
            {
                MessageBoxManager.GetMessageBoxStandardWindow("Playlist Error", "Cannot add song from another drive.",
                                                              MessageBox.Avalonia.Enums.ButtonEnum.Ok, MessageBox.Avalonia.Enums.Icon.Forbidden).ShowDialog(AppSession.ShellWindow);
            }
        }
        private ObservableCollection <VideoFolder> GetObservableCollection(PlaylistModel plm)
        {
            var padlock = new object();
            ObservableCollection <VideoFolder> list = new ObservableCollection <VideoFolder>();
            List <Task> Tasks = new List <Task>();

            foreach (var s in plm.GetEnumerator)
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(s.FilePath);
                var           task          = Task.Factory.StartNew(() =>
                                                                    FileLoader.LoadChildrenFiles(directoryInfo)
                                                                    ).ContinueWith(t =>
                {
                    lock (padlock)
                    {
                        if (t.Result != null)
                        {
                            list.Add(t.Result);
                        }
                    }
                }, TaskScheduler.Current);
                Tasks.Add(task);
            }
            Task.WaitAll(Tasks.ToArray());

            return(list);
        }
        private static List <PlaylistModel> _GetAllPlayLists()
        {
            List <PlaylistModel> pl = new List <PlaylistModel>();

            for (int i = 0; i < 50; i++)
            {
                PlaylistModel item = new PlaylistModel();
                item.PlayListName = string.Concat("Playlist ", i);
                for (int j = 0; j < 10; j++)
                {
                    SongModel song = new SongModel
                    {
                        AlbumName     = "Test",
                        PublishedDate = DateTime.Now.AddYears(-i),
                        SongArtist    = new ArtistModel
                        {
                            ArtistHomePageUrl       = "http://cnn.com",
                            ArtistName              = string.Concat("Artist ", j, "-", i),
                            ArtistThumbnailImageUrl = string.Empty
                        },
                        SongOrder = j,
                        Title     = string.Concat("Song ", j, "-", i)
                    };
                    item.Songs.Add(song);
                }
                pl.Add(item);
            }
            return(pl);
        }
Пример #7
0
        private void PlaylistImage_MouseDown(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog open = new System.Windows.Forms.OpenFileDialog();

            // image filters
            open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
            if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // display image in picture box


                string sourceFile = open.FileName;
                string destFile   = $@"{GeneralDataManagement.ImageFolderPath}\{System.IO.Path.GetFileName(sourceFile)}";
                try
                {
                    PlaylistImage.Source = new BitmapImage(new Uri(open.FileName));
                    PlaylistModel playlistToEdit = (this.DataContext as PlaylistInfoViewModel).PlaylistDetail;

                    if (File.Exists(destFile) == false)
                    {
                        System.IO.File.Copy(sourceFile, destFile, true);
                    }
                    playlistToEdit.ImagePath = destFile.Replace($@"{GeneralDataManagement.ImageFolderPath}\", "");
                    SongDataAccess.UpdatePlaylist(playlistToEdit);
                    playlistToEdit.ImagePath = System.IO.Path.GetFileName(open.FileName);
                }
                catch (Exception)
                {
                    MessageBox.Show("Chỉnh sửa thất bại");
                }
            }
        }
Пример #8
0
        private void AddHighestRatedToPlaylists(Task<AlbumList> task)
        {
            switch (task.Status)
            {
                case TaskStatus.RanToCompletion:
                    Dispatcher.Invoke(() =>
                    {
                        AlbumList albumList = task.Result;
                        var tracks = albumList.Albums.Where(a => !a.IsDir).ToList();
                        int duration = tracks.Sum(child => child.Duration);

                        PlaylistModel newHighestRatedPlaylist = new PlaylistModel
                        {
                            Duration = TimeSpan.FromSeconds(duration),
                            Name = "Highest Rated",
                            Tracks = tracks.Count,
                            Playlist = null
                        };

                        PlaylistModel currentHighestRatedPlaylist = _playlistItems.FirstOrDefault(p => p.Playlist == null && p.Name == "Highest Rated");

                        if (currentHighestRatedPlaylist == null)
                            _playlistItems.Add(newHighestRatedPlaylist);
                        else
                        {
                            _playlistItems.Remove(currentHighestRatedPlaylist);
                            _playlistItems.Add(newHighestRatedPlaylist);
                        }
                    });
                    break;
            }
        }
Пример #9
0
        private PlaylistModel PopulatePlaylist(PlaylistModel playlist)
        {
            for (var i = 0; i < 4; i++)
            {
                playlist.MediaItems.Add(new MediaItemModel()
                {
                    CreatedBy     = _context.FullyQualifiedTestClassName,
                    CreatedOn     = DateTime.UtcNow,
                    UpdatedOn     = DateTime.UtcNow,
                    UpdatedBy     = _context.FullyQualifiedTestClassName,
                    Description   = $"Description for {_context.FullyQualifiedTestClassName} MediaItem number {i}",
                    Duration      = 0,
                    Id            = 1,
                    IsDeleted     = false,
                    Location      = "Memory",
                    Playlist      = playlist,
                    PlaylistId    = playlist.Id,
                    PrivacyStatus = (int)PrivacyStatus.None,
                    Sequence      = 0,
                    Title         = $"Title for {_context.FullyQualifiedTestClassName} MediaItem number {i}",
                });
            }

            return(playlist);
        }
Пример #10
0
        public void Post(PlaylistModel result)
        {
            var tracks      = TransformViewModelToTracks(result.Tracks);
            var newPlaylist = createService.CreatePlaylist(result.Name, result.Description, tracks);

            Console.WriteLine();
        }
        public List <int> Suggset(PlaylistModel playlist)
        {
            if (classifier == null)
            {
                throw new NotTrainedException();
            }

            List <int> songIdList = new List <int>();

            foreach (PlaylistSongModel pms in playlist.Songs)
            {
                songIdList.Add(pms.SongId);
            }

            int[][]    matches          = classifier.Decide(songIdList.ToArray());
            List <int> resultSongIdList = new List <int>();

            for (int i = 0; i < matches.Length; i++)
            {
                for (int j = 0; j < matches[0].Length; j++)
                {
                    resultSongIdList.Add(matches[i][j]);
                }
            }

            return(resultSongIdList);
        }
Пример #12
0
        private void RenameDia_OnFinished(object sender, EventArgs e)
        {
            RenameDialogControl renameDialog  = (RenameDialogControl)sender;
            PlaylistModel       playlistModel = renameDialog.PlaylistModel;

            if (renameDialog.IsCancel)
            {
                return;
            }

            string PlaylistName = renameDialog.RenameText.Text;

            if (playlistModel == null)
            {
                PlaylistModel plm = new PlaylistModel
                {
                    PlaylistName = PlaylistName
                };
                plm.Add(renameDialog.ItemPath);
                AddToPlayList(plm);
                return;
            }
            playlistModel.PlaylistName = PlaylistName;
            AddToPlayList(playlistModel);
        }
        private async void OpenMidi(object sender, RoutedEventArgs e)
        {
            try
            {
                MidiFile midiFile = await bassManager.LoadFile();

                PlaylistModel playlist = MainModule.ActivePlaylist;

                if (playlist == null)
                {
                    MainModule.InitPlaylist();
                }

                if (midiFile != null)
                {
                    MainModule.AddMidiFile(midiFile);
                    if (state == States.Idle || state == States.Midi_loaded)
                    {
                        state = States.Midi_loaded;
                    }
                    else
                    {
                        state = States.All_loaded;
                    }
                }
            }
            catch (Exception exep)
            {
                Debug.WriteLine(exep.Message);
            }
        }
Пример #14
0
        public JsonResult Playlists(PlaylistModel model)
        {
            CustomToken token = ViewBag.Token;

            if (token.IsTokenEmpty())
            {
                return(null);
            }

            SpotifyWebAPI api = new SpotifyWebAPI()
            {
                AccessToken = token.AccessToken, TokenType = token.TokenType
            };

            var tracksIds = model.trackId.Split(',');

            List <ErrorResponse> errorResponses = new List <ErrorResponse>();

            foreach (var tracksId in tracksIds)
            {
                errorResponses.Add(api.AddPlaylistTrack(model.playlistId, string.Format("spotify:track:{0}", tracksId)));
            }

            return(Json(errorResponses.FirstOrDefault(e => e.Error == null)));
        }
Пример #15
0
 private async Task WorkoutRemove(IWorkout workout, PlaylistModel list)
 {
     list.Workouts.Remove(list.Workouts.First(w => w.Id == workout.Id && w.WorkoutType == workout.WorkoutType));
     var type = workout.WorkoutType.ToString();
     await db_.Database.Table <ListWorkoutDBModel>().DeleteAsync(s =>
                                                                 s.PlaylistId == list.Playlist.Id && s.WorkoutId == workout.Id && s.WorkoutType.Equals(type));
 }
        public async System.Threading.Tasks.Task <RedirectResult> PlaylistCreate()
        {
            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                string body = await reader.ReadToEndAsync();

                body = body.Replace("+", " ").Replace("=on", "");
                Stack <string> brokenOutPlayStack = new Stack <string>();
                string[]       brokenOutPlaylist  = body.Split('&');
                foreach (var item in brokenOutPlaylist)
                {
                    brokenOutPlayStack.Push(item);
                }
                string playlistId   = brokenOutPlayStack.Pop().Replace("playlistid=", "");
                string playlistName = brokenOutPlayStack.Pop().Replace("playlistname=", "");
                if (playlistId != "")
                {
                    _playlistService.Update(playlistId, new PlaylistModel {
                        playlistname = playlistName, videos = brokenOutPlayStack, __v = 0
                    });
                }
                else
                {
                    PlaylistModel newDoc = _playlistService.Create(new PlaylistModel {
                        playlistname = playlistName, videos = brokenOutPlayStack, __v = 0
                    });
                    playlistId = newDoc.Id;
                }
                string referrer = Request.Headers["Referer"].ToString() + "playlistorder?id=" + playlistId;
                return(Redirect(referrer));
            }
        }
        public async Task <PlaylistModel> GetPlaylistWithKey(PlaylistModel playlist)
        {
            var dbPlaylists = _database.GetCollection <LiteDbPlaylistModel>("Playlists");
            var matched     = dbPlaylists.Find(x => x.User_ID == playlist.User_ID && x.Name == playlist.Name).FirstOrDefault();

            return(await Task.FromResult(matched.ConvertToPlaylist()));
        }
        public async Task <IActionResult> Edit(int id, [Bind("PlaylistId,Public,PlaylistImage,PlaylistName")] PlaylistModel playlistModel)
        {
            if (id != playlistModel.PlaylistId)
            {
                return(NotFound());
            }

            PlaylistModel orig = _context.Playlists.AsNoTracking().Where(p => p.PlaylistId == id).FirstOrDefault();

            playlistModel.PlaylistImage = orig.PlaylistImage;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(playlistModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlaylistModelExists(playlistModel.PlaylistId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(playlistModel));
        }
Пример #19
0
 public void RemoveMoviePlaylistItem(PlaylistModel plm)
 {
     if (ApplicationService.AppPlaylist.MoviePlayList.Contains(plm))
     {
         ApplicationService.AppPlaylist.MoviePlayList.Remove(plm);
     }
 }
Пример #20
0
 public void AddMoviePlaylistItem(PlaylistModel plm)
 {
     if (!ApplicationService.AppPlaylist.MoviePlayList.Contains(plm))
     {
         ApplicationService.AppPlaylist.MoviePlayList.Add(plm);
     }
 }
Пример #21
0
        private void EditPlaylist_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            PlaylistModel    playlistModel    = e.Parameter as PlaylistModel;
            EditPlaylistView editPlaylistView = new EditPlaylistView(playlistModel);

            editPlaylistView.ShowDialog();
        }
Пример #22
0
 /// <summary>
 /// Remove ParentNode of playlist from the database
 /// </summary>
 /// <param name="playlistReferencingItemToRemove"></param>
 private void RemoveParentTreeViewNode(PlaylistModel playlistReferencingItemToRemove)
 {
     if (dbContext.TreeViewNodes != null && playlistReferencingItemToRemove.ParentNode != null)
     {
         dbContext.TreeViewNodes.Remove(playlistReferencingItemToRemove.ParentNode);
     }
 }
        public async Task <List <VideoModel> > GetPlaylistVideos(PlaylistModel playlist)
        {
            var dbPlaylists = _database.GetCollection <LiteDbPlaylistModel>("Playlists");
            var matched     = dbPlaylists.Include(x => x.Videos).Find(x => x.Name == playlist.Name && x.User_ID == playlist.User_ID).FirstOrDefault();
            var videos      = matched.Videos;

            return(await Task.FromResult(videos));
        }
Пример #24
0
        public async Task <PlaylistModel> GetPlaylistAsync(PlaylistModel playlist)
        {
            var p = _mapper.Map <Playlist>(playlist);

            p = await _unitOfWork.Playlists.GetByIdAsync(p.PlaylistId);

            return(_mapper.Map <PlaylistModel>(p));
        }
        public async Task <PlaylistModel> GetPlaylistWithKey(PlaylistModel playlist)
        {
            var userId    = UserId;
            var context   = _context;
            var playlists = await context.PlaylistsTable.Where(x => x.User_ID == userId).ToListAsync();

            return(playlists.Where(x => x.Name == playlist.Name).FirstOrDefault());
        }
        public async Task RemoveVideoFromPlaylist(VideoModel video, PlaylistModel playlist = null)
        {
            var context = _context;

            context.Attach(video);
            context.Remove(video);
            await context.SaveChangesAsync();
        }
 public void ChangePlaylist(PlaylistModel playlist)
 {
     if (_playlistManager.Contains(playlist))
     {
         Debug.WriteLine("Cambiando Playlist {0} con {1} canciones.", playlist.Name, playlist.Songs.Count);
         ActivePlaylist = playlist;
     }
 }
Пример #28
0
        private void PlayList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            TreeView      tree = (TreeView)sender;
            PlaylistModel pm   = (PlaylistModel)tree.SelectedItem;

            PlayFile.PlayFileFromPlayList(pm);
            UnSelectItem(tree);
        }
Пример #29
0
        private void ViewMyPlaylist(PlaylistModel obj)
        {
            NavigationParameters parameters = new NavigationParameters();

            parameters.Add("model", obj);

            _navigationService.NavigateAsync("ViewAllSongsInPlaylistPage", parameters, true, true);
        }
Пример #30
0
        public static string GetPlaylistId(PlaylistModel list)
        {
            var url    = new Uri(list.Location);
            var result = HttpUtility.ParseQueryString(url.Query)
                         .Get("list");

            return(result);
        }
Пример #31
0
 public static Playlist MapPlaylist(PlaylistModel playlistModel) => new Playlist
 {
     Id        = playlistModel.Id,
     Name      = playlistModel.Name,
     Public    = playlistModel.Public,
     UserId    = playlistModel.UserId,
     ShareLink = playlistModel.ShareLink
 };
Пример #32
0
        public void AddPlaylist(string name)
        {
            PlaylistTable table = new PlaylistTable(name);

            DatabaseManager.Current.AddPlaylist(table);

            PlaylistModel playlistModel = new PlaylistModel(table);
            Playlists.Add(playlistModel);
            playlistLookupDictionary.Add(playlistModel.PlaylistId, playlistModel);
        }
Пример #33
0
        private void LoadCollection()
        {
            PerfTracer perfTracer = new PerfTracer("LibraryModel Loading");

            IEnumerable<SongTable> allSongs = DatabaseManager.Current.FetchSongs();
            foreach (SongTable songEntry in allSongs)
            {
                SongModel songModel = new SongModel(songEntry);
                _allSongs.Add(songModel);
                songLookupDictionary.Add(songModel.SongId, songModel);                
            }

            perfTracer.Trace("Songs Added");

            IEnumerable<AlbumTable> allAlbums = DatabaseManager.Current.FetchAlbums();
            foreach (AlbumTable albumEntry in allAlbums)
            {
                AlbumModel albumModel = new AlbumModel(albumEntry);
                _allAlbums.Add(albumModel);
                albumLookupDictionary.Add(albumModel.AlbumId, albumModel);
            }

            perfTracer.Trace("Albums Added");

            IEnumerable<ArtistTable> allArtists = DatabaseManager.Current.FetchArtists();
            foreach (ArtistTable artistEntry in allArtists)
            {
                ArtistModel artistModel = new ArtistModel(artistEntry);
                _allArtists.Add(artistModel);
                artistLookupDictionary.Add(artistModel.ArtistId, artistModel);
            }

            perfTracer.Trace("Artists Added");

            IEnumerable<PlaylistTable> allPlaylists = DatabaseManager.Current.FetchPlaylists();
            foreach (PlaylistTable playlistEntry in allPlaylists)
            {
                PlaylistModel playlistModel = new PlaylistModel(playlistEntry);
                Playlists.Add(playlistModel);
                playlistLookupDictionary.Add(playlistModel.PlaylistId, playlistModel);

                playlistModel.Populate();
            }

            perfTracer.Trace("Playlists Added");

            IEnumerable<MixTable> allMixes = DatabaseManager.Current.FetchMixes();
            foreach (MixTable mixEntry in allMixes)
            {
                MixModel mixModel = new MixModel(mixEntry);
                Mixes.Add(mixModel);
                mixLookupDictionary.Add(mixModel.MixId, mixModel);

                mixModel.Populate();
            }

            perfTracer.Trace("Mixes Added");
        }
Пример #34
0
        public PlaylistViewModel LookupPlaylist(PlaylistModel playlist)
        {
            if (PlaylistLookupMap.ContainsKey(playlist.PlaylistId))
            {
                return PlaylistLookupMap[playlist.PlaylistId];
            }
            else
            {
                PlaylistViewModel newViewModel = new PlaylistViewModel(playlist);

                PlaylistLookupMap.Add(newViewModel.PlaylistId, newViewModel);
                PlaylistCollection.Add(newViewModel);
                return newViewModel;
            }
        }
Пример #35
0
        private void AddStarredToPlaylists(Task<Starred> task)
        {
            switch (task.Status)
            {
                case TaskStatus.RanToCompletion:
                    Dispatcher.Invoke(() =>
                                          {
                                              Starred starred = task.Result;
                                              int starDuration = starred.Songs.Sum(child => child.Duration);

                                              PlaylistModel newStarredPlaylist = new PlaylistModel
                                                                             {
                                                                                 Duration = TimeSpan.FromSeconds(starDuration),
                                                                                 Name = "Starred",
                                                                                 Tracks = starred.Songs.Count,
                                                                                 Playlist = null
                                                                             };

                                              PlaylistModel currentStarredPlaylist = _playlistItems.FirstOrDefault(p => p.Playlist == null && p.Name == "Starred");

                                              if (currentStarredPlaylist == null)
                                                  _playlistItems.Add(newStarredPlaylist);
                                              else
                                              {
                                                  _playlistItems.Remove(currentStarredPlaylist);
                                                  _playlistItems.Add(newStarredPlaylist);
                                              }
                                          });
                    break;
            }
        }