-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…rize-youtube [Feat] 크롤링해 비디오와 장소 정보를 저장하는 기능을 추가했어요
- Loading branch information
Showing
24 changed files
with
562 additions
and
256 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/team7/inplace/crawling/application/AddressUtil.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package team7.inplace.crawling.application; | ||
|
||
import static lombok.AccessLevel.PRIVATE; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = PRIVATE) | ||
public class AddressUtil { | ||
private static final String ADDRESS_REGEX = "[가-힣0-9]+(?:도|시|구|군|읍|면|동|리|로|길)[^#,\\n()]+(?:동|읍|면|리|로|길|호|층|번지)[^#,\\n()]+"; | ||
|
||
public static String extractAddress(JsonNode snippet) { | ||
|
||
String videoDescription = snippet.path("description").asText(); | ||
|
||
Pattern pattern = Pattern.compile(ADDRESS_REGEX); | ||
Matcher matcher = pattern.matcher(videoDescription); | ||
if (matcher.find()) { | ||
return matcher.group(); | ||
} | ||
return null; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/team7/inplace/crawling/application/CrawlingFacade.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package team7.inplace.crawling.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import team7.inplace.global.annotation.Facade; | ||
import team7.inplace.video.application.VideoFacade; | ||
|
||
@Facade | ||
@RequiredArgsConstructor | ||
public class CrawlingFacade { | ||
private final YoutubeCrawlingService youtubeCrawlingService; | ||
private final VideoFacade videoFacade; | ||
|
||
public void updateVideos() { | ||
var crawlingInfos = youtubeCrawlingService.crawlAllVideos(); | ||
for (var crawlingInfo : crawlingInfos) { | ||
var videoCommands = crawlingInfo.toVideoCommands(); | ||
var placesCommands = crawlingInfo.toPlacesCommands(); | ||
|
||
videoFacade.createVideos(videoCommands, placesCommands); | ||
} | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/main/java/team7/inplace/crawling/application/dto/CrawlingInfo.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package team7.inplace.crawling.application.dto; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import java.util.List; | ||
import team7.inplace.crawling.client.dto.PlaceNode; | ||
import team7.inplace.place.application.command.PlacesCommand; | ||
import team7.inplace.video.application.command.VideoCommand; | ||
|
||
public record CrawlingInfo( | ||
Long influencerId, | ||
List<JsonNode> videoSnippets, | ||
List<PlaceNode> placeNodes | ||
) { | ||
public List<VideoCommand.Create> toVideoCommands() { | ||
return videoSnippets.stream() | ||
.map(snippet -> VideoCommand.Create.from(snippet, influencerId)) | ||
.toList(); | ||
} | ||
|
||
public List<PlacesCommand.Create> toPlacesCommands() { | ||
return placeNodes.stream() | ||
.map(placeNode -> PlacesCommand.Create.from(placeNode.locationNode(), placeNode.placeNode())) | ||
.toList(); | ||
} | ||
} |
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
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
12 changes: 12 additions & 0 deletions
12
src/main/java/team7/inplace/crawling/client/dto/PlaceNode.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package team7.inplace.crawling.client.dto; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
public record PlaceNode( | ||
JsonNode locationNode, | ||
JsonNode placeNode | ||
) { | ||
public static PlaceNode of(JsonNode locationNode, JsonNode placeNode) { | ||
return new PlaceNode(locationNode, placeNode); | ||
} | ||
} |
Oops, something went wrong.