コード例 #1
0
ファイル: library.go プロジェクト: i96751414/quasar
func RemoveShow(ctx *gin.Context) {
	LibraryPath := config.Get().LibraryPath
	ShowsLibraryPath := filepath.Join(LibraryPath, "Shows")
	DBPath := filepath.Join(LibraryPath, fmt.Sprintf("%s.json", DBName))
	showId := ctx.Params.ByName("showId")
	Id, _ := strconv.Atoi(showId)
	show := tmdb.GetShow(Id, "en")
	if show == nil {
		ctx.String(404, "")
		return
	}
	ShowStrm := toFileName(fmt.Sprintf("%s (%s)", show.Name, strings.Split(show.FirstAirDate, "-")[0]))
	ShowPath := filepath.Join(ShowsLibraryPath, ShowStrm)

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

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

	xbmc.Notify("Quasar", "LOCALIZE[30222]", config.AddonIcon())
	ctx.String(200, "")
	xbmc.VideoLibraryClean()
	ClearCache(ctx)
	xbmc.Refresh()
	libraryLog.Notice("Show removed")
}
コード例 #2
0
ファイル: torrents.go プロジェクト: abuisine/quasar
func ResumeSession(btService *bittorrent.BTService) gin.HandlerFunc {
	return func(ctx *gin.Context) {
		btService.Session.Resume()
		xbmc.Refresh()
		ctx.String(200, "")
	}
}
コード例 #3
0
ファイル: library.go プロジェクト: i96751414/quasar
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")
}
コード例 #4
0
ファイル: providers.go プロジェクト: i96751414/quasar
func ProviderDisable(ctx *gin.Context) {
	addonId := ctx.Params.ByName("provider")
	xbmc.SetAddonEnabled(addonId, false)
	path := xbmc.InfoLabel("Container.FolderPath")
	if path == "plugin://plugin.video.quasar/provider/" {
		xbmc.Refresh()
	}
	ctx.String(200, "")
}
コード例 #5
0
ファイル: trakt.go プロジェクト: scakemyer/quasar
func AddShowToWatchlist(ctx *gin.Context) {
	tmdbId := ctx.Params.ByName("showId")
	resp, err := trakt.AddToWatchlist("shows", tmdbId)
	if err != nil {
		xbmc.Notify("Quasar", err.Error(), config.AddonIcon())
	} else if resp.Status() != 201 {
		xbmc.Notify("Quasar", fmt.Sprintf("Failed %d", resp.Status()), config.AddonIcon())
	} else {
		xbmc.Notify("Quasar", "Show added to watchlist", config.AddonIcon())
		os.RemoveAll(filepath.Join(config.Get().Info.Profile, "cache"))
		xbmc.Refresh()
	}
}
コード例 #6
0
ファイル: trakt.go プロジェクト: scakemyer/quasar
func RemoveMovieFromWatchlist(ctx *gin.Context) {
	tmdbId := ctx.Params.ByName("tmdbId")
	resp, err := trakt.RemoveFromWatchlist("movies", tmdbId)
	if err != nil {
		xbmc.Notify("Quasar", err.Error(), config.AddonIcon())
	} else if resp.Status() != 200 {
		xbmc.Notify("Quasar", fmt.Sprintf("Failed with %d status code", resp.Status()), config.AddonIcon())
	} else {
		xbmc.Notify("Quasar", "Movie removed from watchlist", config.AddonIcon())
		os.RemoveAll(filepath.Join(config.Get().Info.Profile, "cache"))
		xbmc.Refresh()
	}
}
コード例 #7
0
ファイル: trakt.go プロジェクト: scakemyer/quasar
func AddMovieToCollection(ctx *gin.Context) {
	tmdbId := ctx.Params.ByName("tmdbId")
	resp, err := trakt.AddToCollection("movies", tmdbId)
	if err != nil {
		xbmc.Notify("Quasar", err.Error(), config.AddonIcon())
	} else if resp.Status() != 201 {
		xbmc.Notify("Quasar", fmt.Sprintf("Failed with %d status code", resp.Status()), config.AddonIcon())
	} else {
		xbmc.Notify("Quasar", "Movie added to collection", config.AddonIcon())
		os.RemoveAll(filepath.Join(config.Get().Info.Profile, "cache"))
		xbmc.Refresh()
	}
}
コード例 #8
0
ファイル: library.go プロジェクト: i96751414/quasar
func AddShow(ctx *gin.Context) {
	LibraryPath := config.Get().LibraryPath
	DBPath := filepath.Join(LibraryPath, fmt.Sprintf("%s.json", DBName))

	if fileInfo, err := os.Stat(LibraryPath); err != nil || fileInfo.IsDir() == false || LibraryPath == "" || LibraryPath == "." {
		xbmc.Notify("Quasar", "LOCALIZE[30220]", config.AddonIcon())
		ctx.String(404, "")
		return
	}

	showId := ctx.Params.ByName("showId")

	if inJsonDb, err := InJsonDB(showId, LShow); err != nil || inJsonDb == true {
		ctx.String(404, "")
		return
	}

	ShowsLibraryPath := filepath.Join(LibraryPath, "Shows")
	if _, err := os.Stat(ShowsLibraryPath); os.IsNotExist(err) {
		if err := os.Mkdir(ShowsLibraryPath, 0755); err != nil {
			libraryLog.Error("Unable to create library path for Shows")
			ctx.String(404, "")
			return
		}
	}

	if err := WriteShowStrm(showId, ShowsLibraryPath); err != nil {
		ctx.String(404, "")
		return
	}

	if err := UpdateJsonDB(DBPath, showId, LShow); err != nil {
		libraryLog.Error("Unable to update json DB")
		ctx.String(404, "")
		return
	}

	xbmc.Notify("Quasar", "LOCALIZE[30221]", config.AddonIcon())
	ctx.String(200, "")
	xbmc.VideoLibraryScan()
	ClearCache(ctx)
	xbmc.Refresh()
	libraryLog.Notice("Show added")
}
コード例 #9
0
ファイル: torrents.go プロジェクト: abuisine/quasar
func ResumeTorrent(btService *bittorrent.BTService) gin.HandlerFunc {
	return func(ctx *gin.Context) {
		torrentsVector := btService.Session.GetTorrents()
		torrentId := ctx.Params.ByName("torrentId")
		torrentIndex, _ := strconv.Atoi(torrentId)
		torrentHandle := torrentsVector.Get(torrentIndex)

		if torrentHandle == nil {
			ctx.Error(errors.New(fmt.Sprintf("Unable to resume torrent with index %d", torrentIndex)))
		}

		status := torrentHandle.Status(uint(libtorrent.TorrentHandleQueryName))

		torrentName := status.GetName()
		torrentsLog.Infof("Resuming %s", torrentName)

		torrentHandle.AutoManaged(true)

		xbmc.Refresh()
		ctx.String(200, "")
	}
}
コード例 #10
0
ファイル: torrents.go プロジェクト: abuisine/quasar
func RemoveTorrent(btService *bittorrent.BTService) gin.HandlerFunc {
	return func(ctx *gin.Context) {
		btService.Session.GetTorrents()
		torrentsVector := btService.Session.GetTorrents()
		torrentId := ctx.Params.ByName("torrentId")
		torrentIndex, _ := strconv.Atoi(torrentId)
		torrentHandle := torrentsVector.Get(torrentIndex)
		if torrentHandle.IsValid() == false {
			ctx.Error(errors.New("Invalid torrent handle"))
		}
		torrentInfo := torrentHandle.TorrentFile()

		if torrentInfo != nil && torrentInfo.Swigcptr() != 0 {
			libtorrent.DeleteTorrentInfo(torrentInfo)
		}

		// Delete fast resume data
		torrentStatus := torrentHandle.Status(uint(libtorrent.TorrentHandleQuerySavePath) | uint(libtorrent.TorrentHandleQueryName))
		shaHash := torrentStatus.GetInfoHash().ToString()
		infoHash := hex.EncodeToString([]byte(shaHash))
		fastResumeFile := filepath.Join(config.Get().TorrentsPath, fmt.Sprintf("%s.fastresume", infoHash))
		if _, err := os.Stat(fastResumeFile); err == nil {
			torrentsLog.Infof("Deleting fast resume data at %s", fastResumeFile)
			defer os.Remove(fastResumeFile)
		}

		if config.Get().KeepFilesAfterStop == false {
			torrentsLog.Info("Removing the torrent and deleting files...")
			btService.Session.RemoveTorrent(torrentHandle, int(libtorrent.SessionDeleteFiles))
		} else {
			torrentsLog.Info("Removing the torrent without deleting files...")
			btService.Session.RemoveTorrent(torrentHandle, 0)
		}

		xbmc.Refresh()
		ctx.String(200, "")
	}
}
コード例 #11
0
ファイル: torrents.go プロジェクト: abuisine/quasar
func PauseTorrent(btService *bittorrent.BTService) gin.HandlerFunc {
	return func(ctx *gin.Context) {
		btService.Session.GetTorrents()
		torrentsVector := btService.Session.GetTorrents()
		torrentId := ctx.Params.ByName("torrentId")
		torrentIndex, _ := strconv.Atoi(torrentId)
		torrentHandle := torrentsVector.Get(torrentIndex)
		if torrentHandle.IsValid() == false {
			ctx.Error(errors.New("Invalid torrent handle"))
		}
		torrentInfo := torrentHandle.TorrentFile()

		if torrentInfo != nil && torrentInfo.Swigcptr() != 0 {
			libtorrent.DeleteTorrentInfo(torrentInfo)
		}

		torrentsLog.Info(fmt.Sprintf("Pausing torrent %s", torrentHandle.Status(uint(0)).GetName()))
		torrentHandle.AutoManaged(false)
		torrentHandle.Pause(1)

		xbmc.Refresh()
		ctx.String(200, "")
	}
}