Link: Linux Terminal: Poor Man’s Spotify (actually works with Windows, Linux, and Mac OS X)

While I was looking some video related to Linux I’ve found this video of gotbletu an user that I follow on Youtube, related to a small player to listen music directly from the terminal: pms AKA Poor Man’s Spotify.

I like lightweight clients, and so I’ve gave it a try, these are the results.

Note that this is a Python script, and therefore should run on any platform that has Python 2.7 or 3 installed.

Full article here:
Linux Terminal: Poor Man’s Spotify (Linuxaria)

Link: Remotely control your Raspberry Pi

Take control of your Raspberry Pi from your smartphone, tablet or PC, from anywhere in the world

People are starting to do all kinds of things with their Raspberry Pi, like having it open and close a garage door, automate lighting and heating in the home, and so on. Even if you don’t yet have a project like this, this tutorial will still serve as a useful introduction to writing web applications with Python.

Full article here:
Remotely control your Raspberry Pi (Linux User & Developer)

Notes on using HDHomeRun recorder under Ubuntu for lowest CPU usage when recording from HDHomeRun device

 

Important
This is an edited version of a post that originally appeared on a blog called The Michigan Telephone Blog, which was written by a friend before he decided to stop blogging. It is reposted with his permission. Comments dated before the year 2013 were originally posted to his blog.

Sometimes I write articles for others, but sometimes I use this blog just to post a collection of notes on something I had a need to do.  This is one of the latter type.  You are welcome to look, and if it helps anyone else, great, but it’s not a full, step-by-step, “here’s how to do it” article, and I definitely do not advise you to just blindly emulate what I did, since there are probably more elegant ways to do this. This was one of those “I just want to get the thing working” type projects, and I must say that it works very well, at least for me.

HDHomeRun recorder is a simple Python script that will record specific channels based on a pre-established schedule.  It is less CPU intensive (and in my opinion, much easier to set up) than some of the other ways to do this, such as Myth TV.  But it is more limited — in particular the current script will only record from a single tuner, and there’s no GUI at all.  Everything is done in script and configuration files.

Here’s what I did:

Using  apt-get or Synaptic, install the following:  hdhomerun-config-gui, hdhomerun-config, libhdhomerun1, python-pip:
sudo apt-get install hdhomerun-config-gui hdhomerun-config libhdhomerun1 python-pip

Install apscheduler:
sudo pip install apscheduler

EDIT (for newer version mentioned by Fred C. in the comments): Then go to this page and click the ZIP button to download a ZIP file containing HDHomeRun recorder.  Unzip it into a subdirectory off of your user directory (I named the subdirectory HDHomeRun_Recorder on my system) — you should get several files and a scripts directory, which contains a couple more files. At this point you might want to check the ownership and permissions of the files — in particular make sure the .py files are executable. Do NOT follow the instructions in the README file; they are for an older version of the software. You may want to read the file, particularly if you have a WDTV Live media player, but the INSTALL section needs updating.

You then need to modify a couple of the files.  This is a bit tricky because what might seem the obvious way to do it won’t work (unless you apply my fix mentioned below).  So here is what you need to do:

(Read through this before actually doing anything, it may save you some effort!)

First, modify config-file.  There are three things you need to change here.  First you need to change this line as shown:

hdhomerun_config = /usr/bin/hdhomerun_config

This assumes the hdhomerun_config program is in /usr/bin, which it will be if you installed it using apt-get or Synaptic.  Next, you need to modify the tuners line to show the correct tuner IDs for your HDHomeRun — you can discover these using the HDHomeRun Configuration utility, if you don’t already know them.  And, you need to replace the entries in the channelmap section with your local channels.  You can run the hdhomerun_setup.py program (run it with no arguments and it will tell you what arguments it needs) and it will show you a list of channels (note it takes a few minutes to run, so be patient), and it appears as if it produces an entire config-file for you, but it doesn’t (keep reading before you do anything, there’s a fix for this below that you might want to try).  So look at the list of channels it outputs and then change each line to match the format you see in the included config-file.  For example, let’s say you see:

35.1   = 11   3   WGVU-11
35.2   = 11   4   WGVU-11
35.3   = 11   5   WGVU-11
35.4   = 11   6   WGVU-11
0 = 11 9 (control)
0 = 11 10 (control)

What that needs to be changed to in config-file is:

35.1 = 8vsb:11, 3       ; WGVU-11
35.2 = 8vsb:11, 4       ; WGVU-11
35.3 = 8vsb:11, 5       ; WGVU-11
35.4 = 8vsb:11, 6       ; WGVU-11

I have no clue why the hdhomerun_setup.py program doesn’t produce the correct output, it just doesn’t. I tried fixing it to produce the correct output (despite the fact that Python is a very incoherent language to me), and think I have it, so if you want to try my fix to hdhomerun_setup.py, the code is at the end of this article.

Second, you need to modify schedule-file. This is an example schedule file, and you just modify the entries with programs you like to record.

When you run the python script, I found that you need to actually be in its directory, and also that when you run it, it will seem like nothing is happening. And the command prompt won’t come back either, so you may want to initially run it using screen:

screen ./hdhomerun_recorder.py

You can use Control-A followed by D to detach from the process. To check that it started and everything is working okay, check logfile (in the same directory as the hdhomerun_recorder.py program). I found that the following could be used to kill the process:

pkill -f “python ./hdhomerun_recorder.py”

I made a bash shell script that looks like this:

#!/bin/bash
export USER=yourusername
pkill -f “python ./hdhomerun_recorder.py”
cd HDHomeRun_Recorder
./hdhomerun_recorder.py &

I can run this script to restart the Python script (in case I make a change to the schedule) and I can also add it to my startup items to start the script after a reboot (the pkill is ignored in that case).

Note: If you need a way to determine the channels in your area and don’t want to run hdhomerun_setup.py, see hdhomeruntoolbox, but note that the .strm files it produces are not in the correct format for XBMC (in case you are using XBMC, and if you are and you know anything about Java, maybe you want to grab a Java Decompiler and see if you can fix the output). However, after it runs, the information you will need for each channel in HDHomeRun recorder will be in a file named scan_tuner1.txt in the (hidden) .hdhomerun directory. When you look in that file, you will see sections for each working channel that contain information such as this:

SCANNING: 201000000 (us-bcast:11)
LOCK: 8vsb (ss=100 snq=91 seq=100)
TSID: 0x05E7
PROGRAM 3: 35.1 WGVU-11
PROGRAM 4: 35.2 WGVU-11
PROGRAM 5: 35.3 WGVU-11
PROGRAM 6: 35.4 WGVU-11
PROGRAM 9: 0 (control)
PROGRAM 10: 0 (control)

In config-file, the above would translate to something like this:

35.1 = 8vsb:11, 3 ; WGVU-11
35.2 = 8vsb:11, 4 ; WGVU-11
35.3 = 8vsb:11, 5 ; WGVU-11
35.4 = 8vsb:11, 6 ; WGVU-11

Note that stations will not always have the real channel numbers after the callsign, so the real channel number actually comes from the (us-bcast:11) in this case.

Setting up config-file is probably the hardest (not actually hard, but maybe tedious) part, if you can’t get my modifications to the hdhomerun_setup.py script (below) to work, but remember that you only need to add the channels from which you might want to record programming, not every channel available. Remember to restart the Python script if you change the schedule, but of course you DON’T want to do that while it’s recording programming!

I should add that since HDHomeRun recorder is a Python script, it’s probably possible to make it run under operating systems other than Ubuntu, but I just haven’t attempted to do that.

Here are my changes for hdhomerun_setup.py, that should cause it to print out usable lines that replace the existing lines in config-file (you will have to copy and paste them; it does NOT overwrite config-file). Note that there will only be one tuner shown on the tuners line, so you should add your additional tuners if you want to use them For example, if you have a HDHomeRun Dual, and this script prints out tuners = 10ABCDEF:0 you should add the second tuner so that the line is tuners = 10ABCDEF:0, 10ABCDEF:1 (with comma and space separating the two).

#!/usr/bin/env python

def channel_iter(file):
    for line in file:
        if line.startswith("SCANNING: "):
            channel = line.split()[2].strip('()')
            channel = channel.split(':')[1]
        elif line.startswith("LOCK: "):
            modulation = line.split()[1]
        elif line.startswith("PROGRAM "):
            (PROGRAM, subchannel, vchannel, name) = line.split(None, 3)
            subchannel = subchannel.rstrip(':')
            name = name.strip()     # remove new line
            name = name.replace(' ', '-')
            yield (vchannel, modulation, channel, subchannel, name)

def channel_info(hdhomerun_config, device_id, tuner):
    import subprocess
    import tempfile

    f = tempfile.TemporaryFile()
    cmd = [hdhomerun_config, device_id, "scan", "/tuner%d" % tuner]
    p = subprocess.Popen(cmd, stdout=f)
    p.wait()
    f.seek(0)
    return list(channel_iter(f))

def main():
    import sys, os, os.path

    usage = ("usagde: %s path-to-hdhomerun-config device-id tuner-number"
             % sys.argv[0])
    if len(sys.argv) != 4:
        sys.exit(usage)
    hdhomerun_config = sys.argv[1]
    device_id = sys.argv[2]
    tuner = int(sys.argv[3])
    if not os.path.exists(hdhomerun_config):
        sys.exit("%s doesn't exist, aborting!")
    if not os.path.isfile(hdhomerun_config):
        sys.exit("%s is not a regular file, aborting!")
    if not os.access(hdhomerun_config, os.X_OK):
        sys.exit("%s doesn't have execute permission set, aborting!")

    chan_info = channel_info(hdhomerun_config, device_id, tuner)
    if not len(chan_info):
        sys.exit("couldn't find any channels, quitting!")

    print("[global]")
    print("logfile = logfile")
    print("media_dir = media")
    print("schedule_file = schedule-file")
    print("hdhomerun_config = %s" % hdhomerun_config)
    print("tuners = %s:%s" % (device_id, tuner))
    print("[channelmap]")
    print("# virtual-channel = physical-channel program-number name-of-program")
    for (vchannel, modulation, channel, subchannel, name) in chan_info:
        line = "%s = %s:%s, %s t; %s" % (vchannel, modulation, channel, subchannel, name)
        if vchannel != '0':
            print(line)

if __name__ == '__main__':
    main()