New Discord bot to pin DTube videos to IPFS node

in #utopian-io6 years ago (edited)

Repository

https://github.com/techcoderx/DTube-IPFS-Bot

Project overview

About

DTube IPFS Discord bot enables Discord server members to obtain the IPFS hash of a DTube video at a specified resolution by sending a Discord bot command in the server with the link to DTube video. It then obtains the IPFS hash of the video, and downloads the video into the server, and pins the file to IPFS node that runs alongside with the NodeJS bot within the same server.

Since DTube deletes old videos in order to save storage spaces in their servers to accommodate new videos, some content creators may want to keep their old videos in the network by hosting the videos themselves. However, maintaining an IPFS node to ensure that all videos that the content creator produce are pinned into their local IPFS node is not easy. Therefore, I've created this Discord bot, aimed at smaller DTube communities, to have their videos pinned to an IPFS node so that their videos stay playable forever. All they need to do is to send a bot command on the Discord server with the link to DTube video.

The commands accept d.tube, steemit.com and busy.org links.

How it works

NodeJS logo

This bot is written mainly in JavaScript, with the NodeJS runtime to run the bot. When the user enters a command for this bot e.g. !ipfs <link>, the bot will obtain the IPFS hash of the video from the post on the Steem blockchain, depending on the command.

  • !ipfs <link> will obtain the source video hash
  • !ipfs480 <link> will obtain the 480p video hash
  • !ipfs240 <link> will obtain the 240p video hash

After obtaining the hash, the bot will generate a download link by adding https://video.dtube.top/ipfs/ in front of the IPFS hash obtained from the blockchain. Next, it will proceed to download the video with the generated download link using wget. Once the download is successful, it will add the IPFS hash to the queue, which is a text file named hashvalues.txt, for pinning the downloaded videos to the local IPFS node (which is running alongside with the bot). This is achieved by using the NodeJS dependency called fs.

The reason I'm not using js-ipfs-api to call a method to pin videos immediately after it is downloaded is that the ipfs.file.add method does not support trickledag option as described in their documentation here, which is what is needed in order to obtain the same final hash as compared to the hash obtained from the post in the blockchain from the beginning.

So, the workaround is to add the hashes to a queue in a text file, then create a bash script which adds the videos to the IPFS node with the trickledag option, and pins the file to the node recursively. After pinning the files, the bash script will clean up the queue by deleting the contents of the text file (leaving an empty text file), then deleting the downloaded videos in the folder as the videos are already in the IPFS node. This is done by deleting all files that begins with Qm in the folder, as all IPFS hashes begin with Qm.

The bash script can be scheduled to execute automatically at regular intervals, using a built in Linux/macOS built in utility, called crontab, as described here.

Use cases

This bot is useful for DTube communities on Discord so that community members can send a Discord command to have their videos pinned in a IPFS node, where the bot is hosted.

I'm planning to implement this bot in the @onelovedtube discord server I'm in.

Setup

All requirements for installing the bot, plus instructions to install the bot are laid out in README.md file in the repository.

Roadmap

In the next few updates, I will add the following:

  1. The ability to fetch and pin IPFS files other than DTube (e.g. DSound)
  2. 720p and 1080p IPFS hashes support (other than 240p, 480p and source resolutions)

How to contribute?

If you found any ways to improve on the code or found any bugs, feel free to create a pull request on the GitHub repository. You can also contact me on Discord techcoderx#7481 if you have any enquiries.

Github account

https://github.com/techcoderx

Sort:  

Thank you for your contribution. I must say, a very well written post. You are getting authorname https://github.com/techcoderx/DTube-IPFS-Bot/blob/master/bot.js#L65, but I would suggest you to first check using regex if the authorname is available or not or is it a broken steemit or busy link.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks for reviewing my contribution. Apologies for the late reply.
I've tested the bot commands with broken or invalid links, it will not crash the bot or reply anything to the command. All it did is log an error message that the author and permlink doesn't exist 😉

Hey @techcoderx
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Sorry to say you my account is hacked by some one. Today i recovery my account, sir i request to say please remove downvote because that is not my activity. Last a month i work hard and suddenly my account is hacked. so sir I Apologize, because my account is misused that activity not done by me... Sir i inform you because it was my duty.. Now your choice Sir down vote remove or not ...thank

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.030
BTC 68062.15
ETH 2637.96
USDT 1.00
SBD 2.70