Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding OIL to Autosubs #131

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ sign.sh
/Transcription-Server/build
AutoSubs-App/package-lock.json
/Mac-Package/Payload
*.pem
32 changes: 31 additions & 1 deletion AutoSubs-App/src-tauri/resources/AutoSubs V2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,16 @@ function ExportAudio(outputDir)
markIn = renderSettings["MarkIn"],
markOut = renderSettings["MarkOut"]
}

local renderingLoops = 0
while project:IsRenderingInProgress() do
print("Rendering...")
sleep(0.5) -- Check every 500 milliseconds
renderingLoops = renderingLoops + 1
if renderingLoops > 3 then
print("Render Status")
print(project:GetRenderStatus(pid))
renderingLoops = 0
end
end
end)

Expand Down Expand Up @@ -457,6 +463,13 @@ function AddSubtitles(filePath, trackIndex, templateName, textFormat, removePunc
end
end


-- Add subtitles to the timeline using the specified template
function AddMediaToBin(filePath)
local mediaStorage = resolve:GetMediaStorage()
mediaStorage:AddItemListToMediaPool(filePath)
end

local function set_cors_headers(client)
client:send("HTTP/1.1 200 OK\r\n")
client:send("Access-Control-Allow-Origin: *\r\n")
Expand Down Expand Up @@ -584,6 +597,23 @@ while not quitServer do
body = json.encode({
message = "Job completed"
})
elseif data.func == "GetTimelineStoragePath" then -- this is how davinchi knows what to do. Localhost:55010
print("[AutoSubs Server] Cooked With OIL")

print("Mounted Volume List: ", mountedVolumeList[1])
print("Current Project: ", currentProject)
-- above is where files collected using OIL are stored mountedVolumeList[1]+currentProject
-- Prepare the body for the API request

body = json.encode({
message = "Job completed",
filePath = mountedVolumeList[1] .. '/' .. currentProject
})
elseif data.func == "AddMediaToBin" then -- this is h
AddMediaToBin(data.filePath)
body = json.encode({
message = "Job completed"
})
elseif data.func == "Exit" then
body = json.encode({
message = "Server shutting down"
Expand Down
Binary file added BrowserExtentions/ChromeExtention.crx
Binary file not shown.
197 changes: 197 additions & 0 deletions BrowserExtentions/ChromeExtention/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
// Create context menu items for images and videos
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: "sendMediaToApi",
title: "Send URL to Local API",
contexts: ["image", "video"], // Show menu on right-clicking images or videos
});

chrome.contextMenus.create({
id: 'exit',
title: 'Exit',
contexts: ["image", "video"]
});
});

function makenotifications(title, message) {
chrome.notifications.create(
{
type: "basic",
iconUrl: "images/icon-128x128.png",
title: title,
message: message,
priority: 2,
},
(notificationId) => {
// Clear the notification after 3 seconds
setTimeout(() => {
chrome.notifications.clear(notificationId);
}, 3000);
}
);
}



chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
if (changeInfo.status === "complete") {
chrome.scripting
.executeScript({
target: { tabId },
files: ["./content.js"],
})
.then(() => {
console.log("content script injected");
})
.catch((err) => console.log(err, "error injecting script"));
}
});

// Handle the context menu click
chrome.contextMenus.onClicked.addListener((info) => {
console.log(info);
if (info.menuItemId === "sendMediaToApi" && info.srcUrl) {
const mediaUrl = info.srcUrl; // URL of the image or video
sendStringToApi('save_image',mediaUrl).then((result) => {
if (result != "true") {
console.log(result);
const title = "Failed To send, check if localhost is running";
const message =
"Failed to send media URL. Please check if the local API is running.";
makenotifications(title, message);
}
});
}
else if (info.menuItemId === 'exit') {
exit().then((result) => {
if (result != "true") {
console.log(result);
const title = "Failed To exit, check if localhost is running";
const message =
"Failed to exit. Please check if the local API is running.";
makenotifications(title, message);
}
});
}
});

