This article is part of the Social Media from Command Line series:
- Social Media from the Command Line, Part 1: Facebook and Twitter
- Social Media from the Command Line, Part 2: Google
- Social Media from the Command Line, Part 3: Tumblr, Flickr, and YouTube
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.
You must first install Ruby and RubyGems. Once that’s out of the way, you can grab Tumblr-rb with a single command:
Now symlink the gem so you can use it without having to type out the complete file path every time:
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:
You’ll be taken to a page that looks like this:
Enter your credentials and wait for the success message. Now you can use Tumblr-rb.
- Make a text post:
- Post a URL and put it in your queue:
- Post a multimedia (image, audio, or video) file and save it as a draft:
- Post text from STDIN:
- Post from STDIN using a YAML file:
You can add metadata to your posts by incorporating YAML front-matter. Here’s an example:
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.
First of all, you need Python 2.*. Now download the latest Uploadr.py sources from GitHub:
Before proceeding, sign into this Flickr page in your browser to get an API key. Click on “Apply for a non-commercial 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:
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 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!
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:
You can also set it up to receive command-line arguments for the title, description, and tags:
Now you can upload the images from your chosen directory with a title, description, and tags:
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.*):
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:
- Download a video in MP4 format and use the title for the file name:
- View all available formats and their codes for a video:
- Download the audio from a video:
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.
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.
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:
These are some other commands you can run inside youtube-viewer:
- Log in:
- Show a video author’s latest uploads:
- Like or dislike a video:
- Subscribe to an author’s channel:
- Show related videos:
- Play videos from your search results in a specific order:
- Download a video:
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?