├── LICENSE ├── README.md └── yt2ipfs /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Juan Batiz-Benet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # yt2ipfs - re-host youtube videos on ipfs 2 | 3 | > Only intended for use on videos you are allowed to download, such as your own or out of copyright. 4 | 5 | ## Install 6 | 7 | - [install ipfs](https://ipfs.io/docs/install) (probably in your package manager) 8 | - [install youtube-dl](https://github.com/rg3/youtube-dl#installation) (probably in your package manager) 9 | - run `ipfs daemon` in the background 10 | - place `yt2ipfs` in your `$PATH` somewhere 11 | - test with `yt2ipfs -h` 12 | 13 | ## Usage 14 | 15 | ``` 16 | > yt2ipfs --help 17 | yt2ipfs [--api ] 18 | ``` 19 | 20 | ## Examples 21 | 22 | ### Download a link 23 | 24 | ``` 25 | > yt2ipfs https://www.youtube.com/watch?v=vyRZBeMtkrA 26 | using ipfs api at: /ip4/127.0.0.1/tcp/9095 27 | cd temp dir: /tmp/yt2ipfs.2018-02-05T03:08:43Z.0sDA1j 28 | downloading youtube video: https://www.youtube.com/watch?v=vyRZBeMtkrA 29 | [youtube] vyRZBeMtkrA: Downloading webpage 30 | [youtube] vyRZBeMtkrA: Downloading video info webpage 31 | [youtube] vyRZBeMtkrA: Extracting video information 32 | [download] Destination: Filecoin-Protocol-vyRZBeMtkrA.mp4 33 | [download] 100% of 230.80MiB in 3:09 34 | adding video to ipfs...done 35 | local gateway: http://localhost:8080/ipfs/QmUhBnUYYywHqdHKy44zvbBpdrim4NGGZ2dntK8bTnohfT 36 | global gateway: https://ipfs.io/ipfs/QmUhBnUYYywHqdHKy44zvbBpdrim4NGGZ2dntK8bTnohfT 37 | cleaning up...done 38 | ``` 39 | 40 | ### Just the youtube id 41 | 42 | ``` 43 | yt2ipfs vyRZBeMtkrA 44 | ``` 45 | 46 | ### Use another ipfs API 47 | 48 | ``` 49 | yt2ipfs --api /ip4/127.0.0.1/tcp/9096 https://www.youtube.com/watch?v=vyRZBeMtkrA 50 | ``` 51 | 52 | ## LICENSE 53 | 54 | MIT 55 | -------------------------------------------------------------------------------- /yt2ipfs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | ipfsAPI=/ip4/127.0.0.1/tcp/5001 6 | clusterAPI=/ip4/127.0.0.1/tcp/9095 7 | localGWY=http://localhost:8080 8 | globalGWY=https://ipfs.io 9 | 10 | # to use default cluster api, uncomment this line. 11 | # ipfsAPI="$clusterAPI" 12 | 13 | usage() { 14 | echo "yt2ipfs [--api ] " 15 | exit 0 16 | } 17 | 18 | die() { 19 | echo "error: $@" 20 | exit 1 21 | } 22 | 23 | assertDep() { 24 | which "$1" >/dev/null || die "please install dependency: $1" 25 | } 26 | 27 | assertDeps() { 28 | assertDep "ipfs" 29 | assertDep "youtube-dl" 30 | } 31 | 32 | assertIpfsOnline() { 33 | ipfs --api "$ipfsAPI" swarm addrs local >/dev/null || die "ipfs node offline" 34 | } 35 | 36 | printIpfsLinks() { 37 | hash="$1" 38 | 39 | echo "local gateway: $localGWY/ipfs/$hash" 40 | echo "global gateway: $globalGWY/ipfs/$hash" 41 | } 42 | 43 | # ---- main ---- 44 | 45 | if [ $# -eq 0 ]; then 46 | usage 47 | elif [ "$1" = "-h" ]; then 48 | usage 49 | elif [ "$1" = "--help" ]; then 50 | usage 51 | else 52 | 53 | if [ "$1" == "--api" ]; then 54 | ipfsAPI="$2" 55 | ytlink="$3" 56 | else 57 | ytlink="$1" 58 | fi 59 | 60 | if [ "$ytlink" == "" ]; then 61 | usage 62 | fi 63 | 64 | assertDeps 65 | 66 | echo "using ipfs api at: $ipfsAPI" 67 | assertIpfsOnline 68 | 69 | d=$(date +"%Y-%m-%dT%H:%M:%SZ") 70 | tmpdir=$(mktemp -d "/tmp/yt2ipfs.$d.XXXXXX") 71 | echo "cd temp dir: $tmpdir" 72 | cd "$tmpdir" 73 | 74 | echo "downloading youtube video: $ytlink" 75 | youtube-dl -f mp4 "$ytlink" 76 | 77 | printf "adding video to ipfs..." 78 | hash=$(ipfs --api "$ipfsAPI" add -q -r . | tail -n1) 79 | echo "done" 80 | 81 | printIpfsLinks "$hash" 82 | 83 | printf "cleaning up..." 84 | cd ".." 85 | rm -r "$tmpdir" 86 | echo "done" 87 | fi 88 | --------------------------------------------------------------------------------