Beispiel #1
0
func main() {
	if len(os.Args) <= 1 {
		usage()
	}

	storeDir := filepath.Join(util.EnvDefault("XDG_CONFIG_HOME", ".config"), "cpod")
	if err := os.MkdirAll(storeDir, 0755); err != nil {
		panic(err)
	}

	store, err := store.Load(filepath.Join(storeDir, "urls"))
	if err != nil && !os.IsNotExist(err) {
		panic(err)
	}

	outlines, err := load(os.Args)
	if err != nil {
		panic(err)
	}

	for _, outline := range outlines {
		url := outline.URL
		if !store.Contains(url) {
			store.Add(url)
		}
	}

	if err = store.Save(); err != nil {
		panic(err)
	}
}
Beispiel #2
0
func main() {
	flag.Parse()
	if *version {
		logger.Fatal(appVersion)
	}

	storeDir := filepath.Join(util.EnvDefault("XDG_CONFIG_HOME", ".config"), appName)
	lockPath := filepath.Join(os.TempDir(), fmt.Sprintf("%s-%s", appName, util.Username()))

	if err := util.Lock(lockPath); os.IsExist(err) {
		logger.Fatalf("database is locked, remove %q to force unlock\n", lockPath)
	} else if err != nil {
		logger.Fatal(err)
	}

	storage, err := store.Load(filepath.Join(storeDir, "urls"))
	if err != nil {
		logger.Fatal(err)
	}

	update(storage)
	if err := os.Remove(lockPath); err != nil {
		logger.Fatal(err)
	}
}
Beispiel #3
0
func main() {
	if len(os.Args) <= 1 {
		usage()
	}

	storeDir := filepath.Join(util.EnvDefault("XDG_CONFIG_HOME", ".config"), "cpod")
	storage, err := store.Load(filepath.Join(storeDir, "urls"))
	if err != nil {
		panic(err)
	}

	var wg sync.WaitGroup
	opmlFile := opml.Create(title)

	for cast := range storage.Fetch() {
		wg.Add(1)
		go func(p store.Podcast) {
			defer wg.Done()
			if p.Error != nil {
				fmt.Fprintf(os.Stderr, "%s\n", p.Error)
				return
			}

			feed := p.Feed
			opmlFile.Add(feed.Title, feed.Type, p.URL)
		}(cast)
	}

	wg.Wait()
	if err = opmlFile.Save(os.Args[1]); err != nil {
		panic(err)
	}
}
Beispiel #4
0
)

const (
	appName    = "cpod"
	appVersion = "1.9"
)

var (
	limit   = flag.Int("p", 5, "number of maximal parallel downloads")
	recent  = flag.Int("r", 0, "number of most recent episodes to download")
	version = flag.Bool("v", false, "display version number and exit")
)

var (
	logger      = log.New(os.Stderr, fmt.Sprintf("%s: ", appName), 0)
	downloadDir = util.EnvDefault("CPOD_DOWNLOAD_DIR", "podcasts")
)

func main() {
	flag.Parse()
	if *version {
		logger.Fatal(appVersion)
	}

	storeDir := filepath.Join(util.EnvDefault("XDG_CONFIG_HOME", ".config"), appName)
	lockPath := filepath.Join(os.TempDir(), fmt.Sprintf("%s-%s", appName, util.Username()))

	if err := util.Lock(lockPath); os.IsExist(err) {
		logger.Fatalf("database is locked, remove %q to force unlock\n", lockPath)
	} else if err != nil {
		logger.Fatal(err)