chiark / gitweb /
Expand video URLs
authorMatthew Vernon <matthewv@chiark.greenend.org.uk>
Fri, 20 May 2016 13:29:57 +0000 (14:29 +0100)
committerMatthew Vernon <matthewv@chiark.greenend.org.uk>
Fri, 20 May 2016 13:29:57 +0000 (14:29 +0100)
The previous patch gave you the photo link for the video, not the
video itself; this fixes that (and handles non-ascii better again,
though it's a bit of a hack having to UTF-8 it twice).

patch by adam

commands.py

index ec133f581869e488cd492a733582c24676997a75..ce6b199589c628117aa137811de023606036d929 100755 (executable)
@@ -519,7 +519,9 @@ def getTweet(urlstring,twitapi):
 
     for medium in status.media:
         if "media_url_https" in medium:
-            tweetText = tweetText.replace(medium["url"], medium["media_url_https"])
+            link = medium["media_url_https"]
+            link = re.sub(r"/tweet_video_thumb/(\w+).jpg", r"/tweet_video/\1.mp4", link)
+            tweetText = tweetText.replace(medium["url"], link)
     for url in status.urls:
         toReplace = url.expanded_url
 
@@ -535,6 +537,7 @@ def getTweet(urlstring,twitapi):
     tweetText = tweetText.replace("&gt;",">")
     tweetText = tweetText.replace("&lt;","<")
     tweetText = tweetText.replace("&amp;","&")
+    tweetText = tweetText.encode('UTF-8', 'replace')
 
     stringout = "tweet by %s (%s): %s" %(tweeter_screen,tweeter_name,tweetText)
   except twitter.TwitterError: