Programming, philosophy, pedaling.

Neat Things I've Found This Week

May 18, 2016

Tags: programming

I’ve decided to start this (semi) regular series of posts, both as an experiment in blogging more regularly and as a way to expose interesting and lesser-known things (mostly related to programming) to an audience in a way that tucked away documentation normally cannot.

Without further ado…

There’s a YouTube API for channel RSS feeds

There are a lot of YouTube channels that I regularly enjoy, but staying up-to-date on them involves maintaining a list of subscriptions on a YouTube (Google?) account. This isn’t a particularly great solution for me, as I do the vast majority of my media consumption via youtube-dl over mpv to avoid both the sluggish web interface and the constant stream of “personalized” recommendations.

Luckily, as I discovered yesterday, YouTube exposes channels as RSS feeds containing the 15 most recently published videos. All one has to do is point RSS reader (or other consumer) of choice at the endpoint with the proper parameter:


(channel_id being for newer channels with long key-like URLs, and user being for older channels with personalized URLs).

Pithos has a Python API

As far as I know, Pithos is the only Linux Pandora client that comes close to approaching a full feature set. I’ve used it on-and-off as a way to discover new bands, but I didn’t know about its API until a friend (and contributor to the project) told me that it could be accessed programmatically (and by default, no less).

This is pretty awesome - with just a few lines of Python and a Pandora account, anybody can access millions of songs as plain old URLs:

import pithos.pandora
import pithos.pandora.data # not necessary in newer versions of pithos

email = 'foo@bar.baz'
pass = 'quux'

pandora = pithos.pandora.make_pandora()

station = pandora.get_stations()[0] # get the very first station
playlist = station.get_playlist() # get a list of songs on that station

song = playlist[0] # get the very first song
song.artRadio # album art (url)
song.audioUrlMap # dict -> quality level -> 'audioUrl' (url)

mpv has a JSON-based protocol for IPC

mpv has a fairly well-known and well-documented Lua interface, normally used to write plugins and construct the on-screen controller.

Its JSON interface, on the other hand, only seems to be really documented in the man page as the combination of already-defined input commands, a dash of JSON, and a unix socket. In practice (in conjunction with a wrapper like python-mpv), it’s an incredibly powerful way to control an mpv instance:

import mpv

player = mpv.MPV()

player.command('loadfile', '/path/to/file', 'append-play')
player.set_property('mute', 'yes')
player.set_property('pause', 'yes')


Combined with the Pithos API above, I used this to whip up a little script for playing Pandora streams through mpv. You can check it out here.


That’s all I have this week (so far…), but I’ll try to make posts like this on a semi-regular basis.

- William