Skip to content

Commit

Permalink
Change libvorbis to mp3
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh14901 committed Dec 16, 2021
1 parent 0458889 commit 9e11a45
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 39 deletions.
10 changes: 6 additions & 4 deletions CLI/cli/audio_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def extract(path, quality="medium"):

try:

output_path = path[:-3] + "ogg"
cmd = [ffmpeg, "-i", path, "-vn", "-acodec", "libvorbis", output_path]
output_path = path[:-3] + "mp3"
cmd = [ffmpeg, "-i", path, "-vn", "-acodec", "mp3", output_path]
if os.path.exists(output_path):
print(
f"[{colored('#','yellow')}] Audio file {colored(path2title(output_path),'green')} already exists"
Expand Down Expand Up @@ -84,7 +84,8 @@ def get_duration(file):
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
).communicate()
try:
time_str = re.search("Duration: (.*), start", time_str[0].decode()).groups()[0]
time_str = re.search("Duration: (.*), start",
time_str[0].decode()).groups()[0]
hours, minutes, seconds = time_str.split(":")
return int(hours) * 3600 + int(minutes) * 60 + float(seconds)
except:
Expand Down Expand Up @@ -126,7 +127,8 @@ def convert_async(paths, args):
with Pool() as pool:
st = time.perf_counter()
print(f"\n[{colored('+','green')}] Extraction of audio started ...")
p = pool.starmap_async(extract, product(paths, [args.q]), callback=files.extend)
p = pool.starmap_async(extract, product(
paths, [args.q]), callback=files.extend)

p.wait()
print(
Expand Down
11 changes: 6 additions & 5 deletions CLI/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ def initialize(videos, server, first=False):
for video in videos:

if args.web:
server.upload(video, video[:-3] + "ogg")
server.upload(video, video[:-3] + "mp3")
else:
server.addAudioPath(video, video[:-3] + "ogg")
TO_CLEAR.append(video[:-3] + "ogg")
server.addAudioPath(video, video[:-3] + "mp3")
TO_CLEAR.append(video[:-3] + "mp3")

platform_dependent(video, linux=player.enqueue)

Expand Down Expand Up @@ -133,7 +133,7 @@ def exitHandler(*args, **kwargs):
if __name__ == "__main__":
print(sys.argv)

platform_dependent(windows=freeze_support,osx=freeze_support)
platform_dependent(windows=freeze_support, osx=freeze_support)

sys.stdout = Unbuffered(sys.stdout)
signal.signal(signal.SIGINT, exitHandler)
Expand All @@ -153,7 +153,8 @@ def exitHandler(*args, **kwargs):
windows=win_util.start_server,
osx=osx_util.start_server,
)
platform_dependent(linux=Process(target=player.update, args=(server,)).start)
platform_dependent(linux=Process(
target=player.update, args=(server,)).start)

initialize([args.f[0]], server=server, first=True)

Expand Down
18 changes: 12 additions & 6 deletions CLI/cli/server_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
SERVER_ADDR = "localhost"

# this is used internally by ServerConnection


class SignalReceiver(socketio.ClientNamespace):
def __init__(self, *args, **kwargs):
self.ARGS = kwargs["params"]
Expand All @@ -26,7 +28,8 @@ def on_createRoom(self, *args, **kwargs):
platform_dependent(
f"start \"\" {url.replace('client','host')}", windows=os.system
)
platform_dependent(f"open \"\" {url.replace('client','host')}", osx=os.system)
platform_dependent(
f"open \"\" {url.replace('client','host')}", osx=os.system)

from util import print_url

Expand Down Expand Up @@ -74,7 +77,8 @@ def on_pause(self, *args, **kwargs):
platform_dependent(linux=self.handle_pause)

def handle_seek(self, state):
seek_time = int(time.time() - state["last_updated"] + state["position"])
seek_time = int(
time.time() - state["last_updated"] + state["position"])
print(
f"[{colored('$','blue')}] Seek signal recieved ==> seeking to {colored(seek_time,'yellow')}"
)
Expand Down Expand Up @@ -129,7 +133,7 @@ def track_change(self, videoPath, state):
)
self.send(
"changeTrack",
{self.tracks[videoPath][0]: self.tracks[videoPath][1], "state": state},
{self.tracks[videoPath][0] : self.tracks[videoPath][1], "state": state},
)

def add_track(self, videoPath):
Expand All @@ -152,13 +156,15 @@ def upload(self, videoPath, audioPath):
import requests

url = f"http://{SERVER_ADDR}:5000/api/upload/"
files = {"file": (path2title(videoPath), open(audioPath, "rb"), "audio/ogg")}
r = requests.post(url=url, files=files, data={"title": path2title(videoPath)})
files = {"file": (path2title(videoPath), open(
audioPath, "rb"), "audio/mp3")}
r = requests.post(url=url, files=files, data={
"title": path2title(videoPath)})

self.tracks[videoPath] = ("trackId", r.json()["trackId"])
print(
f"[{colored('+','green')}] Upload complete for file {colored(path2title(audioPath),'green')}"
)

