Results 1 to 2 of 2
  1. #1
    MikeRohsoft's Avatar
    Join Date
    May 2013
    Gender
    male
    Location
    Los Santos
    Posts
    797
    Reputation
    593
    Thanks
    26,314

    provide YT sounds local, for GreaseMonkey Scripts

    Today someone asked for a Script which detects a Message for the new MPGH IM and plays a Sound and i've written a lil Script for it.
    Maybe it's interessting for something/someone else too:
    The NodeJS Part is well coded, the Grease Monkey Part, only an example and can be improved very much

    It needs ffmpeg.exe in the same folder as the server for work.

    NodeJS:
    Code:
    const   http = require('http'),
            fs = require('fs'),
            ytdl = require('ytdl-core'),
            cp  = require('child_process'),
            port = 1337;
    
    const   VideoURL = 'https://www.youtube.com/watch?v=gycSZoYzEks',
            saveVideoAs = 'video.flv',
            saveAudioAs = 'sound.mp3';
    
    // This is the Response if you call localhost:1337
    const requestAnswer = (req, res) => {
      const   path = `./${saveAudioAs}`,
              stat = fs.statSync(path),
              total = stat.size;
      res.writeHead(200, { 'Content-Length': total, 'Content-Type': 'audio/mp3' });
      fs.createReadStream(path).pipe(res);
    }; 
    
    // It runs the HTTP Server 
    const startServer = code => {
        http.createServer(requestAnswer).listen(port);
        console.log(`Server is listening on Port ${port}`);
    };
    
    // It spawns the HTTP Server after it extracted the Audio from the Video
    const onDownloadEnd = () => {
      const ls = cp.spawn('ffmpeg', ['-i', saveVideoAs, saveAudioAs]);
      ls.on('close', startServer);
    };
    
    // This is the Second Task, download the Video, save it as 'video.flv' to get the Audio File from it
    const afterFileDelete = err => {
      const vidRequest = ytdl(VideoURL);
      vidRequest.on('end', onDownloadEnd);
      vidRequest.pipe(fs.createWriteStream(saveVideoAs));
    };
    
    // Just a stupid Stub
    const warnSuppress= () => {};
    
    // Program Main
    fs.unlink(`./${saveAudioAs}`, warnSuppress);
    fs.unlink(`./${saveVideoAs}`, afterFileDelete);
    GreaseMonkey:
    Code:
    var intervalTimer = setInterval(() => {
      // can we Find any Container with Class Name 'messagesContainer'
      var header = document.getElementsByClassName('messagesContainer');
      if (typeof header !== 'object' || header.length === 0) {
        return;
      }
      // Yes, so play a Sound
      var audio = new Audio('https://localhost:1337/sound.mp3');
      if (!!audio && typeof audio === 'object') {
        audio.play(); 
      }
      clearInterval(intervalTimer);
    }, 300);
    Last edited by MikeRohsoft; 06-27-2018 at 07:25 AM.

  2. The Following User Says Thank You to MikeRohsoft For This Useful Post:

    Hell_Demon (06-27-2018)

  3. #2
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    I never thought about running NodeJS just to serve sounds, I usually just uploaded them to my website host if I needed them for local projects. Seems like I'll be using this alternative from now on!
    Ah we-a blaze the fyah, make it bun dem!

Similar Threads

  1. [Request] Looking for an undetected (non local) vehicle spawn script.
    By someperson00 in forum DayZ Mod & Standalone Hacks & Cheats
    Replies: 24
    Last Post: 01-20-2013, 11:31 AM
  2. [Request] Sound File For Headshot
    By Bountygrime in forum Combat Arms Help
    Replies: 11
    Last Post: 08-08-2010, 09:23 PM
  3. [Release] Sound Pack for CF ( credits to Sups )
    By XM8-ADV-[3 Burst Scope] in forum CrossFire Mods & Rez Modding
    Replies: 9
    Last Post: 06-03-2010, 08:40 AM
  4. All Sound files for warrock
    By bk360 in forum WarRock - International Hacks
    Replies: 2
    Last Post: 01-10-2008, 06:55 AM
  5. looking for these scripts, will give m60codes for it!
    By BillGates in forum Trade Accounts/Keys/Items
    Replies: 3
    Last Post: 07-28-2007, 08:55 AM