Coder Social home page Coder Social logo

claudebot / hubot-youtube-info Goto Github PK

View Code? Open in Web Editor NEW
3.0 4.0 2.0 17 KB

:information_source: Show video metadata when YouTube URLs are seen. [Original: https://github.com/github/hubot-scripts/blob/master/src/scripts/youtube-info.coffee]

License: Other

JavaScript 16.83% CoffeeScript 73.45% Shell 9.72%

hubot-youtube-info's Introduction

hubot-youtube-info

Build Status devDependency Status

Shows video metadata when YouTube URLs are seen.

Youtubeのリンクを見た時に動画のメタデータを表示する

Important

This script was not created by me, I have only made a repository for it and made some minor changes. Aside from those, the Copyright for this script lies with GitHub Inc.

Credit for authorship of this script goes to mmb. The original script may be found here.

How to install

The Claudebot repository comes with hubot-youtube-info already set as a script, and you can follow that example.

To add this script to your own version of hubot, edit package.json to contain the latest version of hubot-youtube-info, and the same for external-scripts.json. Then simply run npm update or npm install.

How to use

The script is often coupled with an irc adapter, and will listen to chat for any valid youtube links. Simply paste a link, and the bot will do the rest.

GOOGLE_API_KEY environment variable should be set for script to function properly. To obtain API key: https://www.youtube.com/watch?v=JbWnRhHfTDA

Obtaining a $GOOGLE_API_KEY

  1. Create a Google account to gain access to the Developers Console && create a Project
  2. Find and enable access to the "Youtube Data API v3" for your project
  3. Create a "Public" access token for your project
  4. Set the $GOOGLE_API_KEY environment variable to this token

Summary of changes

  1. Script now exists independently of the hubot-scripts bundle, and may be downloaded via npm.
  2. Added date of video publish/upload to the information printed about the video.
  3. Fixed a bug in the script that caused it to crash if a video lacked ratings.
  4. Added support for gaming subdomain.

hubot-youtube-info's People

Contributors

mrsaints avatar mbwk avatar n0mer avatar

Stargazers

 avatar  avatar Ryan Stecker avatar

Watchers

 avatar James Cloos avatar Jafnee avatar  avatar

Forkers

n0mer digideskio

hubot-youtube-info's Issues

Package is invalid

Due to an error encountered in package.json, the repo is not seen as a valid package by NPM. This is preventing claudebot from using this script.

YouTube API v3

New API endpoint as the old one is deprecated:

GET https://www.googleapis.com/youtube/v3/videos?part=contentDetails%2Cstatistics%2Csnippet&id={VIDEO_ID_HERE}&key={YOUR_API_KEY}

It's part of the videos.list resource so it returns a list of items. Thus, to access the number of views for example:

data.items[0].statistics.viewCount

Assuming data is the fetched / parsed JSON from the API.

Sample return from API call:

{
 "kind": "youtube#videoListResponse",
 "etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/FVju79dVVBMGXdQVZBiE9geOys8\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#video",
   "etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/7-TwPYToOeOT84MVTtjy5cVvabc\"",
   "id": "tGx-u-Rmzws",
   "snippet": {
    "publishedAt": "2015-05-06T21:00:29.000Z",
    "channelId": "UC18NaGQLruOEw65eQE3bNbg",
    "title": "Dota 2 WTF Moments 115",
    "description": "Dota 2 fail/win compilation\nSubmit your clip / Manda tu video: \nhttp://dotawatafak.com/\n\nCheck out the WTF Tees:\nhttp://shrsl.com/?~8c3r\n\nFacebook\nhttps://www.facebook.com/DotaWatafak\n\nTwitter:\nhttps://twitter.com/Dota2WTF\n\n---------------\n\nLAST CLIP MUSIC\n\nTrack Name: OMFG - Hello\nVideo Link: https://www.youtube.com/watch?v=XRgiNUtJurk\nYoutube: https://www.youtube.com/channel/UCMkh-WZrlhqwh_m42ZQNe7g\nDownload: http://bit.ly/alexomfghello\nFacebook: https://www.facebook.com/alexomfg\nSoundCloud: https://soundcloud.com/alexomfg\nTwitter: https://twitter.com/AlexSavageOMFG",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/tGx-u-Rmzws/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/tGx-u-Rmzws/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/tGx-u-Rmzws/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/tGx-u-Rmzws/sddefault.jpg",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "https://i.ytimg.com/vi/tGx-u-Rmzws/maxresdefault.jpg",
      "width": 1280,
      "height": 720
     }
    },
    "channelTitle": "Dota Watafak",
    "categoryId": "20",
    "liveBroadcastContent": "none",
    "localized": {
     "title": "Dota 2 WTF Moments 115",
     "description": "Dota 2 fail/win compilation\nSubmit your clip / Manda tu video: \nhttp://dotawatafak.com/\n\nCheck out the WTF Tees:\nhttp://shrsl.com/?~8c3r\n\nFacebook\nhttps://www.facebook.com/DotaWatafak\n\nTwitter:\nhttps://twitter.com/Dota2WTF\n\n---------------\n\nLAST CLIP MUSIC\n\nTrack Name: OMFG - Hello\nVideo Link: https://www.youtube.com/watch?v=XRgiNUtJurk\nYoutube: https://www.youtube.com/channel/UCMkh-WZrlhqwh_m42ZQNe7g\nDownload: http://bit.ly/alexomfghello\nFacebook: https://www.facebook.com/alexomfg\nSoundCloud: https://soundcloud.com/alexomfg\nTwitter: https://twitter.com/AlexSavageOMFG"
    }
   },
   "contentDetails": {
    "duration": "PT8M11S",
    "dimension": "2d",
    "definition": "hd",
    "caption": "false",
    "licensedContent": true
   },
   "statistics": {
    "viewCount": "301",
    "likeCount": "5198",
    "dislikeCount": "36",
    "favoriteCount": "0",
    "commentCount": "364"
   }
  }
 ]
}

Migration notes:

  • contentDetails contains the video duration (in ISO6801 format).
  • statistics contains the views, likes / dislikes, favourites, comments.
  • snippet contains the title, description, etc.

More on properties: https://developers.google.com/youtube/v3/docs/videos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.