Social Media from the Command Line, Part 3: Tumblr, Flickr, and YouTube

This article is part of the Social Media from Command Line series:

In the first installment of this article series, we taught you the basics of managing your Facebook and Twitter accounts from the command line. In the second installment, we introduced you to GoogleCL for managing your Google services. This time we’re going to talk about some text-mode applications for Tumblr, Flickr, and YouTube.

Although there’s more than one command-line Tumblr client in existence, the one I recommend is a Ruby gem called Tumblr-rb. It’s the only one I know of that supports YAML Ain’t Markup Language (YAML), which is a clean, human-readable way to format documents.

Installation

You must first install Ruby and RubyGems. Once that’s out of the way, you can grab Tumblr-rb with a single command:

gem install tumblr-rb

Now symlink the gem so you can use it without having to type out the complete file path every time:

sudo ln -s ~/.gem/ruby/1.8/bin/tumblr /usr/bin/tumblr

Finally, there are a couple of steps required to authorize Tumblr-rb to access your Tumblr account. You need to first register a Tumblr application; you can call it anything you want. The important thing is to get the OAuth consumer key and the secret key. Once you have those, run:

tumblr authorize

You’ll be taken to a page that looks like this:

tumblr-authorize

Enter your credentials and wait for the success message. Now you can use Tumblr-rb.

Usage

Tumblr-rb has an online manual as well as some more developer-oriented documentation. Here is a quick reference for some of the commands you can run:

  • Make a text post:
    tumblr post my-formatted-post.txt
  • Post a URL and put it in your queue:
    tumblr post -q http://maketecheasier.com
  • Post a multimedia (image, audio, or video) file and save it as a draft:
    tumblr post -d my-new-song.wav
  • Post text from STDIN:
    tumblr post "I'm posting to Tumblr from my Raspberry Pi!"
  • Post from STDIN using a YAML file:
    cat data.yaml pretty-post.txt | tumblr --host=myblawg.tumblr.com

You can add metadata to your posts by incorporating YAML front-matter. Here’s an example:

tumblr-yaml

Uploadr.py is a simple Flickr client written in Python. It will allow you to upload image files from a local folder to your Flickr account.

Installation

First of all, you need Python 2.*. Now download the latest Uploadr.py sources from GitHub:

git clone https://github.com/ept/uploadr.py.git

Before proceeding, sign into this Flickr page in your browser to get an API key. Click on “Apply for a non-commercial key.”

flickr-api-key

Fill out the application with any name and description you want and agree to the terms at the bottom. Once you submit your application, you’ll get a key and a secret. Add these lines to your “~/.bashrc”, replacing “[key]” and “[secret]” appropriately, so that your system will remember them from one session to the next:

export FLICKR_UPLOADR_PY_API_KEY='[key]'
export FLICKR_UPLOADR_PY_SECRET='[secret]'

Start a new shell session to make the changes take effect. Enter the uploadr.py directory you downloaded from GitHub and the subdirectory “uploadr.” Run:

python ./uploadr.py

Substitute python with your 2.* version of Python, such as python2.7, if your default version is 3.*. This command will open an authorization page in your browser. Click “OK, I’ll authorize it.” Now we’re ready to roll!

Usage

Well, almost ready to roll. We need to edit a few lines in uploadr.py to give the program some instructions. On line 56, specify the directory your images are stored in:

IMG_DIR = "~/Pictures/PhotosForFLickr/"

As described in this excellent tutorial, you can also set it up to receive command-line arguments for the title, description, and tags:

FLICKR = {
"title"      : sys.argv[1],
"description": sys.argv[2],
"tags"       : sys.argv[3],
"is_public"  : "1",
"is_friend"  : "0",
"is_family"  : "0"}

uploadr-config

Now you can upload the images from your chosen directory with a title, description, and tags:

python uploadr.py "Screenshot" "This is a screenshot." "screenshots, Linux"

Previously, we covered how to manage your YouTube account using GoogleCL. But what if you just want to be a consumer, not a producer? For simply watching YouTube videos from the command line, there are two notable tools: youtube-dl and youtube-viewer.

If you’re using Linux, you can probably install both of these tools with your package manager. Alternatively, you can grab the sources from GitHub and install them yourself:

Youtube-dl (requires Python 2.*):

git clone https://github.com/rg3/youtube-dl.git

Youtube-viewer:

git clone https://github.com/trizen/youtube-viewer.git

Usage (youtube-dl):

Youtube-dl is a video downloader. All of its options have been explained. Some basic examples include:

  • Just download a video in the default FLV format:
    youtube-dl http://www.youtube.com/watch?v=p6Mq8pXNAfA
  • Download a video in MP4 format and use the title for the file name:
    youtube-dl -f 18 -t http://www.youtube.com/watch?v=p6Mq8pXNAfA
  • View all available formats and their codes for a video:
    youtube-dl -F http://www.youtube.com/watch?v=p6Mq8pXNAfA
  • Download the audio from a video:
    youtube-dl --extract-audio --audio-format "vorbis"

Once you’ve downloaded a video, you can watch it in a terminal using MPlayer with an ASCII art library such as AAlib (for monochrome playback) or libcaca (for viewing in color). For example:

mplayer -vo caca videofile.flv

mplayer-caca

Usage (youtube-viewer):

Unlike youtube-dl, youtube-viewer is interactive. When you enter the command youtube-viewer, you’ll be taken to an interactive prompt where you can search for videos or enter :h for help. Searching will return the top twenty results.

youtube-viewer-search

To watch a video, enter its number into the prompt. You may initially get the mplayer: could not connect to socket error; just give it a moment, and the video will start playing.

youtube-viewer-watch

If you are using youtube-viewer from a text-only console, as opposed to a terminal emulator (any “terminal” run in an X session is actually a terminal emulator), youtube-viewer will automatically play videos with aalib. Depending on the size of your console, the picture may get distorted. For example, here I split the screen using Tmux for the purpose of grabbing a screenshot, and the video appeared elongated:

youtube-viewer-tty

These are some other commands you can run inside youtube-viewer:

  • Log in:
    :login
  • Show a video author’s latest uploads:
    :a(uthor)=i,i
  • Like or dislike a video:
    :(dis)like=i
  • Subscribe to an author’s channel:
    :subscribe=i
  • Show related videos:
    :r(related)=i
  • Play videos from your search results in a specific order:
    3-5, 8 10 7 1
  • Download a video:
    d18

Congratulations! You’ve reached the end of the article series “Social Media from the Command Line.” Now go SSH into that headless server (because everyone has one, right?) and work your magic! Tell us in the comments about your experiences using command-line social media tools and which ones are your favorites. Are there any other online services you wish you could access from the command line?

Do you like what you read here?

Receive the latest update in your inbox.

Or connect with us: