Beispiel #1
0
func Lookup(ctx *gin.Context) {
	var db DataBase

	LibraryPath := config.Get().LibraryPath
	DBPath := filepath.Join(LibraryPath, fmt.Sprintf("%s.json", DBName))

	if _, err := os.Stat(DBPath); err == nil {
		file, err := ioutil.ReadFile(DBPath)
		if err != nil {
			ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*")
			ctx.JSON(200, gin.H{
				"success": false,
			})
			return
		}
		json.Unmarshal(file, &db)
	}

	Movies := make([]*Item, 0, len(db.Movies))
	Shows := make([]*Item, 0, len(db.Shows))

	for i := 0; i < len(db.Movies); i++ {
		movie := tmdb.GetMovieById(db.Movies[i], "en")
		Movies = append(Movies, &Item{
			Id:       db.Movies[i],
			Title:    movie.OriginalTitle,
			Year:     strings.Split(movie.ReleaseDate, "-")[0],
			Overview: movie.Overview,
			Poster:   tmdb.ImageURL(movie.PosterPath, "w500"),
		})
	}

	for i := 0; i < len(db.Shows); i++ {
		showId, _ := strconv.Atoi(db.Shows[i])
		show := tmdb.GetShow(showId, "en")
		if show == nil {
			ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*")
			ctx.JSON(200, gin.H{
				"success": false,
			})
			return
		}
		Shows = append(Shows, &Item{
			Id:       db.Shows[i],
			Title:    show.Name,
			Year:     strings.Split(show.FirstAirDate, "-")[0],
			Overview: show.Overview,
			Poster:   tmdb.ImageURL(show.PosterPath, "w500"),
		})
	}

	ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*")
	ctx.JSON(200, gin.H{
		"success": true,
		"results": gin.H{
			"movies": Movies,
			"shows":  Shows,
		},
	})
}
Beispiel #2
0
func RemoveMovie(ctx *gin.Context) {
	LibraryPath := config.Get().LibraryPath
	MoviesLibraryPath := filepath.Join(LibraryPath, "Movies")
	DBPath := filepath.Join(LibraryPath, fmt.Sprintf("%s.json", DBName))
	tmdbId := ctx.Params.ByName("tmdbId")
	movie := tmdb.GetMovieById(tmdbId, "en")
	MovieStrm := toFileName(fmt.Sprintf("%s (%s)", movie.OriginalTitle, strings.Split(movie.ReleaseDate, "-")[0]))
	MoviePath := filepath.Join(MoviesLibraryPath, MovieStrm)

	if err := RemoveFromJsonDB(DBPath, tmdbId, LMovie); err != nil {
		libraryLog.Error("Unable to remove movie from db")
		ctx.String(404, "")
		return
	}

	if err := os.RemoveAll(MoviePath); err != nil {
		libraryLog.Error("Unable to remove movie folder")
		ctx.String(404, "")
		return
	}

	xbmc.Notify("Quasar", "LOCALIZE[30222]", config.AddonIcon())
	ctx.String(200, "")
	xbmc.VideoLibraryClean()
	ClearCache(ctx)
	xbmc.Refresh()
	libraryLog.Notice("Movie removed")
}
Beispiel #3
0
func movieLinks(tmdbId string) ([]*bittorrent.Torrent, string) {
	log.Println("Searching links for:", tmdbId)

	movie := tmdb.GetMovieById(tmdbId, config.Get().Language)

	log.Printf("Resolved %s to %s", tmdbId, movie.Title)

	searchers := providers.GetMovieSearchers()
	if len(searchers) == 0 {
		xbmc.Notify("Quasar", "LOCALIZE[30204]", config.AddonIcon())
	}

	return providers.SearchMovie(searchers, movie), movie.Title
}
Beispiel #4
0
func WriteMovieStrm(tmdbId string, MoviesLibraryPath string) error {
	movie := tmdb.GetMovieById(tmdbId, "en")
	MovieStrm := toFileName(fmt.Sprintf("%s (%s)", movie.OriginalTitle, strings.Split(movie.ReleaseDate, "-")[0]))
	MoviePath := filepath.Join(MoviesLibraryPath, MovieStrm)

	if _, err := os.Stat(MoviePath); os.IsNotExist(err) {
		if err := os.Mkdir(MoviePath, 0755); err != nil {
			libraryLog.Error("Unable to create path for Movies")
			return err
		}
	}

	MovieStrmPath := filepath.Join(MoviePath, fmt.Sprintf("%s.strm", MovieStrm))
	if err := ioutil.WriteFile(MovieStrmPath, []byte(UrlForXBMC("/library/play/movie/%s", tmdbId)), 0644); err != nil {
		libraryLog.Error("Unable to write to strm file for movie")
		return err
	}

	return nil
}
Beispiel #5
0
func MoviePlay(ctx *gin.Context) {
	tmdbId := ctx.Params.ByName("tmdbId")
	torrents := movieLinks(tmdbId)
	if len(torrents) == 0 {
		xbmc.Notify("Quasar", "LOCALIZE[30205]", config.AddonIcon())
		return
	}

	movie := tmdb.GetMovieById(tmdbId, "")
	runtime := 120
	if movie.Runtime > 0 {
		runtime = movie.Runtime
	}

	sort.Sort(sort.Reverse(providers.ByQuality(torrents)))

	AddToTorrentsMap(tmdbId, torrents[0])

	rUrl := UrlQuery(UrlForXBMC("/play"), "uri", torrents[0].Magnet(),
		"tmdb", tmdbId,
		"type", "movie",
		"runtime", strconv.Itoa(runtime))
	ctx.Redirect(302, rUrl)
}
Beispiel #6
0
func ProviderGetMovie(ctx *gin.Context) {
	tmdbId := ctx.Params.ByName("tmdbId")
	provider := ctx.Params.ByName("provider")
	log.Println("Searching links for:", tmdbId)
	movie := tmdb.GetMovieById(tmdbId, "en")
	log.Printf("Resolved %s to %s", tmdbId, movie.Title)

	searcher := providers.NewAddonSearcher(provider)
	torrents := searcher.SearchMovieLinks(movie)
	if ctx.Request.URL.Query().Get("resolve") == "true" {
		for _, torrent := range torrents {
			torrent.Resolve()
		}
	}
	data, err := json.MarshalIndent(providerDebugResponse{
		Payload: searcher.GetMovieSearchObject(movie),
		Results: torrents,
	}, "", "    ")
	if err != nil {
		xbmc.AddonFailure(provider)
		ctx.Error(err)
	}
	ctx.Data(200, "application/json", data)
}
Beispiel #7
0
func MovieLinks(ctx *gin.Context) {
	tmdbId := ctx.Params.ByName("tmdbId")
	torrents := movieLinks(tmdbId)

	if len(torrents) == 0 {
		xbmc.Notify("Quasar", "LOCALIZE[30205]", config.AddonIcon())
		return
	}

	choices := make([]string, 0, len(torrents))
	for _, torrent := range torrents {
		resolution := ""
		if torrent.Resolution > 0 {
			resolution = fmt.Sprintf("[B][COLOR %s]%s[/COLOR][/B] ", bittorrent.Colors[torrent.Resolution], bittorrent.Resolutions[torrent.Resolution])
		}

		info := make([]string, 0)
		if torrent.Size != "" {
			info = append(info, fmt.Sprintf("[B][%s][/B]", torrent.Size))
		}
		if torrent.RipType > 0 {
			info = append(info, bittorrent.Rips[torrent.RipType])
		}
		if torrent.VideoCodec > 0 {
			info = append(info, bittorrent.Codecs[torrent.VideoCodec])
		}
		if torrent.AudioCodec > 0 {
			info = append(info, bittorrent.Codecs[torrent.AudioCodec])
		}
		if torrent.Provider != "" {
			info = append(info, fmt.Sprintf(" - [B]%s[/B]", torrent.Provider))
		}

		multi := ""
		if torrent.Multi {
			multi = "\nmulti"
		}

		label := fmt.Sprintf("%s(%d / %d) %s\n%s\n%s%s",
			resolution,
			torrent.Seeds,
			torrent.Peers,
			strings.Join(info, " "),
			torrent.Name,
			torrent.Icon,
			multi,
		)
		choices = append(choices, label)
	}

	movie := tmdb.GetMovieById(tmdbId, config.Get().Language)
	runtime := 120
	if movie.Runtime > 0 {
		runtime = movie.Runtime
	}

	choice := xbmc.ListDialogLarge("LOCALIZE[30228]", movie.Title, choices...)
	if choice >= 0 {
		AddToTorrentsMap(tmdbId, torrents[choice])

		rUrl := UrlQuery(UrlForXBMC("/play"), "uri", torrents[choice].Magnet(),
			"tmdb", tmdbId,
			"type", "movie",
			"runtime", strconv.Itoa(runtime))
		ctx.Redirect(302, rUrl)
	}
}