Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable user to select their own command to view image or video from tweet #212

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rainbowstream/colorset/config
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 11 additions & 8 deletions rainbowstream/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -371,13 +371,16 @@ 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(' Media available'))


def print_threads(d):
Expand Down
13 changes: 8 additions & 5 deletions rainbowstream/rainbow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.'))

Expand Down