[
  {
    "path": ".github/FUNDING.yml",
    "content": "github: ionicabizau\npatreon: ionicabizau\nopen_collective: ionicabizau\ncustom: https://www.buymeacoffee.com/h96wwchmy"
  },
  {
    "path": ".gitignore",
    "content": "*.swp\n*.swo\n*~\n*.log\nnode_modules\n*.env\n.DS_Store\npackage-lock.json\n.bloggify/*\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# 🌟 Contributing\n\nWant to contribute to this project? Great! Please read these quick steps to streamline the process and avoid unnecessary tasks. ✨\n\n## 💬 Discuss Changes\nStart by opening an issue in the repository using the [bug tracker][1]. Describe your proposed contribution or the bug you've found. If relevant, include platform info and screenshots. 🖼️\n\nWait for feedback before proceeding unless the fix is straightforward, like a typo. 📝\n\n## 🔧 Fixing Issues\n\nFork the project and create a branch for your fix, naming it `some-great-feature` or `some-issue-fix`. Commit changes while following the [code style][2]. If the project has tests, add one. ✅\n\nIf a `package.json` or `bower.json` exists, add yourself to the `contributors` array; create it if it doesn't. 🙌\n\n```json\n{\n   \"contributors\": [\n      \"Your Name <your@email.address> (http://your.website)\"\n   ]\n}\n```\n\n## 📬 Creating a Pull Request\nOpen a pull request and reference the initial issue (e.g., *fixes #<your-issue-number>*). Provide a clear title and consider adding visual aids for clarity. 📊\n\n## ⏳ Wait for Feedback\nYour contributions will be reviewed. If feedback is given, update your branch as needed, and the pull request will auto-update. 🔄\n\n## 🎉 Everyone Is Happy!\nYour contributions will be merged, and everyone will appreciate your effort! 😄❤️\n\nThanks! 🤩\n\n[1]: /issues\n[2]: https://github.com/IonicaBizau/code-style"
  },
  {
    "path": "DOCUMENTATION.md",
    "content": "## Documentation\n\nYou can see below the API reference of this module.\n\n### `authenticate(options)`\nSets an authentication method to have access to protected resources.\n\n#### Params\n\n- **Object** `options`: An object containing the authentication information.\n\n#### Return\n- **Object** The authentication object\n\n### `getConfig()`\nReturns Client configuration object\n\n#### Return\n- **Object** Client configuration object\n\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2013-25 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n# youtube-api\n\n [![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [![Ask me anything](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Version](https://img.shields.io/npm/v/youtube-api.svg)](https://www.npmjs.com/package/youtube-api) [![Downloads](https://img.shields.io/npm/dt/youtube-api.svg)](https://www.npmjs.com/package/youtube-api) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/@johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)\n\n<a href=\"https://www.buymeacoffee.com/H96WwChMy\" target=\"_blank\"><img src=\"https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png\" alt=\"Buy Me A Coffee\"></a>\n\n\n\n\n\n\n\n> A Node.JS module, which provides an object oriented wrapper for the Youtube v3 API.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## :cloud: Installation\n\n```sh\n# Using npm\nnpm install --save youtube-api\n\n# Using yarn\nyarn add youtube-api\n```\n\n\n\n\n\n\n\n\n\n\n\n\n\n## :clipboard: Example\n\n\n\n```js\n/**\n * This script uploads a video (specifically `video.mp4` from the current\n * directory) to YouTube,\n *\n * To run this script you have to create OAuth2 credentials and download them\n * as JSON and replace the `credentials.json` file. Then install the\n * dependencies:\n *\n * npm i r-json lien opn bug-killer\n *\n * Don't forget to run an `npm i` to install the `youtube-api` dependencies.\n * */\n\nconst Youtube = require(\"youtube-api\")\n    , fs = require(\"fs\")\n    , readJson = require(\"r-json\")\n    , Lien = require(\"lien\")\n    , Logger = require(\"bug-killer\")\n    , opn = require(\"opn\")\n    , prettyBytes = require(\"pretty-bytes\")\n    ;\n\n// I downloaded the file from OAuth2 -> Download JSON\nconst CREDENTIALS = readJson(`${__dirname}/credentials.json`);\n\n// Init lien server\nlet server = new Lien({\n    host: \"localhost\"\n  , port: 5000\n});\n\n// Authenticate\n// You can access the Youtube resources via OAuth2 only.\n// https://developers.google.com/youtube/v3/guides/moving_to_oauth#service_accounts\nlet oauth = Youtube.authenticate({\n    type: \"oauth\"\n  , client_id: CREDENTIALS.web.client_id\n  , client_secret: CREDENTIALS.web.client_secret\n  , redirect_url: CREDENTIALS.web.redirect_uris[0]\n});\n\nopn(oauth.generateAuthUrl({\n    access_type: \"offline\"\n  , scope: [\"https://www.googleapis.com/auth/youtube.upload\"]\n}));\n\n// Handle oauth2 callback\nserver.addPage(\"/oauth2callback\", lien => {\n    Logger.log(\"Trying to get the token using the following code: \" + lien.query.code);\n    oauth.getToken(lien.query.code, (err, tokens) => {\n\n        if (err) {\n            lien.lien(err, 400);\n            return Logger.log(err);\n        }\n\n        Logger.log(\"Got the tokens.\");\n\n        oauth.setCredentials(tokens);\n\n        lien.end(\"The video is being uploaded. Check out the logs in the terminal.\");\n\n        var req = Youtube.videos.insert({\n            resource: {\n                // Video title and description\n                snippet: {\n                    title: \"Testing YoutTube API NodeJS module\"\n                  , description: \"Test video upload via YouTube API\"\n                }\n                // I don't want to spam my subscribers\n              , status: {\n                    privacyStatus: \"private\"\n                }\n            }\n            // This is for the callback function\n          , part: \"snippet,status\"\n\n            // Create the readable stream to upload the video\n          , media: {\n                body: fs.createReadStream(\"video.mp4\")\n            }\n        }, (err, data) => {\n            console.log(\"Done.\");\n            process.exit();\n        });\n\n        setInterval(function () {\n            Logger.log(`${prettyBytes(req.req.connection._bytesDispatched)} bytes uploaded.`);\n        }, 250);\n    });\n});\n```\n\n\n\n\n\n\n\n\n\n\n\n\n## :question: Get Help\n\nThere are few ways to get help:\n\n\n\n 1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.\n 2. For bug reports and feature requests, open issues. :bug:\n 3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:\n\n\n\n\n\n\n\n## :memo: Documentation\n\nThe [official Youtube documentation](https://developers.google.com/youtube/v3/docs/) is a very useful resource.\n\n - [Activities](https://developers.google.com/youtube/v3/docs/activities)\n - [ChannelBanners](https://developers.google.com/youtube/v3/docs/channelBanners)\n - [Channels](https://developers.google.com/youtube/v3/docs/channels)\n - [GuideCategories](https://developers.google.com/youtube/v3/docs/guideCategories)\n - [PlaylistItems](https://developers.google.com/youtube/v3/docs/playlistItems)\n - [Playlists](https://developers.google.com/youtube/v3/docs/playlists)\n - [Search](https://developers.google.com/youtube/v3/docs/search)\n - [Subscriptions](https://developers.google.com/youtube/v3/docs/subscriptions)\n - [Thumbnails](https://developers.google.com/youtube/v3/docs/thumbnails)\n - [VideoCategories](https://developers.google.com/youtube/v3/docs/videoCategories)\n - [Videos](https://developers.google.com/youtube/v3/docs/videos)\n\nIf you have any questions, please [ask them on **Stack Overflow**](https://stackoverflow.com/questions/ask) and eventually [open an issue](https://github.com/IonicaBizau/youtube-api/issues/new) and link your question there.\n\n### Authentication\n\n\n#### OAuth (Access Token)\n\n```js\nYoutube.authenticate({\n    type: \"oauth\"\n  , token: \"your access token\"\n});\n```\n\n#### OAuth (Refresh Token)\n\n```js\nYoutube.authenticate({\n    type: \"oauth\"\n  , refresh_token: \"your refresh token\"\n  , client_id: \"your client id\"\n  , client_secret: \"your client secret\"\n  , redirect_url: \"your refresh url\"\n});\n```\n\n#### Server Key\n\nOnly for requests that don't require [user authorization](https://developers.google.com/youtube/v3/guides/authentication) (certain list operations)\n```js\nYoutube.authenticate({\n    type: \"key\"\n  , key: \"your server key\"\n});\n```\n\n\n\n\n\n\n\n\n\n\n\n\n\n## :yum: How to contribute\nHave an idea? Found a bug? See [how to contribute][contributing].\n\n\n## :sparkling_heart: Support my projects\nI open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,\nthis takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it).\n\nHowever, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:\n\n\n - Starring and sharing the projects you like :rocket:\n - [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book:\n - [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:\n - [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).\n - **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`\n\n    ![](https://i.imgur.com/z6OQI95.png)\n\n\nThanks! :heart:\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## :scroll: License\n\n[MIT][license] © [Ionică Bizău][website]\n\n\n\n\n\n\n[license]: /LICENSE\n[website]: https://ionicabizau.net\n[contributing]: /CONTRIBUTING.md\n[docs]: /DOCUMENTATION.md\n[badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg\n[badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg\n[badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg\n[badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg\n[patreon]: https://www.patreon.com/ionicabizau\n[amazon]: http://amzn.eu/hRo9sIZ\n[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW\n"
  },
  {
    "path": "example/credentials.json",
    "content": "{\n    \"web\": {\n        \"client_id\": \"103..................................hf7bb75o0.apps.googleusercontent.com\",\n        \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n        \"token_uri\": \"https://accounts.google.com/o/oauth2/token\",\n        \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",\n        \"client_email\": \"1038................................dhf7bb75o0@developer.gserviceaccount.com\",\n        \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/1038...................................7bb75o0%40developer.gserviceaccount.com\",\n        \"client_secret\": \"ji.....................w\",\n        \"redirect_uris\": [\"http://localhost:5000/oauth2callback\"],\n        \"javascript_origins\": [\"http://localhost:5000\"]\n    }\n}\n"
  },
  {
    "path": "example/index.js",
    "content": "\"use strict\";\n\n/**\n * This script uploads a video (specifically `video.mp4` from the current\n * directory) to YouTube,\n *\n * To run this script you have to create OAuth2 credentials and download them\n * as JSON and replace the `credentials.json` file. Then install the\n * dependencies:\n *\n * npm i r-json lien opn bug-killer\n *\n * Don't forget to run an `npm i` to install the `youtube-api` dependencies.\n * */\n\nconst Youtube = require(\"../lib\")\n    , fs = require(\"fs\")\n    , readJson = require(\"r-json\")\n    , Lien = require(\"lien\")\n    , Logger = require(\"bug-killer\")\n    , opn = require(\"opn\")\n    , prettyBytes = require(\"pretty-bytes\")\n    ;\n\n// I downloaded the file from OAuth2 -> Download JSON\nconst CREDENTIALS = readJson(`${__dirname}/credentials.json`);\n\n// Init lien server\nlet server = new Lien({\n    host: \"localhost\"\n  , port: 5000\n});\n\n// Authenticate\n// You can access the Youtube resources via OAuth2 only.\n// https://developers.google.com/youtube/v3/guides/moving_to_oauth#service_accounts\nlet oauth = Youtube.authenticate({\n    type: \"oauth\"\n  , client_id: CREDENTIALS.web.client_id\n  , client_secret: CREDENTIALS.web.client_secret\n  , redirect_url: CREDENTIALS.web.redirect_uris[0]\n});\n\nopn(oauth.generateAuthUrl({\n    access_type: \"offline\"\n  , scope: [\"https://www.googleapis.com/auth/youtube.upload\"]\n}));\n\n// Handle oauth2 callback\nserver.addPage(\"/oauth2callback\", lien => {\n    Logger.log(\"Trying to get the token using the following code: \" + lien.query.code);\n    oauth.getToken(lien.query.code, (err, tokens) => {\n\n        if (err) {\n            lien.lien(err, 400);\n            return Logger.log(err);\n        }\n\n        Logger.log(\"Got the tokens.\");\n\n        oauth.setCredentials(tokens);\n\n        lien.end(\"The video is being uploaded. Check out the logs in the terminal.\");\n\n        var req = Youtube.videos.insert({\n            resource: {\n                // Video title and description\n                snippet: {\n                    title: \"Testing YoutTube API NodeJS module\"\n                  , description: \"Test video upload via YouTube API\"\n                }\n                // I don't want to spam my subscribers\n              , status: {\n                    privacyStatus: \"private\"\n                }\n            }\n            // This is for the callback function\n          , part: \"snippet,status\"\n\n            // Create the readable stream to upload the video\n          , media: {\n                body: fs.createReadStream(\"video.mp4\")\n            }\n        }, (err, data) => {\n            console.log(\"Done.\");\n            process.exit();\n        });\n\n        setInterval(function () {\n            Logger.log(`${prettyBytes(req.req.connection._bytesDispatched)} bytes uploaded.`);\n        }, 250);\n    });\n});\n"
  },
  {
    "path": "lib/index.js",
    "content": "// Dependencies\nvar Google = require(\"googleapis\").google;\n\n// Create YoutTube client\nvar Client = module.exports = function(config) {};\n\n(function() {\n    var config = {};\n    /**\n     * authenticate\n     * Sets an authentication method to have access to protected resources.\n     *\n     * @name authenticate\n     * @function\n     * @param {Object} options An object containing the authentication information.\n     * @return {Object} The authentication object\n     */\n    this.authenticate = function (options) {\n        if (!options) {\n            config.auth = undefined;\n            return;\n        }\n\n        var authObj = null;\n        switch (options.type) {\n            case \"oauth\":\n                authObj = new Google.auth.OAuth2(options.client_id, options.client_secret, options.redirect_url);\n                authObj.setCredentials({\n                    access_token: options.access_token || options.token\n                  , refresh_token: options.refresh_token\n                });\n                break;\n            case \"key\":\n                authObj = options.key;\n                break;\n        }\n\n        Google.options({ auth: authObj });\n        config.auth = options;\n\n        return authObj;\n    };\n\n    /**\n     * getConfig\n     * Returns Client configuration object\n     *\n     * @name getConfig\n     * @function\n     * @return {Object} Client configuration object\n     */\n    this.getConfig = function () {\n        return config;\n    };\n\n    // Add Google YouTube API functions\n    var GoogleYoutube = Google.youtube(\"v3\");\n    for (var f in GoogleYoutube) {\n        this[f] = GoogleYoutube[f];\n    }\n}).call(Client);\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"youtube-api\",\n  \"version\": \"3.0.2\",\n  \"description\": \"A Node.JS module, which provides an object oriented wrapper for the Youtube v3 API.\",\n  \"main\": \"lib/index.js\",\n  \"author\": \"Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)\",\n  \"contributors\": [\n    \"Ionică Bizău <bizauionica@gmail.com>\",\n    \"Adam <aaschodd@asu.edu> (brutalhonesty)\",\n    \"Michael Scharl <developeme@gmail.com>\",\n    \"Vels <velshome@yahoo.com> (velsa)\",\n    \"Rasmus Karlsson <pajlada@bithack.se>\",\n    \"Brad Oyler <bradoyler@gmail.com>\"\n  ],\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git://github.com/IonicaBizau/youtube-api.git\"\n  },\n  \"keywords\": [\n    \"youtube\",\n    \"api\",\n    \"v3\",\n    \"node\"\n  ],\n  \"license\": \"MIT\",\n  \"bugs\": {\n    \"url\": \"https://github.com/IonicaBizau/youtube-api/issues\"\n  },\n  \"dependencies\": {\n    \"googleapis\": \"^54.1.0\"\n  },\n  \"homepage\": \"https://github.com/IonicaBizau/youtube-api\",\n  \"directories\": {\n    \"example\": \"example\"\n  },\n  \"devDependencies\": {\n    \"bug-killer\": \"^4.2.2\",\n    \"lien\": \"^3.3.0\",\n    \"opn\": \"^6.0.0\",\n    \"pretty-bytes\": \"^5.3.0\",\n    \"r-json\": \"^1.2.2\"\n  },\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"blah\": {\n    \"show_jsdocs\": false,\n    \"documentation\": [\n      \"The [official Youtube documentation](https://developers.google.com/youtube/v3/docs/) is a very useful resource.\",\n      {\n        \"ul\": [\n          \"[Activities](https://developers.google.com/youtube/v3/docs/activities)\",\n          \"[ChannelBanners](https://developers.google.com/youtube/v3/docs/channelBanners)\",\n          \"[Channels](https://developers.google.com/youtube/v3/docs/channels)\",\n          \"[GuideCategories](https://developers.google.com/youtube/v3/docs/guideCategories)\",\n          \"[PlaylistItems](https://developers.google.com/youtube/v3/docs/playlistItems)\",\n          \"[Playlists](https://developers.google.com/youtube/v3/docs/playlists)\",\n          \"[Search](https://developers.google.com/youtube/v3/docs/search)\",\n          \"[Subscriptions](https://developers.google.com/youtube/v3/docs/subscriptions)\",\n          \"[Thumbnails](https://developers.google.com/youtube/v3/docs/thumbnails)\",\n          \"[VideoCategories](https://developers.google.com/youtube/v3/docs/videoCategories)\",\n          \"[Videos](https://developers.google.com/youtube/v3/docs/videos)\"\n        ]\n      },\n      \"If you have any questions, please [ask them on **Stack Overflow**](https://stackoverflow.com/questions/ask) and eventually [open an issue](https://github.com/IonicaBizau/youtube-api/issues/new) and link your question there.\",\n      \"\",\n      {\n        \"h3\": \"Authentication\"\n      },\n      \"\",\n      {\n        \"h4\": \"OAuth (Access Token)\"\n      },\n      {\n        \"code\": {\n          \"language\": \"js\",\n          \"content\": [\n            \"Youtube.authenticate({\",\n            \"    type: \\\"oauth\\\"\",\n            \"  , token: \\\"your access token\\\"\",\n            \"});\"\n          ]\n        }\n      },\n      {\n        \"h4\": \"OAuth (Refresh Token)\"\n      },\n      {\n        \"code\": {\n          \"language\": \"js\",\n          \"content\": [\n            \"Youtube.authenticate({\",\n            \"    type: \\\"oauth\\\"\",\n            \"  , refresh_token: \\\"your refresh token\\\"\",\n            \"  , client_id: \\\"your client id\\\"\",\n            \"  , client_secret: \\\"your client secret\\\"\",\n            \"  , redirect_url: \\\"your refresh url\\\"\",\n            \"});\"\n          ]\n        }\n      },\n      {\n        \"h4\": \"Server Key\"\n      },\n      \"Only for requests that don't require [user authorization](https://developers.google.com/youtube/v3/guides/authentication) (certain list operations)\",\n      {\n        \"code\": {\n          \"language\": \"js\",\n          \"content\": [\n            \"Youtube.authenticate({\",\n            \"    type: \\\"key\\\"\",\n            \"  , key: \\\"your server key\\\"\",\n            \"});\"\n          ]\n        }\n      }\n    ]\n  },\n  \"files\": [\n    \"bin/\",\n    \"app/\",\n    \"lib/\",\n    \"dist/\",\n    \"src/\",\n    \"scripts/\",\n    \"resources/\",\n    \"menu/\",\n    \"cli.js\",\n    \"index.js\",\n    \"index.d.ts\",\n    \"package-lock.json\",\n    \"bloggify.js\",\n    \"bloggify.json\",\n    \"bloggify/\"\n  ]\n}"
  }
]