Beispiel #1
0
func NewBTService(config BTConfiguration) *BTService {
	s := &BTService{
		Session:           libtorrent.NewSession(),
		log:               logging.MustGetLogger("btservice"),
		libtorrentLog:     logging.MustGetLogger("libtorrent"),
		alertsBroadcaster: broadcast.NewBroadcaster(),
		config:            &config,
		closing:           make(chan interface{}),
	}

	if _, err := os.Stat(s.config.TorrentsPath); os.IsNotExist(err) {
		if err := os.Mkdir(s.config.TorrentsPath, 0755); err != nil {
			s.log.Error("Unable to create Torrents folder")
		}
	}

	s.configure()
	go s.saveResumeDataConsumer()
	go s.saveResumeDataLoop()
	go s.alertsConsumer()
	go s.logAlerts()

	if config.BackgroundHandling {
		go s.loadFastResumeFiles()
		go s.downloadProgress()
	}

	tmdb.CheckApiKey()

	return s
}
Beispiel #2
0
func NewBTPlayer(bts *BTService, uri string, deleteAfter bool) *BTPlayer {
	btp := &BTPlayer{
		bts:                  bts,
		uri:                  uri,
		log:                  logging.MustGetLogger("btplayer"),
		deleteAfter:          deleteAfter,
		closing:              make(chan interface{}),
		bufferEvents:         broadcast.NewBroadcaster(),
		bufferPiecesProgress: map[int]float64{},
	}
	return btp
}
Beispiel #3
0
func NewBTService(config BTConfiguration) *BTService {
	s := &BTService{
		Session:           libtorrent.NewSession(),
		log:               logging.MustGetLogger("btservice"),
		libtorrentLog:     logging.MustGetLogger("libtorrent"),
		alertsBroadcaster: broadcast.NewBroadcaster(),
		config:            &config,
		closing:           make(chan interface{}),
	}

	s.configure()
	go s.alertsConsumer()
	go s.logAlerts()
	go s.internetMonitor()

	return s
}
Beispiel #4
0
func NewTorrentFile(file *os.File, tfs *TorrentFS, torrentHandle libtorrent.TorrentHandle, torrentInfo libtorrent.TorrentInfo, fileEntry libtorrent.FileEntry, fileEntryIdx int) (*TorrentFile, error) {
	tf := &TorrentFile{
		File:          file,
		tfs:           tfs,
		torrentHandle: torrentHandle,
		torrentInfo:   torrentInfo,
		fileEntry:     fileEntry,
		fileEntryIdx:  fileEntryIdx,
		pieceLength:   torrentInfo.PieceLength(),
		fileOffset:    fileEntry.GetOffset(),
		fileSize:      fileEntry.GetSize(),
		removed:       broadcast.NewBroadcaster(),
	}
	go tf.consumeAlerts()

	return tf, nil
}
Beispiel #5
0
func NewBTPlayer(bts *BTService, uri string, fileIndex int, resume int, infoHash string) *BTPlayer {
	btp := &BTPlayer{
		bts:                  bts,
		uri:                  uri,
		infoHash:             infoHash,
		fileIndex:            fileIndex,
		log:                  logging.MustGetLogger("btplayer"),
		backgroundHandling:   config.Get().BackgroundHandling == true,
		deleteAfter:          config.Get().KeepFilesAfterStop == false,
		resume:               resume,
		fastResuming:         false,
		fastResumeFile:       "",
		closing:              make(chan interface{}),
		bufferEvents:         broadcast.NewBroadcaster(),
		bufferPiecesProgress: map[int]float64{},
	}
	return btp
}
Beispiel #6
0
func NewBTPlayer(bts *BTService, params BTPlayerParams) *BTPlayer {
	btp := &BTPlayer{
		log:                  logging.MustGetLogger("btplayer"),
		bts:                  bts,
		uri:                  params.URI,
		infoHash:             params.InfoHash,
		fileIndex:            params.FileIndex,
		resumeIndex:          params.ResumeIndex,
		overlayStatusEnabled: config.Get().EnableOverlayStatus == true,
		backgroundHandling:   config.Get().BackgroundHandling == true,
		deleteAfter:          config.Get().KeepFilesAfterStop == false,
		scrobble:             config.Get().Scrobble == true && params.TMDBId > 0 && config.Get().TraktToken != "",
		contentType:          params.ContentType,
		tmdbId:               params.TMDBId,
		runtime:              params.Runtime * 60,
		fastResumeFile:       "",
		notEnoughSpace:       false,
		closing:              make(chan interface{}),
		bufferEvents:         broadcast.NewBroadcaster(),
		bufferPiecesProgress: map[int]float64{},
	}
	return btp
}