-
Notifications
You must be signed in to change notification settings - Fork 0
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
Vincenzo
committed
Mar 28, 2022
0 parents
commit 875dde6
Showing
11 changed files
with
2,041 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
node |
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,46 @@ | ||
This program allows you to share and view synchronously across multiple devices in your local internet connection. It does NOT want to be a substitute to [Syncplay](https://github.com/Syncplay/syncplay) but rather a lighter and faster alternative for when you need to watch the same video on multiple devices. | ||
|
||
## [Download](https://somelink.com) | ||
|
||
# Supported video platforms | ||
|Platform|Support status| | ||
|--------|--------------| | ||
|Video files (mp4, mkv, etc.)|✔️ Supported| | ||
|Videos on the web|✔️ Supported| | ||
|YouTube videos|✔️ Supported| | ||
|
||
# Supported operating systems | ||
|OS|Support status| | ||
|--|--------------| | ||
|Linux|✔️ Supported| | ||
|Windows|❌ Not supported| | ||
|MacOS|❌ Not supported| | ||
|
||
# How to install | ||
### Linux | ||
Open the terminal and run the following commands: | ||
```bash | ||
git clone https://git.com | ||
cd sync-play | ||
./install.sh | ||
``` | ||
### Windows | ||
Not currently supported. * | ||
### MacOS | ||
Not currently supported. * | ||
|
||
# How does it work | ||
### Linux | ||
Open the terminal anywhere in the system and type: | ||
```bash | ||
sync-play /path/to/video | ||
``` | ||
Then use the web link(s) that the program gives you to watch the video. | ||
### Windows | ||
Not currently supported. * | ||
### MacOS | ||
Not currently supported. * | ||
|
||
|
||
|
||
##### * Only the server is not supported, that means you can still use the web link(s) to watch a video hosted on a supported OS. |
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,15 @@ | ||
#!/bin/bash | ||
|
||
VERSION=v16.14.0 | ||
DISTRO=linux-x64 | ||
|
||
DIRNAME=$(dirname "$(readlink -f "$0")") | ||
NODE_FILE_NAME=node-$VERSION-$DISTRO | ||
NODE_FILE_FULL_NAME=$NODE_FILE_NAME.tar.xz | ||
NODE_DEST_FOLDER=$DIRNAME/node | ||
NODE_MODULES_FOLDER=$DIRNAME/node_modules | ||
|
||
SRC_FILE=$DIRNAME/run.sh | ||
DEST_FILE=/usr/bin/sync-play | ||
|
||
export PATH=$NODE_DEST_FOLDER/$NODE_FILE_NAME/bin:$PATH |
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,111 @@ | ||
const os = require('os'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const http = require('http'); | ||
const https = require('https'); | ||
const express = require('express'); | ||
const { Server } = require('socket.io'); | ||
const ytmux = require('ytdl-core-muxer'); | ||
|
||
const app = express(); | ||
const server = http.createServer(app); | ||
const io = new Server(server); | ||
|
||
// node index /path/to/video | ||
// ^~~~~~~~~~~~~~ | ||
const VIDEO = { | ||
arg: process.argv[2], | ||
path: '' | ||
}; | ||
const PORT = 53050; | ||
const TEMP_FILE_PATH = path.join(__dirname, 'video.tmp'); | ||
|
||
app.use(express.static(path.join(__dirname, 'static'))); | ||
|
||
app.get('/video', (req, res) => { | ||
res.sendFile(VIDEO.path); | ||
}); | ||
|
||
io.on('connection', socket => { | ||
socket.on('play', time => io.emit('play', time)); | ||
socket.on('pause', () => io.emit('pause')); | ||
}); | ||
|
||
start(); | ||
async function start() { | ||
await checkConstants(); | ||
server.listen(PORT, () => { | ||
console.log(`You can access this service on this device using the following link:`); | ||
console.log(`http://localhost:${PORT}/`); | ||
console.log(); | ||
console.log(`You can access this service on other devices using one of the following links:`); | ||
for (let ip of getExternalIPs()) console.log(`http://${ip}:${PORT}/`); | ||
}); | ||
} | ||
function exitWithError(error, code = 1) { | ||
console.error(error); | ||
process.exit(code); | ||
} | ||
|
||
process.stdin.resume(); | ||
process.on('exit', handleExit); | ||
process.on('SIGINT', handleExit); | ||
process.on('SIGUSR1', handleExit); | ||
process.on('SIGUSR2', handleExit); | ||
process.on('uncaughtException', handleExit); | ||
function handleExit() { | ||
if (fs.existsSync(TEMP_FILE_PATH)) fs.unlinkSync(TEMP_FILE_PATH); | ||
console.log(); | ||
process.exit(0); | ||
} | ||
|
||
async function checkConstants() { | ||
if (VIDEO.arg === undefined) exitWithError('You have to specify a path for the video.'); | ||
|
||
if (VIDEO.arg.includes('youtube.com/watch?v=') || VIDEO.arg.includes('youtu.be/')) { | ||
console.log('Downloading video...'); | ||
try { | ||
VIDEO.path = await downloadYouTubeVideo(VIDEO.arg); | ||
} catch (err) { | ||
exitWithError(`There was an error while downloading the video: ${err}`); | ||
} | ||
} else if (VIDEO.arg.startsWith('http://') || VIDEO.arg.startsWith('https://')) { | ||
console.log('Downloading video...'); | ||
try { | ||
VIDEO.path = await downloadVideo(VIDEO.arg); | ||
} catch (err) { | ||
exitWithError(`There was an error while downloading the video: ${err}`); | ||
} | ||
} else { | ||
if (!fs.existsSync(VIDEO.arg)) exitWithError('You must input an existing file.'); | ||
VIDEO.path = path.resolve(VIDEO.arg); | ||
} | ||
} | ||
function getTransferProtocol(url) { | ||
if (url.startsWith('https://')) return https; | ||
else return http; | ||
} | ||
function downloadVideo(url) { | ||
return new Promise((resolve, reject) => { | ||
let path = TEMP_FILE_PATH; | ||
let stream = fs.createWriteStream(path); | ||
getTransferProtocol(url).get(url, res => res.pipe(stream)); | ||
stream.on('close', () => resolve(path)); | ||
stream.on('error', err => reject(err)); | ||
}); | ||
} | ||
function downloadYouTubeVideo(url) { | ||
return new Promise((resolve, reject) => { | ||
let path = TEMP_FILE_PATH; | ||
let stream = fs.createWriteStream(path); | ||
ytmux(url).pipe(stream); | ||
stream.on('close', () => resolve(path)); | ||
stream.on('error', err => reject(err)); | ||
}); | ||
} | ||
function getExternalIPs() { | ||
let res = []; | ||
let nets = os.networkInterfaces(); | ||
for (let key in nets) for (let net of nets[key]) if (net.family === 'IPv4' && !net.internal) res.push(net.address); | ||
return res; | ||
} |
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,17 @@ | ||
#!/bin/bash | ||
|
||
sudo echo -n "" | ||
|
||
source environment.sh | ||
|
||
wget -O $NODE_FILE_FULL_NAME "https://nodejs.org/dist/$VERSION/$NODE_FILE_FULL_NAME" | ||
|
||
sudo mkdir -p $NODE_DEST_FOLDER | ||
sudo tar -xJvf $NODE_FILE_FULL_NAME -C $NODE_DEST_FOLDER | ||
rm $NODE_FILE_FULL_NAME | ||
|
||
cd $DIRNAME && npm install | ||
|
||
sudo ln -s $SRC_FILE $DEST_FILE | ||
|
||
echo "Installation complete." |
Oops, something went wrong.