aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorClyhtsuriva <61652557+clyhtsuriva@users.noreply.github.com>2021-06-28 17:18:13 +0000
committerGitHub <noreply@github.com>2021-06-28 17:18:13 +0000
commita6f25cbfb673cfcdf29c3913d3add3bd7b2de5cd (patch)
treed9b2fe67e7c087c77383a76ecbdb5ba3cea53409 /src/main/java
parent59ffe41bebf12a968565365892342ac7439d27ec (diff)
parent2b592b4986b92c85150ecb9d08a521e6391cc160 (diff)
Merge pull request #20 from Said-Belhadj/feature/STZ-0005
STZ-0005 : Add new feature - display playlist
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/musichub/business/MusicHub.java28
-rw-r--r--src/main/java/musichub/main/Main.java18
2 files changed, 46 insertions, 0 deletions
diff --git a/src/main/java/musichub/business/MusicHub.java b/src/main/java/musichub/business/MusicHub.java
index 660f0f8..f6805b6 100644
--- a/src/main/java/musichub/business/MusicHub.java
+++ b/src/main/java/musichub/business/MusicHub.java
@@ -359,5 +359,33 @@ public class MusicHub {
this.getAudioElement(searchResult, searchResult.get(0).getTitle());
}
}
+ public String getPlayListsTitles() {
+ StringBuilder titleList = new StringBuilder();
+ for (PlayList pl : playlists)
+ titleList.append(pl.getTitle()).append("\n");
+ return titleList.toString();
+ }
+
+ public List<AudioElement> getPlayListSongs(String playListTitle) throws NoPlayListFoundException {
+ PlayList thePlayList = null;
+ ArrayList<AudioElement> songsInPlayList = new ArrayList<>();
+ for (PlayList pl : playlists) {
+ if (pl.getTitle().equalsIgnoreCase(playListTitle)) {
+ thePlayList = pl;
+ break;
+ }
+ }
+ if (thePlayList == null) throw new NoPlayListFoundException("No playlist with this title in the MusicHub!");
+
+ List<UUID> songIDs = thePlayList.getElements();
+ for (UUID id : songIDs)
+ for (AudioElement el : elements) {
+ if (el instanceof Song) {
+ if (el.getUUID().equals(id)) songsInPlayList.add(el);
+ }
+ }
+ return songsInPlayList;
+
+ }
} \ No newline at end of file
diff --git a/src/main/java/musichub/main/Main.java b/src/main/java/musichub/main/Main.java
index a8d2128..4ac7052 100644
--- a/src/main/java/musichub/main/Main.java
+++ b/src/main/java/musichub/main/Main.java
@@ -277,6 +277,23 @@ public class Main {
System.out.println("Type h for available commands");
choice = scan.nextLine();
break;
+ case 'm':
+ //songs of a playlist
+ System.out.println("Songs of a playlist will be displayed; enter the playlist name, available playlists are:");
+ System.out.println(theHub.getPlayListsTitles());
+
+ playListTitle = scan.nextLine();
+ try {
+ List<AudioElement> songs = theHub.getPlayListSongs(playListTitle);
+ System.out.println(theHub.getPlayListSongs(playListTitle));
+ String song = scan.nextLine();
+ theHub.getAudioElement(songs, song);
+ } catch (NoPlayListFoundException ex) {
+ System.out.println("No playlist found with the requested title " + ex.getMessage());
+ }
+ printAvailableCommands();
+ choice = scan.nextLine();
+ break;
default:
break;
@@ -296,6 +313,7 @@ public class Main {
System.out.println("+: add a song to an album");
System.out.println("l: add a new audiobook");
System.out.println("p: create a new playlist from existing songs and audio books");
+ System.out.println("m: display songs of a playlist");
System.out.println("-: delete an existing playlist");
System.out.println("s: save elements, albums, playlists");
System.out.println("o: consult the app logs");