Skip to content
Permalink
0d82ff1dc4
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
42 lines (36 sloc) 1.23 KB
package kb.howtokb.usecase;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class YoutubeVideoReader {
/**
* Read youtube video information in json format
* @param input
* @return map: youtube video id -- youtube video object
* @throws FileNotFoundException
* @throws IOException
* @throws ParseException
*/
public static Map<String, YouTubeObj> tubeReader(String input) throws FileNotFoundException, IOException, ParseException{
Map<String, YouTubeObj> allvideos = new HashMap<>();
JSONParser parser = new JSONParser();
try (BufferedReader br = new BufferedReader(new FileReader(input))) {
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
Object obj = parser.parse(sCurrentLine);
JSONObject jsonObject = (JSONObject) obj;
YouTubeObj utube = YouTubeObj.toYouTubeObj(jsonObject);
allvideos.put(utube.getId(), utube);
//System.out.println(utube.getTitle());
System.out.println(utube.getId());
}
}
return allvideos;
}
}