Пример #1
0
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")
	show, err := tvdb.NewShow(showId, "en")
	if err != nil {
		ctx.String(404, "")
		return
	}
	ShowPath := filepath.Join(ShowsLibraryPath, toFileName(show.SeriesName))

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

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

	xbmc.Notify("Quasar", "LOCALIZE[30222]", config.AddonIcon())
	ctx.String(200, "")
	xbmc.VideoLibraryClean()
	libraryLog.Info("Show removed")
}
Пример #2
0
func WriteShowStrm(showId string, ShowsLibraryPath string) error {
	show, err := tvdb.NewShow(showId, "en")
	if err != nil {
		return err
	}
	ShowPath := filepath.Join(ShowsLibraryPath, toFileName(show.SeriesName))

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

	now := time.Now().UTC()
	for _, season := range show.Seasons {
		if len(season.Episodes) == 0 {
			continue
		}
		airedDateTime := fmt.Sprintf("%s %s EST", season.Episodes[0].FirstAired, show.AirsTime)
		firstAired, _ := time.Parse("2006-01-02 3:04 PM MST", airedDateTime)
		if firstAired.Add(time.Duration(show.Runtime) * time.Minute).After(now) {
			continue
		}

		/*var SeasonPath string
		if season.Season == 0 {
			SeasonPath = filepath.Join(ShowPath, "Specials")
		} else {
			SeasonPath = filepath.Join(ShowPath, fmt.Sprintf("Season %d", season.Season))
		}

		if _, err := os.Stat(SeasonPath); os.IsNotExist(err) {
			if err := os.Mkdir(SeasonPath, 0755); err != nil {
				libraryLog.Info("Unable to create SeasonPath")
				return err
			}
		}*/

		for _, episode := range season.Episodes {
			if episode.FirstAired == "" {
				continue
			}
			airedDateTime := fmt.Sprintf("%s %s EST", episode.FirstAired, show.AirsTime)
			firstAired, _ := time.Parse("2006-01-02 3:04 PM MST", airedDateTime)
			if firstAired.Add(time.Duration(show.Runtime) * time.Minute).After(now) {
				continue
			}

			EpisodeStrmPath := filepath.Join(ShowPath, fmt.Sprintf("%s S%02dE%02d.strm", toFileName(show.SeriesName), season.Season, episode.EpisodeNumber))
			playLink := UrlForXBMC("/library/play/show/%s/season/%d/episode/%d", showId, season.Season, episode.EpisodeNumber)
			if err := ioutil.WriteFile(EpisodeStrmPath, []byte(playLink), 0755); err != nil {
				libraryLog.Error("Unable to write to EpisodeStrmPath")
				return err
			}
		}
	}

	return nil
}