WebTorrent integration with WordPress
Distributed audio content (podcasts) generated by users and shared via peer-to-peer (P2P) architectures and protocols can lower the entry barrier for community based radios that at the same time are wary of the privacy implications of the free offerings by commercial centralised platforms.
Although not a P2P architecture itself, a website is a useful way to disseminate the torrent podcasts, publishing the magnet-links and making these contents easily and transparently available to users that may not be familiar with torrents and P2P, including in-browser streaming.
WebTorrent is a neat streaming torrent client for the web browser (and the desktop). It can play media content shared via P2P, and automatically re-share (seeding) while listening or viewing it. The user only needs to know the podcast identification on the P2P network (magnet link or hash code).
An easy integration of WebTorrent with the popular WordPress content management system would be useful. An existing old plugin has not been updated in three years and currently does not work with WP [last version].
Instead of developing a new dedicated WebTorrent plugin, I achieved a similar function through a custom shortcode, a handy way to extend WP capabilities that can be added with the existing Shortcoder plugin.
After installing the Shortcoder plugin, it is sufficient to define the new shortcode with the following code (based on examples found on the WebTorrent site), and naming it e.g. “webtorrent”:
of
—
↘0 b/s
/ ↗0 b/s
The shortcode downloads the WebTorrent client, written in javascript, from its CDN, as well as moment.js used to show a human-readable remaining time while downloading. If this function is not needed, moment.js download can be omitted.
The parameters %%id:1 and the like allow to embed more than one WebTorrent podcast in each post/page.
Typical usage within a WordPress post or page:
[sc name="webtorrent" id="1" magnetlink="magnet:?..." extension="m4a"]Text to be shown in the post (linked to the podcast)[/sc]
Where:
name: is the name of the shortcake created in the previous step;
id: is a progressive numeral (default=“1”) to be manually increased if there are more than one podcast embedded in the post/page;
magnetlink: is self-explanatory;
extension: extension of the media filename — audio or video — contained in the magnet-link that we want to stream and play; supported: mp3, m4a, mp4, ogg, etc. (check WebTorrent docs for details); defaults to: “m4a”
The shortcode contains some stylesheet directives that the user can easily customise, as well as torrent statistics about the number of peers, upload/download speed, etc. that can be easily commented out if not needed.