aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/musichub/business/MusicHub.java
diff options
context:
space:
mode:
authorClyhtsuriva <61652557+clyhtsuriva@users.noreply.github.com>2021-06-28 21:40:03 +0000
committerGitHub <noreply@github.com>2021-06-28 21:40:03 +0000
commit1504d0255279133668b85f5c092f040a14fbc35f (patch)
tree0c9b9e927aa4d5f35ccc07e45e8abd973b2bad08 /src/main/java/musichub/business/MusicHub.java
parent48d56d9db8fe93f1e1799674fefabdfc677d2eb7 (diff)
parent49196ae84aea338dbc6cd10f4d135e4b717cdd1f (diff)
downloadSpoteezer-1504d0255279133668b85f5c092f040a14fbc35f.tar.gz
Spoteezer-1504d0255279133668b85f5c092f040a14fbc35f.tar.bz2
Spoteezer-1504d0255279133668b85f5c092f040a14fbc35f.zip
Merge pull request #23 from Said-Belhadj/developHEADmaster
Merging develop to master.
Diffstat (limited to '')
-rw-r--r--src/main/java/musichub/business/MusicHub.java (renamed from src/musichub/business/MusicHub.java)76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/musichub/business/MusicHub.java b/src/main/java/musichub/business/MusicHub.java
index 38e2214..8db2f11 100644
--- a/src/musichub/business/MusicHub.java
+++ b/src/main/java/musichub/business/MusicHub.java
@@ -6,6 +6,9 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.UnsupportedAudioFileException;
+import java.io.IOException;
import java.util.*;
class SortByDate implements Comparator<Album> {
@@ -326,4 +329,77 @@ public class MusicHub {
}
xmlHandler.createXMLFile(document, ELEMENTS_FILE_PATH);
}
+
+ public void getAudioElement(List<AudioElement> audios, String elementTitle) throws NoAlbumFoundException, UnsupportedAudioFileException, IOException, LineUnavailableException {
+ for (AudioElement el : audios) {
+ if (el.getTitle().equalsIgnoreCase(elementTitle)) {
+ el.manageAudioElement();
+ }
+ }
+
+ }
+
+ public void searchAudioElement() throws UnsupportedAudioFileException, NoAlbumFoundException, LineUnavailableException, IOException, NoElementFoundException {
+ Scanner scanner = new Scanner(System.in);
+ System.out.println("Entrez le titre ou l'artiste de la musique que vous souhaitez chercher dans la base de données");
+ String word = scanner.next().toLowerCase(Locale.ROOT);
+ List<AudioElement> searchResult = new ArrayList<>();
+ for(AudioElement el : elements){
+ if(el.getTitle().toLowerCase(Locale.ROOT).contains(word) || el.getArtist().toLowerCase(Locale.ROOT).contains(word)){
+ searchResult.add(el);
+ System.out.println(el);
+ }
+ }
+
+ if (searchResult.isEmpty()) {
+ throw new NoElementFoundException("Any result for your search");
+ }
+ if (searchResult.size() == 1) {
+ this.getAudioElement(searchResult, searchResult.get(0).getTitle());
+ }
+ }
+
+ /**
+ * Method getting a list of playlists
+ *
+ * @return a list of playlist titles
+ * @author Anthony BOULANT
+ */
+ public String getPlayListsTitles() {
+ StringBuilder titleList = new StringBuilder();
+
+ for (PlayList pl : playlists)
+ titleList.append(pl.getTitle()).append("\n");
+ return titleList.toString();
+ }
+
+ /**
+ * Method checking the songs contained in a chosen playlist and returning them if found.
+ *
+ * @param playListTitle the title of a (chosen) playlist
+ * @return a list of songs from a playlist
+ * @throws NoPlayListFoundException if the chosen playlist doesn't exist
+ * @author Anthony BOULANT
+ */
+ 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