def __init__(self, data): super(MediaViewer, self).__init__() img = None self.set_resizable(False) self.set_position(Gtk.WindowPosition.CENTER) self.set_events(Gdk.EventMask.KEY_PRESS_MASK) self.connect("key-press-event", lambda x, y: self.on_key_press(x, y)) # image preview for media in data['entities']['urls']: if "youtube.com" in media['expanded_url'] or \ "youtu.be" in media['expanded_url']: webview = WebKit.WebView() self.add(webview) webview.load_html_string("<iframe width='640' height='390' \ style='margin-left: -10px; \ margin-top: -10px; \ margin-bottom: -10px;' \ src='http://www.youtube.com/embed/" \ + get_youtube_id(media['expanded_url']) \ + "?version=3&autohide=1&controls= \ 2&modestbranding=1&showinfo= \ 0&showsearch=0&vq=hd720&autoplay=1' \ frameborder='0'</iframe>", \ "http://www.youtube.com/embed/"); self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) self.show_all() return try: for media in data['entities']['media']: img = BIRDIE_CACHE_PATH + \ os.path.basename(media['media_url_https']) except: pass try: for media in data['entities']['urls']: if "imgur.com" in media['expanded_url']: img = BIRDIE_CACHE_PATH + \ os.path.basename(media['expanded_url']) except: pass full_image = Gtk.Image() full_image.set_from_pixbuf(fit_image_screen(img, self)) self.add(full_image) self.show_all()
def __init__(self, data): super(MediaViewer, self).__init__() img = None self.set_resizable(False) self.set_position(Gtk.WindowPosition.CENTER) self.set_events(Gdk.EventMask.KEY_PRESS_MASK) self.connect("key-press-event", lambda x, y: self.on_key_press(x, y)) # image preview for media in data['entities']['urls']: if "youtube.com" in media['expanded_url'] or \ "youtu.be" in media['expanded_url']: webview = WebKit.WebView() self.add(webview) webview.load_html_string("<iframe width='640' height='390' \ style='margin-left: -10px; \ margin-top: -10px; \ margin-bottom: -10px;' \ src='http://www.youtube.com/embed/" \ + get_youtube_id(media['expanded_url']) \ + "?version=3&autohide=1&controls= \ 2&modestbranding=1&showinfo= \ 0&showsearch=0&vq=hd720&autoplay=1' \ frameborder='0'</iframe>" , \ "http://www.youtube.com/embed/") self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) self.show_all() return try: for media in data['entities']['media']: img = BIRDIE_CACHE_PATH + \ os.path.basename(media['media_url_https']) except: pass try: for media in data['entities']['urls']: if "imgur.com" in media['expanded_url']: img = BIRDIE_CACHE_PATH + \ os.path.basename(media['expanded_url']) except: pass full_image = Gtk.Image() full_image.set_from_pixbuf(fit_image_screen(img, self)) self.add(full_image) self.show_all()
def add_to_list(self, data, tweet_list, stream): """ Create a TweetBox and add it to the TweetList :param data: BirdieStreamer data obj :param tweet_list: TweetList obj :param stream: bool """ # retweets if 'retweeted_status' in data: data['retweeted_status']['retweeted_by'] = data['user']['name'] data['retweeted_status'][ 'retweeted_by_screen_name'] = data['user']['screen_name'] data = data['retweeted_status'] box = TweetBox(data, self.active_account) box.connect_signal( "tweet-favorited", lambda x, y, z: self.on_tweet_favorited(x, y, z)) box.connect_signal( "tweet-destroy", lambda x, y: self.on_tweet_destroy(x, y)) box.connect_signal( "dm-destroy", lambda x, y: self.on_dm_destroy(x, y)) box.connect_signal("retweet", lambda x, y: self.on_retweet(x, y)) box.connect_signal("retweet-quote", lambda x, y: self.on_retweet_quote(x, y)) box.connect_signal("reply", lambda x: self.on_reply(x)) box.connect_signal("dm-reply", lambda x: self.on_dm_reply(x)) box.connect_signal("update-favorites", self.update_favorites) # dms if tweet_list == self.dm_inbox_list or \ tweet_list == self.dm_outbox_list: profile_image_url = data['sender']['profile_image_url_https'] else: profile_image_url = data['user']['profile_image_url'] GLib.idle_add(lambda: tweet_list.append(box, stream)) self.downloader.add( {'url': profile_image_url, 'box': box, 'type': 'avatar'}) if tweet_list != self.dm_inbox_list and \ tweet_list != self.dm_outbox_list: try: for media in data['entities']['media']: self.downloader.add( {'url': media['media_url_https'], 'box': box, 'type': 'media'}) except: pass # trying to catch imgur images try: for media in data['entities']['urls']: if "imgur.com" in media['expanded_url']: media['expanded_url'] = media['expanded_url'].replace( "http://imgur.com/" + os.path.basename(media['expanded_url']), "http://i.imgur.com/" + os.path.basename(media['expanded_url']) + '.jpg') self.downloader.add( {'url': media['expanded_url'], 'box': box, 'type': 'media'}) except: pass # trying to catch youtube video try: for media in data['entities']['urls']: if "youtube.com" in media['expanded_url'] or \ "youtu.be" in media['expanded_url']: if "youtu.be" in media['expanded_url']: media['expanded_url'] = \ media['expanded_url'].replace("youtu.be/", "youtube.com/watch?v=") youtube_id = get_youtube_id(media['expanded_url']) youtube_thumb = "http://i3.ytimg.com/vi/" + \ youtube_id + "/mqdefault.jpg" self.downloader.add( {'url': youtube_thumb, 'box': box, 'type': 'youtube', 'id': youtube_id}) except: pass
def add_to_list(self, data, tweet_list, stream): """ Create a TweetBox and add it to the TweetList :param data: BirdieStreamer data obj :param tweet_list: TweetList obj :param stream: bool """ # retweets if 'retweeted_status' in data: data['retweeted_status']['retweeted_by'] = data['user']['name'] data['retweeted_status']['retweeted_by_screen_name'] = data[ 'user']['screen_name'] data = data['retweeted_status'] box = TweetBox(data, self.active_account) box.connect_signal("tweet-favorited", lambda x, y, z: self.on_tweet_favorited(x, y, z)) box.connect_signal("tweet-destroy", lambda x, y: self.on_tweet_destroy(x, y)) box.connect_signal("dm-destroy", lambda x, y: self.on_dm_destroy(x, y)) box.connect_signal("retweet", lambda x, y: self.on_retweet(x, y)) box.connect_signal("retweet-quote", lambda x, y: self.on_retweet_quote(x, y)) box.connect_signal("reply", lambda x: self.on_reply(x)) box.connect_signal("dm-reply", lambda x: self.on_dm_reply(x)) box.connect_signal("update-favorites", self.update_favorites) # dms if tweet_list == self.dm_inbox_list or \ tweet_list == self.dm_outbox_list: profile_image_url = data['sender']['profile_image_url_https'] else: profile_image_url = data['user']['profile_image_url'] GLib.idle_add(lambda: tweet_list.append(box, stream)) self.downloader.add({ 'url': profile_image_url, 'box': box, 'type': 'avatar' }) if tweet_list != self.dm_inbox_list and \ tweet_list != self.dm_outbox_list: try: for media in data['entities']['media']: self.downloader.add({ 'url': media['media_url_https'], 'box': box, 'type': 'media' }) except: pass # trying to catch imgur images try: for media in data['entities']['urls']: if "imgur.com" in media['expanded_url']: media['expanded_url'] = media['expanded_url'].replace( "http://imgur.com/" + os.path.basename(media['expanded_url']), "http://i.imgur.com/" + os.path.basename(media['expanded_url']) + '.jpg') self.downloader.add({ 'url': media['expanded_url'], 'box': box, 'type': 'media' }) except: pass # trying to catch youtube video try: for media in data['entities']['urls']: if "youtube.com" in media['expanded_url'] or \ "youtu.be" in media['expanded_url']: if "youtu.be" in media['expanded_url']: media['expanded_url'] = \ media['expanded_url'].replace("youtu.be/", "youtube.com/watch?v=") youtube_id = get_youtube_id(media['expanded_url']) youtube_thumb = "http://i3.ytimg.com/vi/" + \ youtube_id + "/mqdefault.jpg" self.downloader.add({ 'url': youtube_thumb, 'box': box, 'type': 'youtube', 'id': youtube_id }) except: pass