Convert direct download links into Torrent using GitHub Actions
Tags: actionshackathon21, torrent, actions, bittorrent
Published: 2021-12-04 17:36:59

### My Workflow
Back in the day, we have BurnBit that allows us to leverage the P2P power of BitTorrent for our files hosted on our web servers. BurnBit downloads the file in their servers and creates a .torrent metadata of the file and adds your web server as an HTTP webseed for that torrent. This works flawlessly, your file is getting downloaded from your server and at the same time, with other peers already downloaded the file through seeding. This saves bandwidth on your web server, costing you less, and improves the download experience of your users if your web server can't handle the load.

Fast-forward today, BurnBit got down, and there are no alternatives until URLHash, but URLHash has limits, and sometimes goes down.

This GitHub Action workflow allows you to create .torrent file from a direct HTTP link of your web sever and uses that link for webseeding.

This will download the file from your HTTP link and hash it using a torrent creator program using GitHub Actions.

### Submission Category: 
Wacky Wildcards

### Yaml File or Link to Code
```
name: torrenttools
on:
  workflow_dispatch:
    inputs:
      name:
        description: Name of the torrent file
        required: true
        default: Firefox Setup 94.0.2
      comment:
        description: Comment
        required: true
        default: Firefox Setup 94.0.2 win64 en-US by torrent-webseed-creator
      url:
        description: URL of the file
        required: true
        default: 'https://download-installer.cdn.mozilla.net/pub/firefox/releases/94.0.2/win64/en-US/Firefox%20Setup%2094.0.2.exe'
      file_name:
        description: File name of the file in the torrent
        required: true
        default: Firefox Setup 94.0.2.exe
      piece_size:
        description: Piece Size. Use auto for automatic calculation, or use the recommended piece size on the README.md file
        required: true
        default: auto
      protocol_version:
        description: BitTorrent Protocol version 1, 2, or hybrid
        required: true
        default: '1'
      maximize_disk_space:
        description: Maximize disk space. Set to true if getting out of disk space error
        default: 'false'
        
jobs:
  create_torrent:
    runs-on: ubuntu-latest
    steps:
      - name: Maximize disk space
        if: ${{ github.event.inputs.maximize_disk_space == 'true' }}
        uses: easimon/maximize-build-space@v4
        with:
          remove-dotnet: 'true'
          remove-android: 'true'
          remove-haskell: 'true'
          
      - name: Install torrenttools
        run: |
          sudo add-apt-repository ppa:fbdtemme/torrenttools
          sudo apt-get update
          sudo apt-get install torrenttools
          
      - name: Download file
        run: aria2c -x 16 -o "${{ github.event.inputs.file_name }}" "${{ github.event.inputs.url }}"
        
      - name: Create torrent using torrenttools
        run: torrenttools create -v "${{ github.event.inputs.protocol_version }}" -o "${{ github.event.inputs.name }}.torrent" -w "${{ github.event.inputs.url }}" -c "${{ github.event.inputs.comment }}" -l "${{ github.event.inputs.piece_size }}" -s "torrent-webseed-creator" "${{ github.event.inputs.file_name }}"
        
      - name: Upload torrent file
        uses: actions/upload-artifact@v2
        with:
          name: ${{ github.event.inputs.name }}
          path: ${{ github.event.inputs.name }}.torrent
```
{% github https://github.com/AnimMouse/torrent-webseed-creator %}

### Additional Resources / Info
{% github https://github.com/fbdtemme/torrenttools %}

[Burnbit Turns Any Web-Hosted File into a Torrent Article](https://lifehacker.com/burnbit-turns-any-web-hosted-file-into-a-torrent-5637855)
[Burn Any Web-Hosted File into a Torrent With Burnbit Article](https://torrentfreak.com/burn-any-web-hosted-file-into-a-torrent-with-burnbit-100913/)