Peerfilm es un script para ver vídeos en streaming en la red bittorrent. El script necesita Python 2.7 y depende del programa Peerflix, escrito en Nodejs. Para instalarlo:
#npm install -g peerflix
Una vez instalado y resueltas otras posibles dependencias, Peerfilm estará listo para utilizarse. A continuación comparto el script:
"""
Peerfilm
Author: Gustavo Moreno
Email: gustavo@laenreadera.net
Streaming P2P via bittorrent
Depends on:
- Peerflix
Install Peerflix:
- npm install -g peerflix
This script streams films from bittorrent network. Using it is easy. Just
enter a magnet uri in prompt or load a CSV file that contains magnet uris.
CSV file is delimited by ';' and fields are:
Title;Year;magnetURI
"""
import subprocess
class Films:
def __init__(self):
self.magnetList = []
self.inputIsMagnetURI = False
def selectTorrentSource(self):
# Choose between single magnet or csv file
sourceInput = raw_input("Enter path of CSV file or enter magnetURI: ")
if 'magnet:?' in sourceInput:
self.inputIsMagnetURI == True
self.loadMangetURI(self.inputIsMagnetURI)
else:
self.CSVFile = open(sourceInput,"r")
self.loadMagnetURI(self.inputIsMagnetURI)
def loadMagnetURI(self, singleMagnet):
if singleMagnet == True:
self.title = 'Streaming... '
self.magnetURI = source
else:
self.buildListFromFile(self.CSVFile)
def buildListFromFile(self, CSVFile):
peli = []
lineas = CSVFile.readlines()
for linea in lineas:
peli = linea.split(";")
self.magnetList.append(peli)
def userSelectFilmFromList(self):
# Prompt user to choose a film from a given list of titles
numerationOfAvailableFilms=0
for row in self.magnetList:
print numerationOfAvailableFilms+1, " ", row[1], " ", row[0]
numerationOfAvailableFilms += 1
num_peli = int(raw_input("What film do you want to watch? "))
self.title = self.magnetList[num_peli-1][0]
self.magnetURI = self.magnetList[num_peli-1][2]
def streamFilm(self):
# Launch peerflix to VLC
# Type 'peerflix -h' in console to see available parameters
print "\n\n\nStreaming... ", self.title, " \n\n\n"
subprocess.call(['/usr/local/bin/peerflix', self.magnetURI, '-v', 'peliculas/%s'%self.title])
def play(self):
self.selectTorrentSource()
if self.inputIsMagnetURI == True:
self.streamFilm()
else:
self.userSelectFilmFromList()
self.streamFilm()
film=Films()
film.play()
El archivo CSV está delimitado por ; y tiene los siguientes campos:
Título;Año;Magnet
Por ejemplo:
EL corredor del Laberinto: Las Pruebas;2015;magnet:?xt=urn:btih:2813c7e559a98b8e11fd360c1af3773839bcc6dc&dn=El+corredor+del+laberinto-Las+pruebas+%282015%29.HDrip&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969
Este script lanza el reproductor VLC. Peerflix, el proceso al que llama subprocess, tiene otros parámetros como lanzar el vídeo en los reproductores omx o MPlayer.
