Skip to content

Commit 2209951

Browse files
authored
Merge pull request #6 from deployment-helper/dev
Dev
2 parents a2ac7d6 + 47c8063 commit 2209951

File tree

3 files changed

+242
-57
lines changed

3 files changed

+242
-57
lines changed

app-management/apps/app-management/src/workflows/workflows.controller.ts

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import { execSync } from 'child_process';
1212
import { ChatgptService } from '@app/shared/openapi/chatgpt.service';
1313
import { FirestoreService } from '@app/shared/gcp/firestore.service';
1414
import { IScenes, IVideo } from '@app/shared/types';
15+
import { v4 as uuidv4 } from 'uuid';
1516
import { AuthGuard } from '@apps/app-management/auth/auth.guard';
17+
import _ from 'lodash';
1618

1719
console.log("outside workflows controller");
1820
function cleanSubtitles(lines: string[]): string[] {
@@ -46,37 +48,54 @@ export class WorkflowsController {
4648
@Post("youtube")
4749
// project_name: string
4850
async createVideoFromYouTube(
49-
@Body() data: { videoURL: string },
51+
@Body() data: { videoURL: string, projectID: string, promptType: string="story" },
5052
@Req() req: any,
5153
) {
52-
////yt-dlp --write-auto-sub --skip-download --sub-lang en --convert-subs srt -o "subtitle.srt" https://www.youtube.com/watch\?v\=HnQcJ03oEUo
53-
//const stdout = execSync('yt-dlp --write-auto-sub --skip-download --sub-lang en --convert-subs srt -o "subtitle.srt" ' + data.videoURL);
5454

55-
//// Example subtitle lines (replace this with your actual subtitle lines)
56-
//const srtFilePath = path.join('subtitle.srt.en.srt');
57-
//const lines: string[] = fs.readFileSync(srtFilePath);
55+
//yt-dlp --write-auto-sub --skip-download --sub-lang en --convert-subs srt -o "subtitle.srt" https://www.youtube.com/watch\?v\=HnQcJ03oEUo
56+
const stdout = execSync('yt-dlp --write-auto-sub --skip-download --sub-lang en --convert-subs srt -o "subtitle.srt" ' + data.videoURL);
5857

59-
//// Clean the lines
60-
//const cleanedLines = cleanSubtitles(lines.toString().split("\n"));
58+
// Example subtitle lines (replace this with your actual subtitle lines)
59+
const srtFilePath = path.join('subtitle.srt.en.srt');
60+
const lines: string[] = fs.readFileSync(srtFilePath);
61+
62+
// Clean the lines
63+
const cleanedLines = cleanSubtitles(lines.toString().split("\n"));
6164

6265
// Save the cleaned subtitles to a new file
6366
const cleanedFilePath = path.join('cleaned_subtitle.srt');
64-
//fs.writeFileSync(cleanedFilePath, cleanedLines.join(''));
65-
//const scriptData = this.chatgptService.generateScenesScript(cleanedFilePath);
66-
const scriptData = {
67-
"Title": "The Power of Adversity",
68-
"Hook": "Have you ever felt like life’s challenges are just too overwhelming? Imagine turning those challenges into your greatest strengths. Stay with us to find out how!",
69-
"Introduction": "Once upon a time, a young man named John was feeling overwhelmed by the constant struggles in his career. Day after day, he faced one problem after another, leaving him exhausted and disheartened. One evening, he sat down with his father, an experienced chef known for his wisdom, and poured out his frustrations. \"Dad, I feel so overwhelmed. Every single day feels like a battle I can't win. Just when I think I've solved one problem, another one hits me. I'm exhausted, and I don't know how much more I can handle,\" he said, his voice filled with despair. His father looked at him with compassionate eyes, understanding the weight his son carried on his shoulders.",
70-
"Action": "Without saying a word, John's father stood up and led him to the kitchen. He filled three pots with water and placed them on the stove over high heat. John followed him, puzzled but curious. As the water began to boil, his father added potatoes to one pot, eggs to the second, and coffee beans to the third. John stood there, a mix of curiosity and confusion on his face, as he watched his father’s every move. 'What is he up to?' he wondered. The kitchen filled with the rising steam and the soft bubbling sounds of the boiling water.",
71-
"Observation": "After twenty minutes, his father turned off the burners. He took the potatoes out of the pot and placed them in a bowl. Then, he did the same with the eggs, and finally, he poured the coffee into a cup. Turning to John, he gently smiled, his eyes filled with understanding and warmth. \"John, come closer and touch the potatoes,\" he said softly. John tentatively reached out, feeling the soft, mushy texture of the potato. His father then handed him an egg. With a slight frown of concentration, John cracked it open and marveled at the hard, solid interior. Finally, his father asked him to sip the coffee. John took a sip, and a smile spread across his face as he savored the rich aroma and taste.",
72-
"Moral Lesson": "\"John,\" his father began, his voice gentle yet firm, \"each of these items faced the same boiling water, but they responded differently. It's not the adversity that defines you, but how you respond to it. The potato went in strong and hard but came out soft and weak. The egg was fragile with its liquid interior, but after being boiled, it became hard. The coffee beans, however, were unique. After they were exposed to the boiling water, they transformed it into something new and wonderful.\"",
73-
"Application": "His father continued, \"Which one are you? When adversity knocks on your door, how do you respond? Are you like the potato that becomes weak? Or the egg that becomes hardened and bitter? Or are you like the coffee bean that changes the environment around it, creating something positive from the hardship?\" He paused, letting the words sink in. \"Life will always throw challenges our way,\" he added, \"but it's our response to these trials that truly shapes who we are.\"",
74-
"Extended Reflection": "John looked down at the items in front of him, deep in thought. His mind wandered to the countless times he had felt like giving up, the moments when he felt broken and defeated. \"I think I understand now,\" he said quietly. \"I've been acting like the potato, strong on the outside but crumbling under pressure.\" His father nodded. \"It's a common response, son. Many people face their challenges and feel overwhelmed, losing their strength. But remember, you have the power to change your response.\" John's thoughts shifted to his friend, Sarah, who had recently lost her job. Despite her initial despair, she had taken the time to learn new skills and eventually started a successful business. She had become like the coffee bean, transforming her adversity into an opportunity for growth. Inspired by her resilience, John felt a newfound determination brewing within him.",
75-
"Incorporating Personal Growth": "\"From now on, I want to be like the coffee bean,\" John declared. \"I want to face my challenges head-on and use them to become stronger and better.\" His father smiled proudly. \"That's the spirit, John. Remember, every challenge you face is an opportunity to grow and improve. You have the strength within you to transform any situation.\"",
76-
"Motivational Dialogues": "Buddha said: \"The mind is everything. What you think you become.\" Better if we see in our lives, we will find that we often face challenges and adversities, but it is our reaction to these challenges that truly defines us. How we respond to problems is what really matters. There are three kinds of people in the world: the first kind is like a potato; they seem strong at first but become weak when facing adversity. The second kind is like eggs; they start off soft but difficulties make them hard and often bitter or frustrated. The third type is like coffee beans; they face adversity bravely and use it as an opportunity to grow and improve. Buddha said: \"In the confrontation between the stream and the rock, the stream always wins – not through strength but by perseverance.\" If we can learn from our experiences, adapt to new situations, and make the best out of every challenge, then we can not only improve ourselves but also inspire and positively influence those around us. Life is full of challenges, but it is up to us to decide how we will react and what we will make of it. Buddha said: \"Pain is inevitable. Suffering is optional.\" We have the power to choose our response and shape our future. So, will you let adversity weaken you, harden you, or transform you into something better? The choice is yours.",
77-
"Conclusion": "John left the kitchen with a new perspective. He realized that he had the power to change his circumstances, not by avoiding difficulties, but by facing them head-on and using them as opportunities to grow and improve. From that day forward, he decided to be like the coffee bean, transforming his challenges into strengths and positively influencing those around him. \"Thank you, Dad,\" he said with gratitude. \"I won't forget this lesson.\"",
78-
"Call to Action": "If you found this story inspiring, make sure to give it a thumbs up and share it with your friends. And don’t forget to subscribe to our channel for more motivational content like this. Hit the bell icon so you never miss an update! What kind of person are you – a potato, an egg, or a coffee bean? Let us know in the comments below!"
79-
};
67+
fs.writeFileSync(cleanedFilePath, cleanedLines.join(''));
68+
const promptPath = "prompt.txt";
69+
const rawData = JSON.parse(await this.chatgptService.generateScenesScript(cleanedFilePath, promptPath));
70+
let scriptData = {};
71+
scriptData["Title"] = rawData["Title"];
72+
scriptData["Hook"] = rawData["Hook"];
73+
scriptData["Introduction"] = rawData["Introduction"];
74+
scriptData["Action"] = rawData["Action"];
75+
scriptData["Observation"] = rawData["Observation"];
76+
scriptData["Moral Lesson"] = rawData["Moral Lesson"];
77+
scriptData["Application"] = rawData["Application"];
78+
scriptData["Extended Reflection"] = rawData["Extended Reflection"];
79+
scriptData["Incorporating Personal Growth"] = rawData["Incorporating Personal Growth"];
80+
scriptData["Motivational Dialogues"] = rawData["Motivational Dialogues"];
81+
scriptData["Conclusion"] = rawData["Conclusion"];
82+
scriptData["Call to Action"] = rawData["Call to Action"];
83+
//const scriptData = {
84+
// "Title": "The Power of Adversity",
85+
// "Hook": "Have you ever felt like life’s challenges are just too overwhelming? Imagine turning those challenges into your greatest strengths. Stay with us to find out how!",
86+
// "Introduction": "Once upon a time, a young man named John was feeling overwhelmed by the constant struggles in his career. Day after day, he faced one problem after another, leaving him exhausted and disheartened. One evening, he sat down with his father, an experienced chef known for his wisdom, and poured out his frustrations. \"Dad, I feel so overwhelmed. Every single day feels like a battle I can't win. Just when I think I've solved one problem, another one hits me. I'm exhausted, and I don't know how much more I can handle,\" he said, his voice filled with despair. His father looked at him with compassionate eyes, understanding the weight his son carried on his shoulders.",
87+
// "Action": "Without saying a word, John's father stood up and led him to the kitchen. He filled three pots with water and placed them on the stove over high heat. John followed him, puzzled but curious. As the water began to boil, his father added potatoes to one pot, eggs to the second, and coffee beans to the third. John stood there, a mix of curiosity and confusion on his face, as he watched his father’s every move. 'What is he up to?' he wondered. The kitchen filled with the rising steam and the soft bubbling sounds of the boiling water.",
88+
// "Observation": "After twenty minutes, his father turned off the burners. He took the potatoes out of the pot and placed them in a bowl. Then, he did the same with the eggs, and finally, he poured the coffee into a cup. Turning to John, he gently smiled, his eyes filled with understanding and warmth. \"John, come closer and touch the potatoes,\" he said softly. John tentatively reached out, feeling the soft, mushy texture of the potato. His father then handed him an egg. With a slight frown of concentration, John cracked it open and marveled at the hard, solid interior. Finally, his father asked him to sip the coffee. John took a sip, and a smile spread across his face as he savored the rich aroma and taste.",
89+
// "Moral Lesson": "\"John,\" his father began, his voice gentle yet firm, \"each of these items faced the same boiling water, but they responded differently. It's not the adversity that defines you, but how you respond to it. The potato went in strong and hard but came out soft and weak. The egg was fragile with its liquid interior, but after being boiled, it became hard. The coffee beans, however, were unique. After they were exposed to the boiling water, they transformed it into something new and wonderful.\"",
90+
// "Application": "His father continued, \"Which one are you? When adversity knocks on your door, how do you respond? Are you like the potato that becomes weak? Or the egg that becomes hardened and bitter? Or are you like the coffee bean that changes the environment around it, creating something positive from the hardship?\" He paused, letting the words sink in. \"Life will always throw challenges our way,\" he added, \"but it's our response to these trials that truly shapes who we are.\"",
91+
// "Extended Reflection": "John looked down at the items in front of him, deep in thought. His mind wandered to the countless times he had felt like giving up, the moments when he felt broken and defeated. \"I think I understand now,\" he said quietly. \"I've been acting like the potato, strong on the outside but crumbling under pressure.\" His father nodded. \"It's a common response, son. Many people face their challenges and feel overwhelmed, losing their strength. But remember, you have the power to change your response.\" John's thoughts shifted to his friend, Sarah, who had recently lost her job. Despite her initial despair, she had taken the time to learn new skills and eventually started a successful business. She had become like the coffee bean, transforming her adversity into an opportunity for growth. Inspired by her resilience, John felt a newfound determination brewing within him.",
92+
// "Incorporating Personal Growth": "\"From now on, I want to be like the coffee bean,\" John declared. \"I want to face my challenges head-on and use them to become stronger and better.\" His father smiled proudly. \"That's the spirit, John. Remember, every challenge you face is an opportunity to grow and improve. You have the strength within you to transform any situation.\"",
93+
// "Motivational Dialogues": "Buddha said: \"The mind is everything. What you think you become.\" Better if we see in our lives, we will find that we often face challenges and adversities, but it is our reaction to these challenges that truly defines us. How we respond to problems is what really matters. There are three kinds of people in the world: the first kind is like a potato; they seem strong at first but become weak when facing adversity. The second kind is like eggs; they start off soft but difficulties make them hard and often bitter or frustrated. The third type is like coffee beans; they face adversity bravely and use it as an opportunity to grow and improve. Buddha said: \"In the confrontation between the stream and the rock, the stream always wins – not through strength but by perseverance.\" If we can learn from our experiences, adapt to new situations, and make the best out of every challenge, then we can not only improve ourselves but also inspire and positively influence those around us. Life is full of challenges, but it is up to us to decide how we will react and what we will make of it. Buddha said: \"Pain is inevitable. Suffering is optional.\" We have the power to choose our response and shape our future. So, will you let adversity weaken you, harden you, or transform you into something better? The choice is yours.",
94+
// "Conclusion": "John left the kitchen with a new perspective. He realized that he had the power to change his circumstances, not by avoiding difficulties, but by facing them head-on and using them as opportunities to grow and improve. From that day forward, he decided to be like the coffee bean, transforming his challenges into strengths and positively influencing those around him. \"Thank you, Dad,\" he said with gratitude. \"I won't forget this lesson.\"",
95+
// "Call to Action": "If you found this story inspiring, make sure to give it a thumbs up and share it with your friends. And don’t forget to subscribe to our channel for more motivational content like this. Hit the bell icon so you never miss an update! What kind of person are you – a potato, an egg, or a coffee bean? Let us know in the comments below!"
96+
//};
97+
console.log("scriptData before stringify " + scriptData);
98+
console.log("scriptData " + JSON.stringify(scriptData));
8099
const videoTitle = scriptData.Title;
81100
let sceneDescriptions = [];
82101
const keys = Object.keys(scriptData);
@@ -87,14 +106,20 @@ export class WorkflowsController {
87106
sceneDescriptions[i] = scriptData[key];
88107
}
89108
}
90-
//return { title: videoTitle, sceneDescriptions: sceneDescriptions};
109+
110+
// get the Project
111+
const project = await this.fireStore.get('project', data.projectID);
91112

92113
// Create the video
93114
const videoData = {
94-
"projectId": "8OA2kJwJS3J7AosAL7Ye",
95-
"projectName": "KidStories",
115+
"projectId": project.id,
116+
"projectName": project.projectName,
96117
"name": videoTitle,
97-
"description": videoTitle
118+
"description": videoTitle,
119+
"backgroundMusic": project.defaultBackgroundMusic, //"https://vm-presentations.s3.ap-south-1.amazonaws.com/public/background-music/deep-meditation-192828.mp3",
120+
"overlay": project.defaultOverlay, //"https://vm-presentations.s3.ap-south-1.amazonaws.com/public/7aebc7e3-86a8-4e2b-9994-634e7aeda3f2.mov",
121+
"audioLanguage": project.defaultLanguage, //"en-US",
122+
"voiceCode": project.defaultVoice, //"en-US-Journey-F",
98123
}
99124

100125
const video = await this.fireStore.add('video', {
@@ -110,54 +135,31 @@ export class WorkflowsController {
110135

111136
const updatedVideo = this.fireStore.update('video', video.id, { scenesId: scenes.id });
112137

113-
const project = await this.fireStore.get('project', "8OA2kJwJS3J7AosAL7Ye");
114138
sceneDescriptions = sceneDescriptions.filter(function(item){ return item != null})
115-
console.log("in workflows controller");
116139
for(let i=0;i<sceneDescriptions.length;i++){
140+
let image = project?.assets[Math.ceil(Math.random()*1000)%project?.assets?.length];
117141
if(sceneDescriptions[i]){
118142
await this.fireStore.updateScene(
119143
`video/${video.id}/scenes`,
120144
scenes.id,
121145
{
146+
"id": uuidv4(),
122147
"content": {
123148
"image": {
124149
"type": "image",
125150
"name": "image",
126-
"value": project?.assets[Math.ceil(Math.random()*1000)%project?.assets?.length],//"https://via.placeholder.com/150",
151+
"value": image,
127152
"placeholder": "Image"
128153
}
129154
},
130155
"description": sceneDescriptions[i],
156+
"image": image,
131157
"layoutId": "layout2"
132158
}
133-
//sceneArrayIndex,
134-
//addAfter,
135159
);
136160
}
137161
}
138162
return video;
139-
//return sceneDescriptions.filter(function(item){ return item != null});
140-
141-
//return this.fireStore.update('video', video.id, { scenesId: scenes.id });
142-
143-
//
144-
//Create Scenes
145-
//{
146-
//"id": "16c09b6c-30b2-467a-aa87-4f25847f14d4",
147-
//"content": {
148-
// "image": {
149-
// "type": "image",
150-
// "name": "image",
151-
// "value": "https://via.placeholder.com/150",
152-
// "placeholder": "Image"
153-
// }
154-
//},
155-
//"description": "Desc",
156-
//"layoutId": "layout2"
157-
//}
158-
//this.fireStore.add(`video/${id}/scenes`, data);
159-
//return this.chatgptService.generateScenesScript(cleanedFilePath);
160-
//return {content: fs.readFileSync(cleanedFilePath).toString()};
161163
}
162164

163165
@Get("list")

0 commit comments

Comments
 (0)