Skip to content

Commit

Permalink
peerflix for watching movies from torrent magnet
Browse files Browse the repository at this point in the history
  • Loading branch information
Dado555 committed Aug 16, 2022
1 parent bdbc190 commit ced7d24
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 22 deletions.
58 changes: 36 additions & 22 deletions scrape-movie-service/server.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
package main

import (
api2 "github.com/Dado555/glef.icu/scrape-movie-service/api"
"github.com/Dado555/glef.icu/scrape-movie-service/models"
routes2 "github.com/Dado555/glef.icu/scrape-movie-service/routes"
"github.com/rs/cors"
"net/http"
"fmt"
"github.com/Dado555/glef.icu/scrape-movie-service/utils"
"os/exec"
)

func main() {
connStr := "host=localhost port=5432 user=postgres dbname=movieService password=root"
func HandleWatchTorrentMagnet(magnet string) {
path, _ := utils.IsInstalledCMD("peerflix")

corsHandler := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{http.MethodPost, http.MethodConnect, http.MethodGet, http.MethodDelete,
http.MethodHead, http.MethodOptions, http.MethodPut, http.MethodTrace},
AllowedHeaders: []string{"*"},
AllowCredentials: false,
})
cmd := exec.Command("peerflix", "--vlc", magnet)
cmd.Dir = path

db := models.NewPostgresDatabase(connStr)
api := api2.CreateAPI(db)
routes := routes2.CreateRoutes(api)
if err := cmd.Run(); err != nil {
fmt.Printf("\n%s: %v\n", "Failed to run Peerflix", err)
}

handler := corsHandler.Handler(routes)
err := http.ListenAndServe(":3001", handler)
if err != nil {
panic(err)
return
if err := cmd.Wait(); err != nil {
fmt.Printf("\n%s: %v\n", "Peerflix returned an error", err)
}
}

func main() {
//connStr := "host=localhost port=5432 user=postgres dbname=movieService password=root"
//
//corsHandler := cors.New(cors.Options{
// AllowedOrigins: []string{"*"},
// AllowedMethods: []string{http.MethodPost, http.MethodConnect, http.MethodGet, http.MethodDelete,
// http.MethodHead, http.MethodOptions, http.MethodPut, http.MethodTrace},
// AllowedHeaders: []string{"*"},
// AllowCredentials: false,
//})
//
//db := models.NewPostgresDatabase(connStr)
//api := api2.CreateAPI(db)
//routes := routes2.CreateRoutes(api)
//
//handler := corsHandler.Handler(routes)
//err := http.ListenAndServe(":3001", handler)
//if err != nil {
// panic(err)
// return
//}
HandleWatchTorrentMagnet("magnet:?xt=urn:btih:F08FFD1B898307A70600F5BCBCC95839804025D7&dn=Harry+Potter+and+the+Deathly+Hallows%3A+Part+2&trudp://open.demonii.com:1337/announce&trudp://tracker.openbittorrent.com:80&trudp://tracker.coppersurfer.tk:6969&trudp://glotorrents.pw:6969/announce&trudp://tracker.opentrackr.org:1337/announce&trudp://torrent.gresille.org:80/announce&trudp://p4p.arenabg.com:1337&trudp://tracker.leechers-paradise.org:6969")
}
21 changes: 21 additions & 0 deletions scrape-movie-service/utils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package utils

import "os"

func IsInstalledCMD(cmd string) (string, bool) {
paths := []string{"/usr/bin/", "/usr/local/bin/"}
for i := 0; i < len(paths); i++ {
if IsFileExists(paths[i] + cmd) {
return paths[i], true
}
}
return "", false
}

func IsFileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}

0 comments on commit ced7d24

Please sign in to comment.