yazninja / nowplayinginfo

Now Playing Text Plugin
4 stars 2 forks source link

Adding a space after title text #1

Open Ihavenoideawhy opened 1 year ago

Ihavenoideawhy commented 1 year ago

Apologies if this is in the wrong area. I do not use github much and the discord link wasn't working. I've figured out how to format the text and image in OBS, however for longer song titles I'd like to have a scrolling effect however the text when scrolling is right up against itself. image As you can see, the two words are right next to one another. Is it possible to add three spaces at the end of the text line? I'd do it myself but I have no JS experience.

Brize-Glace commented 10 months ago

Hi! I found a fix by reworking the code.

  1. Go to your Cider plugin path
  2. Find the NowPlaying plugin
  3. Open index.js
  4. Cut Paste the following code
const writeFileSync = require('fs').writeFileSync;
const appendFileSync = require('fs').appendFileSync;
const existsSync = require('fs').existsSync;
const mkdirSync = require('fs').mkdirSync;
const https = require('node:https');
// import{ default as path } from 'path'

module.exports = class nowPlayingPlugin {
    constructor(env) {
        // Define plugin enviornment within the class
        this.env = env
    }

    // Called when the backend is ready
    onReady(win) {

    }

    // Called when the renderer is ready (app.init())
    onRendererReady(win) {
        console.log("\n\n\n [nowPlayingInfoPlugin] Ready \n\n\n");
    }
    onPlaybackStateDidChange(attributes) {
        if (!existsSync(`${this.env.dir}/dist`)) {
            mkdirSync(`${this.env.dir}/dist`);
        }
        let artworkURL = attributes.artwork.url.replace('{h}', attributes.artwork.height).replace('{w}', attributes.artwork.width);
        writeFileSync(`${this.env.dir}/dist/title.txt`, `${attributes.name}    `); //put the space you want after ${attributes.name}
        console.log('The title has been saved!')

        writeFileSync(`${this.env.dir}/dist/artist.txt`, `${attributes.artistName}   `); //Put the space you want after ${attributes.artistName}
        console.log('The artist has been saved!')

        writeFileSync(`${this.env.dir}/dist/album.txt`, `${attributes.albumName}   `); //put the space you want after ${attributes.albumName}
        console.log('The album has been saved!')

        https.get(artworkURL, (res) => {
            writeFileSync(`${this.env.dir}/dist/artwork.jpg`, "")
            console.log('statusCode:', res.statusCode);
            console.log('headers:', res.headers);
            res.on('data', (d) => {
                appendFileSync(`${this.env.dir}/dist/artwork.jpg`, d)
            }).on('error', (e) => {
                console.error(e);
            }).on('end', () => {
                console.log('The artwork has been saved!')
            })
        });
    }
    onNowPlayingItemDidChange(attributes) {
        if (!existsSync(`${this.env.dir}/dist `)) {
            mkdirSync(`${this.env.dir}/dist `);
        }
        let artworkURL = attributes.artwork.url.replace('{h}', attributes.artwork.height).replace('{w}', attributes.artwork.width);
        writeFileSync(`${this.env.dir}/dist/title.txt`, `${attributes.name}   `); //put the space you want after ${attributes.name}
        console.log('The title has been saved!')

        writeFileSync(`${this.env.dir}/dist/artist.txt`, `${attributes.artistName}   `); //put the space you want after ${attributes.artistName}
        console.log('The artist has been saved!')

        writeFileSync(`${this.env.dir}/dist/album.txt`, `${attributes.albumName}   `); //put the space you want after ${attributes.albumName}
        console.log('The album has been saved!')

        https.get(artworkURL, (res) => {
            writeFileSync(`${this.env.dir}/dist/artwork.jpg`, "")
            console.log('statusCode:', res.statusCode);
            console.log('headers:', res.headers);
            res.on('data', (d) => {
                appendFileSync(`${this.env.dir}/dist/artwork.jpg`, d)
            }).on('error', (e) => {
                console.error(e);
            }).on('end', () => {
                console.log('The artwork has been saved!')
            })
        });
    }
    onBeforeQuit() {
        writeFileSync(`${this.env.dir}/dist/title.txt`, "  ") //put the space you want in the ""
        writeFileSync(`${this.env.dir}/dist/artist.txt`, "   ") //put the space you want in the ""
        writeFileSync(`${this.env.dir}/dist/album.txt`, "   ") //put the space you want in the ""
        writeFileSync(`${this.env.dir}/dist/artwork.jpg`, "") //put the space you want in the ""
    }
}
  1. Restart Cider

PS: I annotated the code for spacing. Be careful to put spaces in the quotes or before the "`", depending on where it is in the code.