Permalink
Cannot retrieve contributors at this time
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?
HowToKB/src/kb/howtokb/usecase/YoutubeVideoReader.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (36 sloc)
1.23 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |