Skip to content

Commit

Permalink
Added missing subtitles for --dry flag
Browse files Browse the repository at this point in the history
  • Loading branch information
tympanix committed Jan 22, 2018
1 parent 68b9393 commit ab06476
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion api/api_subtitle.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (a *API) downloadSubtitles(w http.ResponseWriter, r *http.Request) interfac
if err != nil {
return Error(err, http.StatusBadRequest)
}
err = a.DownloadSubtitles(media, langs, ioutil.Discard)
_, err = a.DownloadSubtitles(media, langs, ioutil.Discard)
if err != nil {
return Error(err, http.StatusBadRequest)
}
Expand Down
10 changes: 5 additions & 5 deletions app/app_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var red = color.New(color.FgRed)

// DownloadSubtitles downloads subtitles for a whole list of mediafiles for every
// langauge in the language set. Any output is written to the ourpur writer
func (a *Application) DownloadSubtitles(media types.LocalMediaList, lang set.Interface, out io.Writer) error {
func (a *Application) DownloadSubtitles(media types.LocalMediaList, lang set.Interface, out io.Writer) (int, error) {
numsubs := 0

dry := a.Context().GlobalBool("dry")
Expand All @@ -29,7 +29,7 @@ func (a *Application) DownloadSubtitles(media types.LocalMediaList, lang set.Int
cursubs, err := item.ExistingSubtitles()

if err != nil {
return cli.NewExitError(err, 2)
return -1, cli.NewExitError(err, 2)
}

missingLangs := set.Difference(lang, cursubs.LanguageSet())
Expand All @@ -45,7 +45,7 @@ func (a *Application) DownloadSubtitles(media types.LocalMediaList, lang set.Int
if !dry {
search, err := a.SearchSubtitles(item)
if err != nil {
return cli.NewExitError(err, 2)
return -1, cli.NewExitError(err, 2)
}
for _, s := range search {
subs.Add(s)
Expand All @@ -61,7 +61,7 @@ func (a *Application) DownloadSubtitles(media types.LocalMediaList, lang set.Int
numsubs++

if !ok {
return cli.NewExitError(err, 3)
return -1, cli.NewExitError(err, 3)
}

langsubs := subs.FilterLanguage(l)
Expand All @@ -86,5 +86,5 @@ func (a *Application) DownloadSubtitles(media types.LocalMediaList, lang set.Int
green.Fprintf(out, " - %v\n", display.English.Languages().Name(l))
}
}
return nil
return numsubs, nil
}
8 changes: 5 additions & 3 deletions supper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {

app := cli.NewApp()
app.Name = "supper"
app.Version = "0.1.2"
app.Version = "0.1.3"
app.Usage = "An automatic subtitle downloader"

app.Commands = []cli.Command{
Expand Down Expand Up @@ -133,15 +133,17 @@ func main() {
return cli.NewExitError(err, 3)
}

if err := sup.DownloadSubtitles(media, lang, os.Stdout); err != nil {
numsubs, err := sup.DownloadSubtitles(media, lang, os.Stdout)

if err != nil {
return cli.NewExitError(err, 5)
}

if c.Bool("dry") {
fmt.Println()
color.Blue("dry run, nothing performed")
color.Blue("total media files: %v", media.Len())
//color.Blue("total missing subtitles: %v", numsubs)
color.Blue("total missing subtitles: %v", numsubs)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion types/app_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ type App interface {
Context() *cli.Context
FindMedia(...string) (LocalMediaList, error)
Languages() set.Interface
DownloadSubtitles(LocalMediaList, set.Interface, io.Writer) error
DownloadSubtitles(LocalMediaList, set.Interface, io.Writer) (int, error)
}

0 comments on commit ab06476

Please sign in to comment.