create account

New Discord bot to pin DTube videos to IPFS node by techcoderx

View this thread on: hive.blogpeakd.comecency.com
· @techcoderx · (edited)
$74.55
New Discord bot to pin DTube videos to IPFS node
<center>![](https://i.imgur.com/o5sbhB4.png)</center>

#### 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

<center>![NodeJS logo](https://i0.wp.com/technology.amis.nl/wp-content/uploads/2016/04/my-first-nodejs-service.png?fit=702%2C336&ssl=1)</center>

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](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesadd), 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](https://gist.github.com/mkaz/69066bd0c5e45515a264).

##### 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](https://discord.gg/Sc4utKr) I'm in.

<center>https://ipfs.io/ipfs/QmQHMCbXovHrsoTppJhgC858chCi79JPDMojRzgsJxeNue</center>

#### Setup

All requirements for installing the bot, plus instructions to install the bot are laid out in [README.md](https://github.com/techcoderx/DTube-IPFS-Bot/blob/master/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.

<center>https://cdn.discordapp.com/attachments/426546263551639552/429098704847503363/templte_banner.png</center>

#### Github account

https://github.com/techcoderx
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 27 others
πŸ‘Ž  
properties (23)
authortechcoderx
permlinknew-discord-bot-to-pin-dtube-videos-to-ipfs-node
categoryutopian-io
json_metadata{"tags":["utopian-io","development","dtube","ipfs","onelovedtube"],"users":["onelovedtube"],"image":["https://i.imgur.com/o5sbhB4.png","https://i0.wp.com/technology.amis.nl/wp-content/uploads/2016/04/my-first-nodejs-service.png?fit=702%2C336&ssl=1","https://ipfs.io/ipfs/QmQHMCbXovHrsoTppJhgC858chCi79JPDMojRzgsJxeNue","https://cdn.discordapp.com/attachments/426546263551639552/429098704847503363/templte_banner.png"],"links":["https://github.com/techcoderx/DTube-IPFS-Bot","https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesadd","https://gist.github.com/mkaz/69066bd0c5e45515a264","https://discord.gg/Sc4utKr","https://github.com/techcoderx/DTube-IPFS-Bot/blob/master/README.md","https://github.com/techcoderx"],"app":"steemit/0.1","format":"markdown"}
created2018-07-28 13:39:18
last_update2018-07-28 14:41:57
depth0
children4
last_payout2018-08-04 13:39:18
cashout_time1969-12-31 23:59:59
total_payout_value56.169 HBD
curator_payout_value18.379 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,764
author_reputation47,797,995,910,732
root_title"New Discord bot to pin DTube videos to IPFS node"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,279,405
net_rshares41,770,225,976,355
author_curate_reward""
vote details (92)
@codingdefined ·
$0.04
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](https://join.utopian.io/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](https://review.utopian.io/result/3/1322222).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , ,
properties (23)
authorcodingdefined
permlinkre-techcoderx-new-discord-bot-to-pin-dtube-videos-to-ipfs-node-20180729t092132214z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://github.com/techcoderx/DTube-IPFS-Bot/blob/master/bot.js#L65","https://join.utopian.io/guidelines","https://review.utopian.io/result/3/1322222","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-07-29 09:21:30
last_update2018-07-29 09:21:30
depth1
children1
last_payout2018-08-05 09:21:30
cashout_time1969-12-31 23:59:59
total_payout_value0.035 HBD
curator_payout_value0.004 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length787
author_reputation534,272,697,992,335
root_title"New Discord bot to pin DTube videos to IPFS node"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,371,617
net_rshares23,116,171,219
author_curate_reward""
vote details (3)
@techcoderx ·
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 πŸ˜‰
properties (22)
authortechcoderx
permlinkre-codingdefined-re-techcoderx-new-discord-bot-to-pin-dtube-videos-to-ipfs-node-20180731t090409546z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-07-31 09:04:09
last_update2018-07-31 09:04:09
depth2
children0
last_payout2018-08-07 09:04:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length266
author_reputation47,797,995,910,732
root_title"New Discord bot to pin DTube videos to IPFS node"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,615,263
net_rshares0
@dulborah ·
# 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
πŸ‘  
πŸ‘Ž  
properties (23)
authordulborah
permlinkre-techcoderx-new-discord-bot-to-pin-dtube-videos-to-ipfs-node-20180729t034153239z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-07-29 03:41:57
last_update2018-07-29 03:41:57
depth1
children0
last_payout2018-08-05 03:41:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length396
author_reputation-600,108,957,082
root_title"New Discord bot to pin DTube videos to IPFS node"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id66,345,442
net_rshares-5,487,319,346
author_curate_reward""
vote details (2)
@utopian-io ·
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.**

<a href='https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-new-discord-bot-to-pin-dtube-videos-to-ipfs-node-20180731t190509z
categoryutopian-io
json_metadata"{"app": "beem/0.19.42"}"
created2018-07-31 19:05:09
last_update2018-07-31 19:05:09
depth1
children0
last_payout2018-08-07 19:05:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length302
author_reputation152,955,367,999,756
root_title"New Discord bot to pin DTube videos to IPFS node"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,671,117
net_rshares0