Slide 1

Slide 1 text

Fuck It: Let’s Have Fun Building a Top Torrents API @rdegges

Slide 2

Slide 2 text

Hey, I’m Randall Chief Hacker, Stormpath Open Source Dude <333 t3h c0d3z

Slide 3

Slide 3 text

Story Time...

Slide 4

Slide 4 text

Let’s turn this Into an API

Slide 5

Slide 5 text

Arrr! Sounds cool, so what’s the plan?

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

https://github.com/rdegges/toptorrents-api

Slide 8

Slide 8 text

Step 1: Download the HTML

Slide 9

Slide 9 text

https://github.com/request/request

Slide 10

Slide 10 text

"use strict"; const request = require("request"); request("https://thepiratebay.org/top/207", (err, resp, body) => { if (err || resp.statusCode !== 200) { throw new Error("thepiratebay must be down! Arg!"); } console.log(body); });

Slide 11

Slide 11 text

Step 2: Parse the HTML The.Infiltrator.2016.720p.BRRip.x264.AAC-ETRG

Slide 12

Slide 12 text

https://github.com/cheeriojs/cheerio

Slide 13

Slide 13 text

const cheerio = require("cheerio"); let $ = cheerio.load(body); $("#searchResult .detName a").each(function() { let torrentName = $(this).text(); console.log(torrentName); });

Slide 14

Slide 14 text

Step 3: Define the API

Slide 15

Slide 15 text

Route: / { "categories": [ "https://toptorrents-api.herokuapp.com/otherPhysibles", "https://toptorrents-api.herokuapp.com/applicationsWindows", "https://toptorrents-api.herokuapp.com/videoMovieClips", "https://toptorrents-api.herokuapp.com/videoMoviesDVDR", "https://toptorrents-api.herokuapp.com/gamesPsx", "https://toptorrents-api.herokuapp.com/videoTvShows", "https://toptorrents-api.herokuapp.com/audioBooks", "https://toptorrents-api.herokuapp.com/applicationsMac", "https://toptorrents-api.herokuapp.com/audioFlac", "https://toptorrents-api.herokuapp.com/videoHandheld", "https://toptorrents-api.herokuapp.com/audioMusic", "https://toptorrents-api.herokuapp.com/gamesMac", "https://toptorrents-api.herokuapp.com/videoHdMovies" ] }

Slide 16

Slide 16 text

Route: / { "torrents": [ { "name": "The.Infiltrator.2016.720p.BRRip.x264.AAC-ETRG", "size": "952.81 MiB", "url": "magnet:?xt=urn:btih:79fbe3251b40d18eb821be...", "seeds": "3272", "leeches": "473" }, { "name": "Star Trek Beyond 2016 1080p WEB-DL x264 AC3-JYK", "size": "3.36 GiB", "url": "magnet:?xt=urn:btih:65959583d7d7f90b98eb2464f...", "seeds": "2720", "leeches": "803" } ] }

Slide 17

Slide 17 text

Step 4: Set the Settings

Slide 18

Slide 18 text

Step 5: Scrape the Data

Slide 19

Slide 19 text

Step 6: Store the Data!

Slide 20

Slide 20 text

Step 7: Create the Routes

Slide 21

Slide 21 text

Step 8: Deploy It!

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

$ heroku create $ git push heroku master $ heroku open $ heroku addons:create heroku-postgresql Create a new app. Deploy your code to Heroku. Open your project in the browser. Create a Postgres database server.

Slide 25

Slide 25 text

Let’s See It In Action!

Slide 26

Slide 26 text

BONUS! (authentication with ...)

Slide 27

Slide 27 text

You’re awesome. @rdegges @gostormpath