* 유튜브 리스트 최신화
/**
* 유튜브 리스트 최신화
* @return
* @throws Exception
*/
@RequestMapping("youtuebList.do", method=RequestMethod.GET)
@ResponseBody
private Map createYoutubeList() {
Map resultMap = new HashMap();
String youtubeUrl = "https://www.googleapis.com/youtube/v3/search?key=키값8o&part=snippet&channelId=채널아이디&order=date&type=video&safeSearch=moderate&maxResults=10&videoEmbeddable=true";
HttpGet get = new HttpGet(youtubeUrl);
String result = "";
DefaultHttpClient http = new DefaultHttpClient();
try {
result = http.execute(get, new BasicResponseHandler());
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(result);
JSONArray items = (JSONArray)jsonObject.get("items");
//유튜브 데이터 초기화
macaronicsService.deleteYoutube();
for(int i = 0; i < items.size(); i++) {
JSONObject item = (JSONObject)items.get(i);
JSONObject sitem = (JSONObject)item.get("snippet"); // 상세정보
Log.info(i + " **** sitem " , sitem.toJSONString());
if(!Util.nvl(sitem.get("liveBroadcastContent")).equals("upcoming")) {
// 실시간 방송은 제한다.
JSONObject iitem = (JSONObject)item.get("id"); // 비디오 아이디
JSONObject titem = (JSONObject)((JSONObject)sitem.get("thumbnails")).get("medium"); // 썸네일
SnsItemVo obj = new SnsItemVo();
obj.setVideoId(Util.nvl(iitem.get("videoId")));
String title = Util.nvl(sitem.get("title"));
//제목 이모티콘 제거
Pattern emoticons = Pattern.compile("[\\uD83C-\\uDBFF\\uDC00-\\uDFFF]+");
Matcher emoticonsMatcher = emoticons.matcher(title);
title = emoticonsMatcher.replaceAll(" ");
obj.setTitle(title);
obj.setDesc(Util.nvl(sitem.get("description")));
obj.setPublishDate(Util.substring(Util.nvl(sitem.get("publishedAt")), 0, 10));
obj.setThumbnailPath(Util.nvl(titem.get("url")));
obj.setLink("https://www.youtube.com/watch?v=" + obj.getVideoId());
//유튜브 데이터 DB 등록 처리
macaronicsService.insertYoutube(obj);
}
}
resultMap.put("processing", "over");
resultMap.put("success", true);
}catch (Exception e) {
}
return resultMap;
}
//유튜브 데이터 초기화
<delete id="deleteYoutube">
DELETE FROM TBL_YOUTUBE
</delete>
//유튜브 데이터 넣기
<insert id="insertYoutube" parameterType="map">
with upsert as(
update TBL_YOUTUBE
set SY_UPD_DT = current_timestamp
where SY_VIDEO_ID = #{videoId}
RETURNING *
)
insert into TBL_YOUTUBE
( SY_VIDEO_ID
,SY_TITLE
,SY_THUMB
,SY_DESC
,SY_LINK
,SY_PUBLISH_DATE
,SY_REG_DT )
select #{videoId},
#{title},
#{thumbnailPath},
#{desc},
#{link},
#{publishDate},
current_timestamp
WHERE NOT EXISTS(SELECT * FROM UPSERT)
</insert>

















댓글 ( 4)
댓글 남기기