Saturday, 26 January 2019

Rapsberry Pi [5]: Using the Pi as the tethered desktop

Due to the fact that my main internet feed is filtered, I sometimes need to access websites that are blocked by the filter. This is easier than trying to get a site unblocked. For example a Family First website, porninquiry.nz, is currently blocked by the web filtering, as are several misclassified Christian sites I read such as truelovedates.com and also another site called endsexualexploitation.com that I enjoy reading.
For this reason I have need of a computer that has both Wi-Fi and wired internet connections. Bedroompc is an example but it is inconvenient to use partly because its Wifi connection turns itself off after a while and can't be brought back up without a reboot. Meaning it was more convenient for me to configure it to use the network cable for everything and not use the Wifi at all, but then it wouldn't be able to be the tethered desktop, because both connections are needed for this.
So I have just finished setting up the Pi to be able to do this task, by flashing Raspbian onto it and connecting it to the same display as Win10Pc uses. Because now I have so little use of Win10Pc I have changed its display over to the Pi (Win10Pc is still connected to the VGA input on the screen, while the Pi has taken over the HDMI to DVI adapter cable) and given it the wireless mouse and Bluetooth keyboard. But with a little more work I can get it to install and auto-start x11vnc which allows me to VNC into it (using Remmina) from mainpc so I can sit in front of my regular keyboard and work in a Remmina window.

Then in the same way as I had BedroomPC set up, the wired internet connection is given a fixed IP address with no other configuration information. So that the computer can't connect to the Internet through the network cable, but we can use that cable to connect with x11vnc. Then we set up the Wifi connection to connect to the internet through the tether (one of my phones set up as a hotspot). And then it's all hunky dory. All checked out and working just fine.

Of course this means I won't be doing any more testing of Pi vs Chromecast. So I will experiment with putting Kodi onto the Elitepad tablet that I have, and test that on a TV to see if it can play well.

After using the Pi in this role it works well, but I want to be able to turn it back into a media player which conflicts with this role. I have decided that the tethered PC role can be filled by my Toshiba R500 laptop which has a docking station that it can be quickly attached to and detached from, that can be left in position on the desktop ready for it to be deployed quickly for the tethered PC role, which is just an occasional usage. The R500 also has the advantages of having its own display and being significantly more powerful and being able to run regular Debian, albeit with LXQt as the desktop environment, and Firefox Developer as the browser, which is my preferred web platform. I had a few issues with the Pi dropping out on VNC, which is probably due to known issues with the stretch standard packages of x11vnc and are fixed with buster packages. So that is where things are heading now, the Pi being set up again with LibreElec and tested as a media player

Wednesday, 23 January 2019

Python Scripting [2A]; Syncing a video and music directory tree

Having completed our first scripting task involved XML extraction and copying files, the next task to be scripted in Python will be the process of extracting audio from our collection of music video tracks and syncing it into a directory tree.

The actual steps needed are:
  1. Compare two directory tree, one for video and one for music
  2. Where a music track is missing, extract the audio from a video clip in the video directory tree and save it into the music directory tree.
So it can be described in a couple of steps but the breakdown of tasks may be a little more complex.

The task involves calling ffmpeg to perform the audio extraction and the parameters may vary depending on the type of source file.  

So we will see how things proceed on this one.

Monday, 21 January 2019

Python Scripting [1C]: Scripting to copy map aerial layers 3

So I spent a bit more time completing the script, which now looks like this:

import glob
import os
import shutil
import xml.etree.ElementTree as ET
tree = ET.parse('/home/patrick/Sources/CopyFiles/Source/layers.qlr')
root = tree.getroot()
for layer in root.iter('layer-tree-layer'):
        sourcename = layer.get('name')
        print("Layer: " + sourcename)
        sourcepath = "/home/patrick/Sources/CopyFiles/Source/" + sourcename + ".*"
        #print(fpath)
        for file in glob.glob(sourcepath):
            #print(file)
            destname = os.path.basename(file)
            #print(destname)
            destpath = "/home/patrick/Sources/CopyFiles/Dest/" + destname
            #print(destpath)
            print("Copying " + file + " to " + destpath)
            shutil.copyfile(file,destpath)


So there are a few commented out lines which we can ignore, the key parts are that it:
  • Imports the contents of a qlr file as XML and parses it
  • Gets the layer names from the XML and makes up a wildcard file spec to copy
  • Copies the files from the source to the destination.
This is saved on serverpc in the CopyFiles directory and is run in a shell window with the command
python copyfiles.py
And it works exactly as expected.

This is going to be much faster than the previous script because we don't need to start that computer up and run it in a remote window, and we also don't need to extract layer names from the qlr file that we get from Qgis because the script can do that as well.

So it's all go and once again I am amazed how simple and straightforward this has been. 

I have also created a second version of the script called movefiles.py, that is the same except it uses the shutil.move function to move the file instead of copying it. This is especially useful where you need to split up an existing directory's contents.