-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b0cbc5
commit 4ad2a48
Showing
7 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,9 @@ backup | |
cleanup-ended-videos | ||
now | ||
|
||
dehydrate-posters | ||
force | ||
|
||
download-video | ||
video-id^*& | ||
mark-watched | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package cli | ||
|
||
import ( | ||
"errors" | ||
"github.com/boggydigital/issa" | ||
"github.com/boggydigital/kevlar" | ||
"github.com/boggydigital/nod" | ||
"github.com/boggydigital/pathways" | ||
"github.com/boggydigital/yet/data" | ||
"github.com/boggydigital/yet_urls/youtube_urls" | ||
"net/url" | ||
"os" | ||
) | ||
|
||
func DehydratePostersHandler(u *url.URL) error { | ||
force := u.Query().Has("force") | ||
return DehydratePosters(force) | ||
} | ||
|
||
func DehydratePosters(force bool) error { | ||
|
||
dpa := nod.NewProgress("dehydrating posters...") | ||
defer dpa.EndWithResult("done") | ||
|
||
metadataDir, err := pathways.GetAbsDir(data.Metadata) | ||
if err != nil { | ||
return dpa.EndWithError(err) | ||
} | ||
|
||
rdx, err := kevlar.NewReduxWriter(metadataDir, data.VideoProperties()...) | ||
if err != nil { | ||
return dpa.EndWithError(err) | ||
} | ||
|
||
videoIds := rdx.Keys(data.VideoTitleProperty) | ||
dpa.TotalInt(len(videoIds)) | ||
|
||
dehydratedPosters := make(map[string][]string) | ||
dehydratedRepColors := make(map[string][]string) | ||
|
||
for _, videoId := range videoIds { | ||
|
||
if rdx.HasKey(data.VideoDehydratedThumbnailProperty, videoId) && !force { | ||
dpa.Increment() | ||
continue | ||
} | ||
|
||
if dp, rc, err := dehydratePosterImageRepColor(videoId); err == nil { | ||
dehydratedPosters[videoId] = append(dehydratedPosters[videoId], dp) | ||
dehydratedRepColors[videoId] = append(dehydratedRepColors[videoId], rc) | ||
} else { | ||
dpa.Error(err) | ||
} | ||
|
||
dpa.Increment() | ||
} | ||
|
||
if err := rdx.BatchReplaceValues(data.VideoDehydratedThumbnailProperty, dehydratedPosters); err != nil { | ||
return dpa.EndWithError(err) | ||
} | ||
|
||
if err := rdx.BatchReplaceValues(data.VideoDehydratedRepColorProperty, dehydratedRepColors); err != nil { | ||
return dpa.EndWithError(err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func dehydratePosterImageRepColor(videoId string) (string, string, error) { | ||
|
||
var absPosterPath string | ||
var err error | ||
|
||
// find the first existing poster (if any if available at all) | ||
for _, q := range youtube_urls.AllThumbnailQualities() { | ||
absPosterPath, err = data.AbsPosterPath(videoId, q) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
if _, err := os.Stat(absPosterPath); err == nil { | ||
break | ||
} | ||
} | ||
|
||
if absPosterPath == "" { | ||
return "", "", errors.New("video has no poster thumbnails: " + videoId) | ||
} | ||
|
||
return issa.DehydrateImageRepColor(absPosterPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.