Skip to content

Instantly share code, notes, and snippets.

@larskluge
Last active November 11, 2017 04:59
Show Gist options
  • Save larskluge/009b039335f725af4149 to your computer and use it in GitHub Desktop.
Save larskluge/009b039335f725af4149 to your computer and use it in GitHub Desktop.
Popcorn Time for the Command Line

Popcorn Time for the Command Line

Install

  1. Requires installed VLC
  2. Requires installed Node.js
  3. npm install -g coffeescript cheerio peerflix

Tested on Mac only.

Usage

play Game of Thrones S04E07
play Arrow S02E07
play Inception
#!/usr/bin/env coffee
#
http = require('http')
cheerio = require('cheerio')
spawn = require('child_process').spawn
searchTerm = process.argv[2..-1].join(' ')
url = "http://thepiratebay.se/search/#{encodeURIComponent(searchTerm)}"
req = http.get url, (res) ->
res.setEncoding("utf8")
content = ""
res.on "data", (chunk) ->
content += chunk
res.on "end", ->
$ = cheerio.load(content)
magnetUri = $("table#searchResult a[href^=magnet]").first().attr("href")
if magnetUri
peerflix = spawn("peerflix", [magnetUri, "--vlc"], stdio: "inherit")
else
process.exit 1
req.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment