Merge lp:~ken-vandine/gwibber/twitter-entities into lp:~markjtully/gwibber/twitter-entities

Proposed by Ken VanDine
Status: Merged
Merged at revision: 1304
Proposed branch: lp:~ken-vandine/gwibber/twitter-entities
Merge into: lp:~markjtully/gwibber/twitter-entities
Diff against target: 176 lines (+39/-20)
3 files modified
gwibber/microblog/plugins/twitter/__init__.py (+29/-13)
gwibber/microblog/util/__init__.py (+5/-5)
libgwibber-gtk/stream-view-tile.vala (+5/-2)
To merge this branch: bzr merge lp:~ken-vandine/gwibber/twitter-entities
Reviewer Review Type Date Requested Status
Mark Tully Approve
Review via email: mp+95649@code.launchpad.net

Description of the change

Fixed some escaping issues to make sure all links get caught and displayed

To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Another issue I found is some private messages get picked up as a link now so they don't end up in the private stream. Perhaps that is a bug more on the client side, how it is being displayed. I haven't really investigated. I am not even sure we don't want links from the private stream to display under links, it actually makes sense for them to be there. But if they are I guess we should signify somehow that it was private.

1302. By Ken VanDine

removed unneeded debug output

1303. By Ken VanDine

twitter: linkify posts that don't have entities included

1304. By Ken VanDine

twtiter: unset type for private and responses, so they don't end up in the links stream

1305. By Ken VanDine

include the url in videos and images

1306. By Ken VanDine

don't fail loading thumbnails for videos

Revision history for this message
Mark Tully (markjtully) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gwibber/microblog/plugins/twitter/__init__.py'
2--- gwibber/microblog/plugins/twitter/__init__.py 2012-02-24 20:13:33 +0000
3+++ gwibber/microblog/plugins/twitter/__init__.py 2012-03-02 23:13:21 +0000
4@@ -75,7 +75,6 @@
5 def _common(self, data):
6 m = {}
7 try:
8-
9 m["mid"] = str(data["id"])
10 m["service"] = "twitter"
11 m["account"] = self.account["id"]
12@@ -117,8 +116,7 @@
13 # Get url entities - These usually go in the link stream, but if they're picturesor videos, they should go in the proper stream
14 if data["entities"].has_key("urls"):
15 for urls in data["entities"]["urls"]:
16-
17- url = urls["url"]
18+ url = cgi.escape (urls["url"])
19 expanded_url = url
20 if urls.has_key("expanded_url"):
21 if not urls["expanded_url"] is None:
22@@ -126,13 +124,20 @@
23
24 display_url = url
25 if urls.has_key("display_url"):
26- display_url = urls["display_url"]
27+ display_url = cgi.escape (urls["display_url"])
28
29- startindex = m["content"].index(url)
30- endindex = startindex + len(url)
31- start = m["content"][0:startindex]
32- end = m["content"][endindex:]
33- m["content"] = start + "<a href='" + url + "'>" + display_url + "</a>" + end
34+ if url == m["content"]:
35+ m["content"] = "<a href='" + url + "'>" + display_url + "</a>"
36+ else:
37+ try:
38+ startindex = m["content"].index(url)
39+ endindex = startindex + len(url)
40+ start = m["content"][0:startindex]
41+ end = m["content"][endindex:]
42+ m["content"] = start + "<a href='" + url + "'>" + display_url + "</a>" + end
43+ except:
44+ logger.debug ("Failed to set url for ID: %s", m["mid"])
45+
46 m["type"] = "link"
47
48 images = util.imgpreview(expanded_url)
49@@ -153,12 +158,11 @@
50 m["link"]["icon"] = ""
51 m["link"]["caption"] = ""
52 m["link"]["properties"] = {}
53-
54
55 if data["entities"].has_key("media"):
56 for media in data["entities"]["media"]:
57 try:
58- url = media["url"]
59+ url = cgi.escape (media["url"])
60 media_url_https = media["media_url_https"]
61 expanded_url = url
62 if media.has_key("expanded_url"):
63@@ -166,7 +170,7 @@
64
65 display_url = url
66 if media.has_key("display_url"):
67- display_url = media["display_url"]
68+ display_url = cgi.escape (media["display_url"])
69
70 startindex = m["content"].index(url)
71 endindex = startindex + len(url)
72@@ -184,6 +188,11 @@
73 except:
74 pass
75
76+ else:
77+ m["content"] = util.linkify(util.unescape(m["text"]),
78+ ((util.PARSE_HASH, '#<a href="gwibber:/tag?acct=%s&query=\\1">\\1</a>' % m["account"]),
79+ (util.PARSE_NICK, '@<a href="gwibber:/user?acct=%s&name=\\1">\\1</a>' % m["account"])), escape=True)
80+
81 m["html"] = m["content"]
82
83 m["to_me"] = ("@%s" % self.account["username"]) in data["text"] # Check if it's a reply directed at the user
84@@ -250,9 +259,16 @@
85
86 return m
87
88+ def _responses(self, data):
89+ m = self._message(data)
90+ m["type"] = None
91+
92+ return m
93+
94 def _private(self, data):
95 m = self._message(data)
96 m["private"] = True
97+ m["type"] = None
98
99 m["recipient"] = {}
100 m["recipient"]["name"] = data["recipient"]["name"]
101@@ -402,7 +418,7 @@
102 return self._get("statuses/home_timeline.json", include_entities=1, count=count, since_id=since)
103
104 def responses(self, count=util.COUNT, since=None):
105- return self._get("statuses/mentions.json", include_entities=1, count=count, since_id=since)
106+ return self._get("statuses/mentions.json", "responses", include_entities=1, count=count, since_id=since)
107
108 def private(self, count=util.COUNT, since=None):
109 private = self._get("direct_messages.json", "private", include_entities=1, count=count, since_id=since) or []
110
111=== modified file 'gwibber/microblog/util/__init__.py'
112--- gwibber/microblog/util/__init__.py 2012-02-24 20:13:33 +0000
113+++ gwibber/microblog/util/__init__.py 2012-03-02 23:13:21 +0000
114@@ -79,7 +79,7 @@
115 end = content.index(':small"><img') + 6
116
117 image = content[start:end]
118- images.append({"src": image, "url": ""})
119+ images.append({"src": image, "url": text})
120 return images
121
122 if "instagr.am" in text:
123@@ -88,7 +88,7 @@
124 resp, content = httplib2.Http().request(thumb)
125 thumb = resp["content-location"]
126
127- images.append({"src": thumb, "url": ""})
128+ images.append({"src": thumb, "url": text})
129 return images
130
131 thumbre = {
132@@ -144,9 +144,9 @@
133 for r, u in zip(thumbre, thumburi):
134 for match in re.finditer(thumbre[r], text):
135 if r == 'tweetphoto' or r == 'pic.gd' or r == 'moby.to':
136- images.append({"src": thumburi[u].replace('@', match.group(0)) , "url": ""})
137+ images.append({"src": thumburi[u].replace('@', match.group(0)) , "url": text})
138 else:
139- images.append({"src": thumburi[u].replace('@', match.group(1)) , "url": ""})
140+ images.append({"src": thumburi[u].replace('@', match.group(1)) , "url": text})
141 return images
142
143 def videopreview(text):
144@@ -173,7 +173,7 @@
145
146 for r, u in zip(thumbre, thumburi):
147 for match in re.finditer(thumbre[r], text):
148- videos.append({ "src": thumburi[u].replace('@', match.group(1)), "url" : ""})
149+ videos.append({ "src": thumburi[u].replace('@', match.group(1)), "url" : text})
150 return videos
151
152 def compact(data):
153
154=== modified file 'libgwibber-gtk/stream-view-tile.vala'
155--- libgwibber-gtk/stream-view-tile.vala 2012-02-23 08:59:27 +0000
156+++ libgwibber-gtk/stream-view-tile.vala 2012-03-02 23:13:21 +0000
157@@ -450,7 +450,10 @@
158 }
159 else if (_stream == "videos")
160 {
161- img_uri = _video_picture;
162+ if (_video_picture.length < 1 && _img_src.length > 0)
163+ img_uri = _img_src;
164+ else
165+ img_uri = _video_picture;
166 img_src = _video_src;
167 }
168
169@@ -949,7 +952,7 @@
170 var last = uri.substring(uri.last_index_of("/") + 1);
171 ret = "http://i.imgur.com/%s.png".printf(last);
172 }
173- else if (uri.contains("youtube.com"))
174+ else if (uri.contains("youtube.com") && !uri.contains("img.youtube.com"))
175 {
176 string id = uri.substring(uri.last_index_of("/") + 1);
177

Subscribers

People subscribed via source and target branches

to all changes: