1.1.0 • Published 4 years ago

youtube-to-twitter v1.1.0

Weekly downloads
2
License
MIT
Repository
-
Last release
4 years ago

YouTube to Twitter

Download video from youtube channel and upload it twitter.

Install

npm install --save youtube-to-twitter

Example

See server.js

const express = require('express');
const { download, trim, tweet, upload, video } = require('youtube-to-twitter');

const app = express();

app.get('/', async (req, res) => {
  res.sendStatus(200);

  main()
    .then(console.log)
    .catch(console.error);
});

const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`listen on port ${port}`);
});

async function main() {
  const start = parseInt(process.env.VIDEO_START, 10) || 0;
  const duration = parseInt(process.env.VIDEO_DURATION, 10) || 30;

  const { title, url } = await video();
  const status =
    title.replace(/【ハックフォープレイ実況】/, ' #HackforPlay') +
    '\n\nつづきはこちら↓\n' +
    url;
  console.log('next tweet:\n', status);

  const source = await download(url);
  const output = await trim(source, start, start + duration);

  const mediaId = await upload(output);
  await tweet(mediaId, status);
}