Add support for 'mobile' twitter links
This commit is contained in:
parent
8b81dafd28
commit
d98f02954e
@ -80,9 +80,18 @@ func get_thumbnail_local_path(remote_url string) string {
|
|||||||
* Given an URL, try to parse it as a tweet url.
|
* Given an URL, try to parse it as a tweet url.
|
||||||
* The bool is an `is_ok` value; true if the parse was successful, false if it didn't match
|
* The bool is an `is_ok` value; true if the parse was successful, false if it didn't match
|
||||||
*/
|
*/
|
||||||
func TryParseTweetUrl(url string) (UserHandle, TweetID, bool) {
|
func TryParseTweetUrl(s string) (UserHandle, TweetID, bool) {
|
||||||
r := regexp.MustCompile(`^https://twitter.com/(\w+)/status/(\d+)(?:\?.*)?$`)
|
parsed_url, err := url.Parse(s)
|
||||||
matches := r.FindStringSubmatch(url)
|
if err != nil {
|
||||||
|
return UserHandle(""), TweetID(0), false
|
||||||
|
}
|
||||||
|
|
||||||
|
if parsed_url.Host != "twitter.com" && parsed_url.Host != "mobile.twitter.com" {
|
||||||
|
return UserHandle(""), TweetID(0), false
|
||||||
|
}
|
||||||
|
|
||||||
|
r := regexp.MustCompile(`^/(\w+)/status/(\d+)$`)
|
||||||
|
matches := r.FindStringSubmatch(parsed_url.Path)
|
||||||
if matches == nil {
|
if matches == nil {
|
||||||
return UserHandle(""), TweetID(0), false
|
return UserHandle(""), TweetID(0), false
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,12 @@ func TestParseTweetUrl(t *testing.T) {
|
|||||||
assert.Equal(UserHandle("NerdNoticing"), handle)
|
assert.Equal(UserHandle("NerdNoticing"), handle)
|
||||||
assert.Equal(TweetID(1263192389050654720), id)
|
assert.Equal(TweetID(1263192389050654720), id)
|
||||||
|
|
||||||
|
// Test a `mobile.twitter.com` url
|
||||||
|
handle, id, is_ok = TryParseTweetUrl("https://mobile.twitter.com/APhilosophae/status/1497720548540964864")
|
||||||
|
assert.True(is_ok)
|
||||||
|
assert.Equal(UserHandle("APhilosophae"), handle)
|
||||||
|
assert.Equal(TweetID(1497720548540964864), id)
|
||||||
|
|
||||||
// Test invalid url
|
// Test invalid url
|
||||||
_, _, is_ok = TryParseTweetUrl("https://twitter.com/NerdNoticing/status/1263192389050654720s=20")
|
_, _, is_ok = TryParseTweetUrl("https://twitter.com/NerdNoticing/status/1263192389050654720s=20")
|
||||||
assert.False(is_ok)
|
assert.False(is_ok)
|
||||||
|
@ -41,7 +41,7 @@ func GetUserFeedGraphqlFor(user_id UserID, min_tweets int) (trove TweetTrove, er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(api_response.Data.User.Result.Timeline.Timeline.Instructions[0].Entries) < min_tweets && api_response.GetCursorBottom() != "" {
|
if len(api_response.GetMainInstruction().Entries) < min_tweets && api_response.GetCursorBottom() != "" {
|
||||||
err = api.GetMoreTweetsFromGraphqlFeed(user_id, &api_response, min_tweets)
|
err = api.GetMoreTweetsFromGraphqlFeed(user_id, &api_response, min_tweets)
|
||||||
if err != nil && !errors.Is(err, END_OF_FEED) {
|
if err != nil && !errors.Is(err, END_OF_FEED) {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user