From 805808bb74251ea2a14d95cef85a9a7be3e99efc Mon Sep 17 00:00:00 2001 From: MarcWeberFS Date: Tue, 12 Nov 2024 01:27:07 +0100 Subject: [PATCH 1/2] set environment variables for python script inside of docker container --- .github/workflows/deploy.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6d7566c..35c5070 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -54,6 +54,8 @@ jobs: USER: ${{ secrets.AWS_EC2_USER }} AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} AWS_REGION: ${{ secrets.AWS_REGION }} + INSTAGRAM_USERNAME: ${{ secrets.INSTAGRAM_USERNAME }} + INSTAGRAM_PASSWORD: ${{ secrets.INSTAGRAM_PASSWORD }} run: | echo "${{ secrets.AWS_EC2_PEM }}" > /tmp/key.pem chmod 600 /tmp/key.pem @@ -68,6 +70,13 @@ jobs: docker rm backend frontend || true docker pull $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/video-downloader-backend docker pull $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/video-downloader-frontend - docker run -d --network=my-app-network --name backend -p 8080:8080 $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/video-downloader-backend - docker run -d --network=my-app-network --name frontend -p 80:80 $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/video-downloader-frontend + + # Run backend and frontend with Instagram credentials passed as environment variables + docker run -d --network=my-app-network --name backend -p 8080:8080 \ + -e INSTAGRAM_USERNAME="$INSTAGRAM_USERNAME" \ + -e INSTAGRAM_PASSWORD="$INSTAGRAM_PASSWORD" \ + $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/video-downloader-backend + + docker run -d --network=my-app-network --name frontend -p 80:80 \ + $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/video-downloader-frontend EOF From 982109043197b7170e97bcbd8d55642c2ad5c0eb Mon Sep 17 00:00:00 2001 From: MarcWeberFS Date: Tue, 12 Nov 2024 14:16:29 +0100 Subject: [PATCH 2/2] transcription delegate that sends a transcription to AWS. --- video-downloader-backend/pom.xml | 9 ++ .../controller/VideoDownloadController.java | 2 +- .../InstagramVideoDownloaderDelegate.java | 3 + .../delegates/TranscribeVideoDelegate.java | 42 +++++++ .../resources/InstagramDownloadWorkflow.bpmn | 118 ++++++++++-------- 5 files changed, 120 insertions(+), 54 deletions(-) create mode 100644 video-downloader-backend/src/main/java/ch/marc/delegates/TranscribeVideoDelegate.java diff --git a/video-downloader-backend/pom.xml b/video-downloader-backend/pom.xml index 6e79237..6a6dfc9 100644 --- a/video-downloader-backend/pom.xml +++ b/video-downloader-backend/pom.xml @@ -42,6 +42,15 @@ org.springframework.boot spring-boot-starter-jdbc + + + software.amazon.awssdk + transcribe + 2.29.9 + + + + diff --git a/video-downloader-backend/src/main/java/ch/marc/controller/VideoDownloadController.java b/video-downloader-backend/src/main/java/ch/marc/controller/VideoDownloadController.java index d908132..071a626 100644 --- a/video-downloader-backend/src/main/java/ch/marc/controller/VideoDownloadController.java +++ b/video-downloader-backend/src/main/java/ch/marc/controller/VideoDownloadController.java @@ -29,7 +29,7 @@ public class VideoDownloadController { public ResponseEntity> startDownloadProcess(@RequestParam("url") String url) { Map variables = new HashMap<>(); variables.put("url", url); - variables.put("advanced", false); + variables.put("advanced", true); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process_1ua4l8j", variables); Map response = new HashMap<>(); diff --git a/video-downloader-backend/src/main/java/ch/marc/delegates/InstagramVideoDownloaderDelegate.java b/video-downloader-backend/src/main/java/ch/marc/delegates/InstagramVideoDownloaderDelegate.java index e1a4e23..5e3fc24 100644 --- a/video-downloader-backend/src/main/java/ch/marc/delegates/InstagramVideoDownloaderDelegate.java +++ b/video-downloader-backend/src/main/java/ch/marc/delegates/InstagramVideoDownloaderDelegate.java @@ -22,6 +22,9 @@ public void execute(DelegateExecution execution) throws Exception { String s3BucketName = "video-download-temp"; String s3Folder = "instagram-videos"; + execution.setVariable("bucketName", s3BucketName); + execution.setVariable("folder", s3Folder); + String result = downloadInstagramVideo(url, s3BucketName, s3Folder); System.out.println("Download result: " + result); diff --git a/video-downloader-backend/src/main/java/ch/marc/delegates/TranscribeVideoDelegate.java b/video-downloader-backend/src/main/java/ch/marc/delegates/TranscribeVideoDelegate.java new file mode 100644 index 0000000..a4d4bd5 --- /dev/null +++ b/video-downloader-backend/src/main/java/ch/marc/delegates/TranscribeVideoDelegate.java @@ -0,0 +1,42 @@ +package ch.marc.delegates; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.springframework.stereotype.Component; + +import software.amazon.awssdk.services.transcribe.TranscribeClient; +import software.amazon.awssdk.services.transcribe.model.*; + +@Component +public class TranscribeVideoDelegate implements JavaDelegate { + + @Override + public void execute(DelegateExecution execution) { + String downloadLink = (String) execution.getVariable("downloadLink"); + + String s3Uri = downloadLink.replace("https://video-download-temp.s3.amazonaws.com/", "s3://video-download-temp/"); + + TranscribeClient transcribeClient = TranscribeClient.builder().build(); + + StartTranscriptionJobRequest transcriptionJobRequest = StartTranscriptionJobRequest.builder() + .transcriptionJobName("TranscriptionJob_" + System.currentTimeMillis()) + .languageCode(LanguageCode.EN_US) + .mediaFormat(MediaFormat.MP4) + .media(Media.builder().mediaFileUri(s3Uri).build()) + .subtitles(Subtitles.builder().formats(SubtitleFormat.SRT).build()) + .build(); + + try { + StartTranscriptionJobResponse transcriptionJobResponse = transcribeClient.startTranscriptionJob(transcriptionJobRequest); + System.out.println("Transcription job started with ID: " + transcriptionJobResponse.transcriptionJob().transcriptionJobName()); + + execution.setVariable("transcriptionJobId", transcriptionJobResponse.transcriptionJob().transcriptionJobName()); + + } catch (TranscribeException e) { + System.err.println("Error starting transcription job: " + e.awsErrorDetails().errorMessage()); + throw new RuntimeException("Transcription job failed", e); + } finally { + transcribeClient.close(); + } + } +} diff --git a/video-downloader-backend/src/main/resources/InstagramDownloadWorkflow.bpmn b/video-downloader-backend/src/main/resources/InstagramDownloadWorkflow.bpmn index b3f4534..a70accc 100644 --- a/video-downloader-backend/src/main/resources/InstagramDownloadWorkflow.bpmn +++ b/video-downloader-backend/src/main/resources/InstagramDownloadWorkflow.bpmn @@ -18,36 +18,31 @@ Flow_0y4bow3 Flow_1wi0v5y - + - Flow_160xutx - Flow_1kmn8mj + Flow_1wi0v5y + Flow_1g1t3hq - Flow_1kmn8mj + Flow_1pf7l1x - - Flow_1wi0v5y + Flow_1g1t3hq Flow_0sarfuf Flow_0k0ot69 ${advanced==false} - - Flow_0k0ot69 - Flow_1rdrtnn - ${advanced==true} - Flow_1rdrtnn + Flow_1nknvr7 Flow_0q66msg - + Flow_0q66msg Flow_1nnbcnd @@ -56,10 +51,20 @@ Flow_0sarfuf Flow_1nnbcnd - Flow_160xutx + Flow_1pf7l1x - + + Flow_1rdrtnn + Flow_1nknvr7 + + + + Flow_0k0ot69 + Flow_1rdrtnn + + + @@ -70,76 +75,83 @@ + + + - + - - - - - + + + + + - + - + - - - - - + + + + + - + - - - - - - + + - + - - + + + + + + + + + + + + + + + - - - + + + - - - + + + - - - - - - + + - - - - + + +