chrome.commands.onCommand.addListener((command) => {
console.log(`Command: ${command}`);
if (command === "open-screen-captue") {
// Get the current active tab
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs.length > 0) {
const currentTab = tabs[0];
console.log("Current Tab:", currentTab);

// Perform any action with the current tab
// For example, you can send a message to the content script
chrome.tabs.sendMessage(
currentTab.id,
{ action: "recording_request" },
(response) => {
if (chrome.runtime.lastError) {
console.error(
"Error sending message:",
chrome.runtime.lastError.message
);
const title = "Screen Recorder Error";
const message =
"Failed to start screen recording. Please refresh the page, or go to a different tab to start capture.";
makenotifications(title, message);
} else {
console.log("Response from content script:", response);
if (response === undefined) {
const title = "cannot start capture on base chrome pages";
const message =
"Failed to start screen recording. Please or go to a different tab or page to start capture.";
makenotifications(title, message);
}
}
}
);

chrome.action.openPopup();
console.log("Popup opened");
} else {
console.error("No active tab found");
}
});
}
});

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "get_tab_title") {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs.length > 0) {
sendResponse({ tabTitle: tabs[0].title });
} else {
sendResponse({ tabTitle: null });
}
});
return true; // Keep the message channel open for sendResponse
//the file save name to send to the backend.
} else if (message.action === "save_name") {
sendStringToApi('save_video',message.saveName).then((result) => {
if (result != "true") {
console.log(result);
const title = "Failed To send filename, check if localhost is running";
const message =
"Failed to send filename. Please check if the local API is running.";
makenotifications(title, message);
}
});
}
});
function exit() {
const apiUrl = `http://localhost:55000`; // Replace with your local API endpoint
console.log("Sending exit to API:", apiUrl);
return fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
func: 'Exit',
}),
})
.then((response) => {
if (response.ok) {
console.log("stringSent sent successfully!");
return "true";
} else {
console.error("Failed to send stringSent:", response.status);
return response.status;
}
})
.catch((error) => {
console.error("Error:", error);
return error;
});
}
function sendStringToApi(apiPath,stringSent) {
const apiUrl = `http://localhost:55000`; // Replace with your local API endpoint
console.log("Sending stringSent to API:", apiUrl);
return fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
func: 'save_image',
releventString: stringSent }),
})
.then((response) => {
if (response.ok) {
console.log("stringSent sent successfully!");
return "true";
} else {
console.error("Failed to send stringSent:", response.status);
return response.status;
}
})
.catch((error) => {
console.error("Error:", error);
return error;
});
}
111 changes: 111 additions & 0 deletions BrowserExtentions/ChromeExtention/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
console.log("content script running");

var recorder = null;

function onAccessApproved(stream) {
recorder = new MediaRecorder(stream, {
videoBitsPerSecond: 5000000,
ignoreMutedMedia: true,
mimeType: "video/webm;codecs=h264,vp9,opus",
});

recorder.start();

recorder.onstop = function () {
stream.getTracks().forEach(function (track) {
if (track.readyState === "live") {
track.stop();
}
});
};

recorder.ondataavailable = function (event) {
let recordedData = event.data;
let url = URL.createObjectURL(recordedData);
// Get the current tab's title
chrome.runtime.sendMessage({ action: "get_tab_title" }, (response) => {
if (response && response.tabTitle) {
let tabTitle = response.tabTitle;
// Clean the tab title to make it a valid file name
let cleanedTitle = tabTitle.replace(/[^a-z0-9]/gi, "_").toLowerCase();

let a = document.createElement("a");
a.style.display = "none";
a.href = url;
a.download = `${cleanedTitle}.mp4`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
chrome.runtime.sendMessage({ action: "save_name", saveName: a.download });
} else {
console.error("Failed to get tab title");
let a = document.createElement("a");
a.style.display = "none";
a.href = url;
a.download = "screen-recording.mp4";
document.body.append(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
chrome.runtime.sendMessage({ action: "save_name", saveName: a.download });
}
});
};
}

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "recording_request") {
console.log("recording requested");
sendResponse(`seen: ${message.action}`);

navigator.mediaDevices
.getDisplayMedia({
audio: true,
video: true,
})
.then((stream) => {
onAccessApproved(stream);
});
}

if (message.action === "stop_recording") {
console.log("Stop recording");
sendResponse(`seen: ${message.action}`);

if (!recorder) {
return console.log("no recording");
} else {
recorder.stop();
}
}
});

chrome.commands.onCommand.addListener((command) => {
console.log(`Command: ${command}`);
console.log(bool(command === "open-screen-captue"));
if (command === "open-screen-captue") {
console.log("recording requested");
sendResponse(`seen: ${command}`);

navigator.mediaDevices
.getDisplayMedia({
audio: true,
video: true,
})
.then((stream) => {
onAccessApproved(stream);
});
}

if (command === "end-screen-captue") {
console.log("Stop recording");
sendResponse(`seen: ${command}`);

if (!recorder) {
return console.log("no recording");
} else {
recorder.stop();
}
}
});
17 changes: 17 additions & 0 deletions BrowserExtentions/ChromeExtention/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

.content{
min-width: 250px;
padding: 5px;

}

.button button{
background: black;
padding: 5px;
border-radius: 5px;
color: yellow;
}

.button button:hover{
box-shadow: 1px 0px 5p gray;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading