-
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.
- Loading branch information
Showing
10 changed files
with
109 additions
and
37 deletions.
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/com/example/BriefMe/controllers/YoutubeVideoSummaryController.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,24 @@ | ||
package com.example.BriefMe.controllers; | ||
|
||
import com.example.BriefMe.service.client.YoutubeVideoSummaryService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
public class YoutubeVideoSummaryController { | ||
|
||
@Autowired | ||
YoutubeVideoSummaryService youtubeVideoSummaryService; | ||
|
||
@GetMapping("/get-summary") | ||
public ResponseEntity<String> generateSummary(@RequestParam String video, @RequestParam int lines){ | ||
String summary = youtubeVideoSummaryService.generateSummary(video, lines); | ||
return ResponseEntity.ok(summary); | ||
} | ||
|
||
} |
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
5 changes: 5 additions & 0 deletions
5
backend/src/main/java/com/example/BriefMe/service/client/YoutubeVideoSummaryService.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,5 @@ | ||
package com.example.BriefMe.service.client; | ||
|
||
public interface YoutubeVideoSummaryService { | ||
String generateSummary(String youtubeVideoUrl, int summarizeIn); | ||
} |
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
44 changes: 26 additions & 18 deletions
44
backend/src/main/java/com/example/BriefMe/service/impl/Mp4AudioExtractorImpl.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 |
---|---|---|
@@ -1,36 +1,44 @@ | ||
package com.example.BriefMe.service.impl; | ||
|
||
import com.example.BriefMe.service.client.AudioExtractor; | ||
import java.io.IOException; | ||
import java.util.UUID; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.bramp.ffmpeg.FFmpeg; | ||
import net.bramp.ffmpeg.FFmpegExecutor; | ||
import net.bramp.ffmpeg.FFprobe; | ||
import net.bramp.ffmpeg.builder.FFmpegBuilder; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
public class Mp4AudioExtractorImpl implements AudioExtractor { | ||
|
||
public static final String OUTPUT_FILE = "output-"; | ||
public static final String DOT = "."; | ||
public static final String MP_3 = "mp3"; | ||
|
||
@Override | ||
public String extractAudio(String inputVideoFile) throws IOException { | ||
FFmpeg ffmpeg = new FFmpeg("/opt/homebrew/bin/ffmpeg"); | ||
FFprobe ffprobe = new FFprobe(); | ||
|
||
String outputFile = OUTPUT_FILE + UUID.randomUUID() + DOT + MP_3; | ||
|
||
FFmpegBuilder builder = new FFmpegBuilder() | ||
.setInput(inputVideoFile) | ||
.overrideOutputFiles(true) | ||
.addOutput(outputFile) | ||
.setFormat(MP_3) | ||
.done(); | ||
|
||
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe); | ||
executor.createJob(builder).run(); | ||
|
||
return outputFile; | ||
public String extractAudio(String inputVideoFile) { | ||
try{ | ||
FFmpeg ffmpeg = new FFmpeg("/opt/homebrew/bin/ffmpeg"); | ||
FFprobe ffprobe = new FFprobe(); | ||
|
||
String outputFile = OUTPUT_FILE + UUID.randomUUID() + DOT + MP_3; | ||
|
||
FFmpegBuilder builder = new FFmpegBuilder() | ||
.setInput(inputVideoFile) | ||
.overrideOutputFiles(true) | ||
.addOutput(outputFile) | ||
.setFormat(MP_3) | ||
.done(); | ||
|
||
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe); | ||
executor.createJob(builder).run(); | ||
|
||
return outputFile; | ||
}catch(Exception e){ | ||
log.error("Unable to extract audio from the link. Exception occured. {}", e.getMessage()); | ||
return ""; | ||
} | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
backend/src/main/java/com/example/BriefMe/service/impl/YoutubeVideoSummaryServiceImpl.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,34 @@ | ||
package com.example.BriefMe.service.impl; | ||
|
||
import com.example.BriefMe.service.client.AudioExtractor; | ||
import com.example.BriefMe.service.client.AudioToTextConverter; | ||
import com.example.BriefMe.service.client.TextSummarizer; | ||
import com.example.BriefMe.service.client.YoutubeVideoSummaryService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@Service | ||
public class YoutubeVideoSummaryServiceImpl implements YoutubeVideoSummaryService { | ||
|
||
@Autowired | ||
AudioExtractor audioExtractor; | ||
|
||
@Autowired | ||
AudioToTextConverter audioToTextConverter; | ||
|
||
@Autowired | ||
TextSummarizer textSummarizer; | ||
|
||
@Override | ||
public String generateSummary(String youtubeVideoUrl, int summarizeIn) { | ||
String audioFile = audioExtractor.extractAudio(youtubeVideoUrl); | ||
String text = audioToTextConverter.covertAudioToText(audioFile); | ||
String summary = textSummarizer.generateSummary(text, summarizeIn); | ||
|
||
log.info("Text summarization completed..."); | ||
|
||
return summary; | ||
} | ||
} |