func (this *Downloader) TorrentAdd(uri string) error { if strings.HasPrefix(uri, "magnet:") { t, err := this.torrentAddFromMagnet(uri) if err != nil { return err } this.Torrent = t return nil } if strings.HasPrefix(uri, "http://") || strings.HasPrefix(uri, "https://") { t, err := this.torrentAddFromUrl(uri) if err != nil { return err } this.Torrent = t return nil } return errors.New( errors.DOWNLOADER_INVALID_URI_CODE, errors.DOWNLOADER_INVALID_URI_MESSAGE, uri, ) }
func New(uri string) (*Downloader, string, error) { var err error var id string var client *torrent.Client var downloader = &Downloader{} id = utils.CalcMd5(uri) downloader.Id = id client, err = torrent.NewClient(&torrent.Config{ DataDir: filepath.Join(os.TempDir(), "gochromecast"), NoUpload: true, Seed: true, }) if err != nil { return downloader, id, errors.New( errors.DOWNLOADER_CANNOT_CREATE_TCLIENT_CODE, errors.DOWNLOADER_CANNOT_CREATE_TCLIENT_MESSAGE, err, ) } downloader.Client = client return downloader, id, nil }
func (this *Downloader) GetFileFoPlay(path string) (t_file torrent.File, err error) { this.RLock() defer this.RUnlock() for _, t_file = range this.Torrent.Files() { if t_file.Path() == path { return } } return t_file, errors.New( errors.DOWNLOADER_FILE_NOT_FOUND_CODE, errors.DOWNLOADER_FILE_NOT_FOUND_MESSAGE, ) }