aboutsummaryrefslogtreecommitdiff
path: root/jMusicHub.java
blob: 2cbedc3bf2393e108611ee94acd6e24445096bbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import java.util.*;

/** <h1>jMusicHub</h1>
 *
 * The jMusicHub class is basically the app.
 * It is used to launch the whole process.
 *
 * @author  Aimeric ADJUTOR
 * @version 1.0
 * @since   2020-11-13
 * */

public class jMusicHub {

	/** <h2>addSong</h2>
	 * add Song is used to add songs thanks to the "c" option
	 * @param scan Scanner Object
	 */
	public static Song addSong(Scanner scan){
		System.out.println("Adding a song...");
		System.out.printf("Title : ");
		String title = scan.nextLine();
		System.out.printf("Duration (in seconds) : ");
		int duration = scan.nextInt();
		System.out.printf("Content path : ");
		String trash = scan.nextLine(); //Using this because the content scan is skip after a nexInt
		String content = scan.nextLine();
		System.out.printf("Artist : ");
		String artist = scan.nextLine();
		System.out.printf("Genre (JAZZ, CLASSICAL, HIPHOP, ROCK, POP, RAP) : ");
		String choosedGenre = scan.nextLine();
		choosedGenre = choosedGenre.toUpperCase();
		Genre genre = Genre.valueOf(choosedGenre);
		System.out.println("");

		System.out.println("Do you confirm the addition of the following song ?");
		System.out.println("Title : " + title);
		System.out.println("Duration : " + duration);
		System.out.println("Content path : " + content);
		System.out.println("Artist : " + artist);
		System.out.println("Genre : " + genre);
		System.out.println("[Y/n]");
		String confirm = scan.nextLine();

		if (confirm.equalsIgnoreCase("Y")){ //if the user is ok with what he typed, create a song obj
			Song newSong = new Song(title, duration, content, artist,genre);
			return newSong;
//				songs.add(newSong);
		} else {
			System.out.println("Aborting...");
			System.out.println("");
			return null;
		}
	}

	public jMusicHub() {

		System.out.println("Welcome to the jMusicHub !\n");

		Scanner scan = new Scanner(System.in);
		String userInput; //Used to get the user's inputs.

		ArrayList<Song> songs = new ArrayList<Song>();
		//used to temporarly save the songs before any "s" command

		System.out.println("Starting extraction");
		//Here will be the process to extract the files
/*	        try {
			FileOutputStream fos = new FileOutputStream(file);
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			oos.writeObject(albums);
			oos.close();
			fos.close();
		}
		catch (IOException ioe) {
			ioe.printStackTrace();
			return;
		}*/
		System.out.println("Extraction done\n");
		//Here will be the number of playlist, albums, songs and auidobook extracted

		do {
			System.out.println("What do you want to do? [h for help]");
			userInput = scan.nextLine();
			switch(userInput) {
				case "h" : //page help
					System.out.printf("c: add a new song\na: add a new album\n+: add an existing song to an album\nl: add a new audiobook\np: create a new playlist from existing songs and audiobooks\n-: delete a playlist\ns: save playlists, albums, songs and audiobooks into the concerned files\nh: print this help screen\nq: quit the program\n");
					break;
				case "q" :
					System.out.println("Goodbye !");
					break;

				case "c":
					try { //If something goes wrong, abort
						Song newSong=addSong(scan);
						if (newSong != null){
							songs.add(newSong);
							System.out.println("Actual content of your songs list (you must save it (s) to do anything else with your songs) :");
							for (Song iSong : songs){
							   System.out.println(iSong);
							}
							System.out.println("");

						}
					} catch (InputMismatchException | IllegalArgumentException e) {
						System.out.println("You typed something wrong... I'm aborting..");
						System.out.println("");
					}
					break;

				case "a":
					break;
				case "+":
					break;
				case "l":
					break;
				case "p":
					break;
				case "-":
					break;
				case "s":
					for (Song s: songs){
					    s.save();
					}

					break;
				default :
					System.out.println("Unknown command. Type h for help.");

			}
		} while(!userInput.equals("q"));

	}

	public static void main(String[] args) {
		new jMusicHub();
	}
}