Skip to content

Commit

Permalink
Sort qualities from high to low
Browse files Browse the repository at this point in the history
Fix a rare case which resulted in two same gif sizes
Bumped dependencies
Bumped version
  • Loading branch information
HirbodBehnam committed Jul 15, 2022
1 parent e017e21 commit f06f86a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// Version is the version of this program :|
const Version = "2.4.0"
const Version = "2.4.1"

// GlobalHttpClient is a http client which all request must be done through it
var GlobalHttpClient = &http.Client{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/PuerkitoBio/goquery v1.8.0
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/google/uuid v1.3.0
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 // indirect
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
)

require github.com/go-faster/errors v0.6.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 h1:Yqz/iviulwKwAREEeUd3nbBFn0XuyJqkoft2IlrvOhc=
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220708220712-1185a9018129 h1:vucSRfWwTsoXro7P+3Cjlr6flUMtzCwzlvkxEQtHHB0=
golang.org/x/net v0.0.0-20220708220712-1185a9018129/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
28 changes: 17 additions & 11 deletions reddit/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,23 +427,29 @@ func getGalleryData(files map[string]interface{}, galleryDataItems []interface{}
// extractPhotoGifQualities creates an array of FetchResultMediaEntry which are the qualities
// of the photo or gif and their links
func extractPhotoGifQualities(data map[string]interface{}) []FetchResultMediaEntry {
result := make([]FetchResultMediaEntry, 1+len(data["resolutions"].([]interface{})))
// Now get all other thumbs
for i, v := range data["resolutions"].([]interface{}) {
u, w, h := extractLinkAndRes(v)
result[i] = FetchResultMediaEntry{
Link: u,
Quality: w + "×" + h,
}
}
resolutions := data["resolutions"].([]interface{})
result := make([]FetchResultMediaEntry, 0, 1+len(resolutions))
// Include source image at last to keep the increasing quality
// Just a note for myself: This source is different from the one in the url field of root
// Just a note for myself: This can be different from the one in resolutions
{
u, w, h := extractLinkAndRes(data["source"])
result[len(result)-1] = FetchResultMediaEntry{
result = append(result, FetchResultMediaEntry{
Link: u,
Quality: w + "×" + h,
})
}
// Now get all other thumbs
for i := len(resolutions) - 1; i >= 0; i-- {
u, w, h := extractLinkAndRes(resolutions[i])
if i == len(resolutions)-1 { // In first case, the sizes can be same. Example: https://www.reddit.com/r/dankmemes/comments/vqphiy/more_than_bargain_for/
if w+"×"+h == result[0].Quality {
continue
}
}
result = append(result, FetchResultMediaEntry{
Link: u,
Quality: w + "×" + h,
})
}
return result
}
Expand Down

0 comments on commit f06f86a

Please sign in to comment.