def addAudioPath(self, videoPath, audioPath):
self.tracks[videoPath] = ("audioPath", audioPath)
self.tracks[videoPath] = ("audioPath", audioPath)
31 changes: 16 additions & 15 deletions Electron/ElectronGUI/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { app, BrowserWindow, ipcMain } = require("electron");
const path = require("path");
const fs = require("fs");
const { spawn } = require("child_process");
const spawnWIN = require('cross-spawn');
const spawnWIN = require("cross-spawn");
const { stderr, kill } = require("process");
const open = require("open");
const isDev = require("electron-is-dev");
Expand All @@ -20,7 +20,10 @@ if (isDev) {
cache_dir = path.join(app.getPath("cache"), app.getName());
}
console.log("cache dir is", cache_dir);
spawn("mkdir", [`"${cache_dir}"`], {detached:true,shell: process.platform == 'win32'});
spawn("mkdir", [`"${cache_dir}"`], {
detached: true,
shell: process.platform == "win32",
});

let pyCliStat = {
process: null,
Expand Down Expand Up @@ -53,8 +56,7 @@ const createWindow = () => {
mainWindow.loadFile(path.join(__dirname, "index.html"));

// Open the DevTools.
if(isDev)
mainWindow.webContents.openDevTools();
if (isDev) mainWindow.webContents.openDevTools();
};

// This method will be called when Electron has finished
Expand All @@ -68,10 +70,8 @@ app.on("ready", createWindow);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
if (pyCliStat.process) {
if(process.platform == 'win32')
treekill(pyCliStat.process.pid);
else
kill(-pyCliStat.process.pid,'SIGINT');
if (process.platform == "win32") treekill(pyCliStat.process.pid);
else kill(-pyCliStat.process.pid, "SIGINT");
}
app.quit();
}
Expand Down Expand Up @@ -103,21 +103,22 @@ const runCLI = async (arg) => {
commandArgs.push(`"${file}"`);
});
if (arg.onlyHost) {
commandArgs.push("--only-host");
commandArgs.push("--control");
}

if (arg.qr) {
commandArgs.push("--qr");
}
const command = `"${binary_dir.toString()}/LocalParty${process.platform == 'win32'?'.exe':''}"`;
const command = `"${binary_dir.toString()}/LocalParty${
process.platform == "win32" ? ".exe" : ""
}"`;
console.log(commandArgs);

const pyCli = spawnWIN(command, commandArgs, {
cwd: cache_dir,
shell: true,
detached: process.platform != 'win32',
detached: process.platform != "win32",
});

pyCliStat.process = pyCli;
pyCliStat.numInstances += 1;

Expand Down Expand Up @@ -174,7 +175,7 @@ ipcMain.on("show_qr", (event) => {
// eslint-disable-next-line no-unused-vars
ipcMain.on("killCLI", (event, arg) => {
if (!pyCliStat.process) return;
treekill(pyCliStat.process.pid,'SIGINT');
treekill(pyCliStat.process.pid, "SIGINT");

console.log("CLI killed");

Expand Down
4 changes: 2 additions & 2 deletions Server/src/assets/js/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const ogg2mkv = file => {
};

const mkv2ogg = file => {
return file.substr(0, file.length - 3) + 'ogg';
return file.substr(0, file.length - 3) + 'mp3';
};

const url_from_file = filePath => {
Expand Down Expand Up @@ -105,7 +105,7 @@ document.getElementById('startParty').addEventListener('click', () => {

const getFileNameFromPath = path => {
let fileName = path.substring(path.lastIndexOf('\\') + 1);
if (fileName.endsWith('ogg'))
if (fileName.endsWith('mp3'))
fileName = fileName.substring(0, fileName.length - 3);
return fileName;
};
Expand Down
14 changes: 7 additions & 7 deletions Server/src/assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const getParams = function (url) {

const socket = io(`http://${addr}/`);

const maxError = 0.15;
const maxError = 0.25;
const eventTimeDiff = 1;
const interval = 1000;
let networkOffset = 0;
Expand Down Expand Up @@ -52,8 +52,8 @@ setInterval(() => {
lastState.last_updated +
lastState.position -
networkOffset +
0.2
+ manualOffset
0.2 +
manualOffset
: lastState.position;
console.log(audio.currentTime - expectedPosition);
if (Math.abs(audio.currentTime - expectedPosition) >= maxError) {
Expand Down Expand Up @@ -82,16 +82,16 @@ document.getElementById('joinRoom').addEventListener('click', () => {
});
document.getElementById('offsetPlus').addEventListener('click', () => {
manualOffset += 0.05;
updateOffsetText()
updateOffsetText();
});
document.getElementById('offsetMinus').addEventListener('click', () => {
manualOffset -= 0.05;
updateOffsetText()
updateOffsetText();
});

const updateOffsetText = () => {
$('#offset')[0].innerText = `${(manualOffset*1000).toFixed(0)} ms`
}
$('#offset')[0].innerText = `${(manualOffset * 1000).toFixed(0)} ms`;
};

socket.on('joinRoom', data => {
console.log('Present state is: ');
Expand Down

0 comments on commit 9e11a45

Please sign in to comment.