From 4f5d8c3fed61b11d4fd9b12cae30f05fdc1ac47b Mon Sep 17 00:00:00 2001 From: Kris Date: Mon, 9 Jan 2017 19:27:18 +0900 Subject: [PATCH 1/2] Update draw.py --- rainbowstream/draw.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index 75e75772..a14275e1 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -371,14 +371,17 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): printNicely(formater) # Display Image - if c['IMAGE_ON_TERM'] and media_url: - for mu in media_url: - try: - response = requests.get(mu) - image_to_display(BytesIO(response.content)) - except Exception: - printNicely(red('Sorry, image link is broken')) - + if media_url: + if c['IMAGE_ON_TERM']: + for mu in media_url: + try: + response = requests.get(mu) + image_to_display(BytesIO(response.content)) + except Exception: + printNicely(red('Sorry, image link is broken')) + else: + printNicely(red('Image available')) + def print_threads(d): """ From 298a0fd1006da76cd18d70b91cf29eede596cc6a Mon Sep 17 00:00:00 2001 From: drselump14 Date: Tue, 10 Jan 2017 17:17:28 +0900 Subject: [PATCH 2/2] enable user to choose their own command to play image and video --- rainbowstream/colorset/config | 4 ++++ rainbowstream/draw.py | 6 +++--- rainbowstream/rainbow.py | 13 ++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/rainbowstream/colorset/config b/rainbowstream/colorset/config index 54b76ff0..9de414c5 100644 --- a/rainbowstream/colorset/config +++ b/rainbowstream/colorset/config @@ -49,6 +49,10 @@ "IMAGE_MAX_HEIGHT" : 90, // Seconds to wait before displaying another tweet, will drop all tweets while waiting. "STREAM_DELAY" : 0, + // Set command for photo viewer, default is feh + "PHOTO_VIEWER_COMMAND": "feh", + // Set command for video viewer, default is mpv + "VIDEO_VIEWER_COMMAND": "mpv", // Stream config "USER_DOMAIN" : "userstream.twitter.com", "PUBLIC_DOMAIN" : "stream.twitter.com", diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index a14275e1..e8810b72 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -238,7 +238,7 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): # Get media try: media_url = [] - media = t['entities']['media'] + media = t['extended_entities']['media'] for m in media: media_url.append(m['media_url']) except: @@ -380,8 +380,8 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): except Exception: printNicely(red('Sorry, image link is broken')) else: - printNicely(red('Image available')) - + printNicely(red(' Media available')) + def print_threads(d): """ diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index a499f957..4ef958d3 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -19,6 +19,7 @@ from twitter.oauth import OAuth, read_token_file from twitter.oauth_dance import oauth_dance from twitter.util import printNicely +from subprocess import call from pocket import Pocket @@ -733,12 +734,14 @@ def show(): id = int(g['stuff'].split()[1]) tid = c['tweet_dict'][id] tweet = t.statuses.show(id=tid) - media = tweet['entities']['media'] + media = tweet['extended_entities']['media'] for m in media: - res = requests.get(m['media_url']) - img = Image.open(BytesIO(res.content)) - img.show() - except: + print m['type'] + if m['type'] == 'photo': + call([c['PHOTO_VIEWER_COMMAND'], m['media_url']]) + else: + call([c['VIDEO_VIEWER_COMMAND'], m['video_info']['variants'][0]['url'] ]) + except Exception as e: debug_option() printNicely(red('Sorry I can\'t show this image.'))