AdrianOnTech.net
Showing posts from 2017
Showing posts from 2017

Bulk FFmpeg audio file extraction from MP4 video

September 16, 2017

Bulk FFmpeg audio file extraction from MP4 video

>> View this full post page here

This is just a short bash script to process a directory hierarchy of MP4 video files, copying just the audio out to a similar directory structure, creating the directories as well. Something to save the battery life of my iPhone, when I'd rather just listen to stuff that doesn't need watching as well.

The script is usefully fast as no transcoding takes place, the output file format is whatever was in the MP4 container - I'm just assuming aac/.m4a here as that was what was originally in my source files.


#!/bin/bash
#
# This script searches $vDir for mp4 files placing
# processed copies in a similar directory structure under $mDir.

vDir=/home/adrian/Videos/Music
mDir=/home/adrian/Music/Artists

find $vDir -type f -name *.mp4 |

while read -r src ; do
dst=$(echo $src | sed 's/.mp4$/.m4a/' | sed "s=$vDir=$mDir=" )

# has audio been previously extracted?
if [ ! -e "$dst" ]; then

dstDir=$(dirname "$dst")

# does dest directory not exist?
if [ ! -d "$dstDir" ]; then
echo "*** creating $dstDir"
mkdir -p "$dstDir"
fi

echo "*** extracting audio from $src"
ffmpeg -nostdin -i "$src" -c:a copy -vn -sn "$dst"

fi
done

echo "Finished."

Note the '-nostdin' switch to avoid ffmpeg sucking up the piped output of 'find' as interactive input! Had a nice tail chase fixing that!

June 04, 2017

Creating Nodeclipse Node.js Express projects with Express 4.x and Pug

>> View this full post page here

At the moment (unless I've missed an update somewhere), installing Enide 2015 into Eclipse neon.3 and starting up a new 'Node.js Express Project', creates that project with an old version of Express – version 3.2.6.

It also creates template code with a named dependency on Jade, the html views engine which they say now should be referred to as Pug.

Nodeclipse : http://www.nodeclipse.org/
Nodeclipse is an Eclipse plugin for the Node.js. The purpose of Nodeclipse is to create an environment in which Node.js development is easy for any user from beginner to professional.
Express : https://expressjs.com/
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
Pug : https://pugjs.org/
a robust, elegant, feature rich template engine for Node.js

To correct both in your new Node.js Eclipse projects, do the following:-

May 14, 2017

Hi! Welcome to my blog!

>> View this full post page here

Thanks for stopping by!

This web site features some of my personal projects, my work activities, and the odd few gadget purchasing experiences.

Also, as my time with IT often features a few interesting technical scuffles with things that are relatively obscure, I've included a quickly worded write-up, posted as soon as possible after the battles.

For those particular articles, and for speed and my convenience, I'm keeping initial editing to the absolute minimum; a bit like some of us folks habitually now do on facebook and twitter. I'll correct errors later as I find them.

Lastly, expect to find changes as I grapple with Blogger coding - This thing is constantly under development!

Enjoy!

Adrian C

March 18, 2017

Compiling and installing ClamAV on Ubuntu

>> View this full post page here

For most folks using open source, maintaining antivirus software on a Linux desktop is something perhaps a little over the top.

I know it is a popularly held opinion that Linux doesn't need much of a virus scanner installed.

But even so, I do have some partly built Windows machines that could still be exposed to viruses, if they came across on my Linux browser. Who knows what lurks within an innocent download?

With this in mind, I installed ClamAV on my main day-to-day (slow, low electrical power) Ubuntu desktop, and took advantage of compiling it from source for better scanning throughput, rather than using the pre-built Ubuntu packages available via apt-get.

    ClamAV : https://www.clamav.net/
    ClamAV® is an open source antivirus engine for detecting trojans, viruses, malware & other malicious threats.

    https://en.wikipedia.org/wiki/Clam_AntiVirus

While doing this, I made some some installation notes that others may find helpful...

March 09, 2017

Extracting data from a website to csv using wget, pup and jq

>> View this full post page here

I've got a little spending habit at a certain hi-tech retailer that lists second hand computer parts on their website.

There are bargains here to be found, but I find daily exploration a pain, with the multiple categories of products shown on separate slow pages. Almost a bit like this blog ;-)

So my quickly written script does the boring work instead using wget, pup and jq, and leaves me a spreadsheet to browse over.

The script requires these tools installed.

    pup : https://github.com/ericchiang/pup
    "pup is a command line tool for processing HTML. It reads from stdin, prints to stdout, and allows the user to filter parts of the page using CSS selectors."
    jq : https://stedolan.github.io/jq/
    "jq is a lightweight and flexible command-line JSON processor. jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data..."

I think the wget tool should already be present in most linux distributions.

The Script

I chose to use pup after looking at the website returned search results. These static HTML coded pages contained a structured 'window.universal_variable' JSON object. Storing a maximum of 16 data records, this object sufficiently held the data that I was interested in.

I did also find further records delivered by dynamic XMLHttpRequest, but with not that many items per interested category shown in their stores, I found this mechanism rarely used. So, no need for me to create code to interface with that :)

In the rest of my script, jq is used to filter, collect and convert these JSON objects to csv.

Running it for the first time, a file 'subcat_list.html' is created. An extract looks like this:

...
...
<a href="product.php?mode=buy&plid=8">
Data Storage
</a>
<a href="search/index.php?stext=*&section=&catid=1">
* IDE Hard Drives
</a>
<a href="search/index.php?stext=*&section=&catid=2">
* Laptop Hard Drives
</a>
<a href="search/index.php?stext=*&section=&catid=3">
Network Attached Hard Drives
</a>
... ,
This lists the subcategories and their internal links found within the website, and is now a configuration file that requires some simple editing to allow script csv output.

To indicate interested subcategories for this, I just place a '*' next to the category title. By way of an example, I've shown that done above for the first two hard drive categories.

Here's the entire script:

#!/bin/bash

# root url of supplier website
baseurl="https://moonbasealphax.com"

# create ./tmp
mkdir -p ./tmp

# create subcategory list for components
if [ ! -f './subcat_list.html' ]; then
url="$baseurl/product.php?scid=3"

wget --output-document=./tmp/index.html $url

cat ./tmp/index.html | pup ".featureBoxContent li a" > ./subcat_list.html
fi

# create csv output script for jq JSON processor
if [ ! -f './tocsv.jq' ]; then

cat << 'EOF' > ./tocsv.jq
# commands for jq to create csv from JSON array
def tocsv:
if length == 0 then empty
else
(.[0] | keys_unsorted) as $keys
| (map(keys) | add | unique) as $allkeys
| ($keys + ($allkeys - $keys)) as $cols
| ($cols, (.[] as $row | $cols | map($row[.])))
| @csv
end ;

tocsv
EOF
# ensure no space before EOF on previous line!
fi


function getStoreStockAsCSV {

# call parameters:
# $1 : numerical store ID
# $2 : alpha store location


store=$1
paras="&rad_which_stock=3&refinebystore=$store"

# output csv file name
csv_file="$2_items.csv"

rm -f ./tmp/items.json

i=0

# get href link (selected with *)
cat ./subcat_list.html | pup 'a:contains("*") attr{href}' |

while read url; do

i=$((i+1))

# remove & html entities
furl=${url//&/&}

# download html
wget --output-document="./tmp/$i.html" "$baseurl/$furl$paras"

# find JSON statement in script block
script=`cat "./tmp/$i.html" |
pup 'script:contains("window.universal") text{}'`

# remove variable name
jvar=${script/window.universal_variable =/}

# remove trailing semicolon and collect item
echo ${jvar%;*} | jq '.listing.items[]' >> ./tmp/items.json 2>/dev/null

done

# With jq slurp up the collected items into an array and output as csv
cat ./tmp/items.json |
jq --raw-output --slurp --from-file tocsv.jq > $csv_file

echo "****** stock list for $2 **********"
cat $csv_file

}



title="Which Store?"
prompt="Pick a store:"
locations=("10 Mars" "11 Jupiter" "12 Pluto")

while storelocation=$(zenity --title="$title" --text="$prompt" --list \
--column="Location" "${locations[@]}" 2>/dev/null); do

if [ -n "$storelocation" ]; then
clear
getStoreStockAsCSV $storelocation
fi

done

Mars, Jupiter, Pluto and moonbasealphax.com are all, of course, completely fictitious.

They need to be changed for sites in reality, should you want to further modify and reuse this script for some other purpose. Enjoy :)

March 02, 2017

Interest - Coding

>> View this full post page here

I'll freely admit it. I'm a bit of a code geek ...

After finding programming favourable to computer game playing, I haven't stopped hammering various keyboards. The aliens are safe from me!

Back in 1982, my own cherished setup was a BBC Microcomputer 'Model B' system. Cassettes, Floppy Discs. Eventually it even had Hard Disks! :)

The experience of structured coding using BBC Basic's Procedures and Functions support was my initial step into a few programming jobs in C & HP BASIC on UNIX and then to Microsoft Office with VBA. The latter, I successfully used as a contracting programming consultant for over twenty years!

However, now that I've moved away from general Microsoft application development, I'll use VBA and Microsoft Access for quick manipulations of data - but that's it. The moment of their joy has passed.

I believe front end interfaces are better done in a web browser, using scripting languages and web coding, especially to support multiple users.

As web projects are generally hosted in simpler environments, the supporting hardware (and me) is not anywhere as stressed as much. The support headaches of unmanaged Windows DLLs, Oracle Java installs and ActiveX, can just stay well away!

So, I'll eagerly code in HTML, CSS, XML, XSLT, VBS, PowerShell or JavaScript; and whatever new exciting scripting language or fashionable framework arises - I'd probably settle for PHP and client jQuery otherwise. KISS applies!

This Blogger based free website is a good target for my coding prowess. I find their templates easily configurable using XML, HTML, JavaScript and CSS.

March 02, 2017

Interest - Electronics

>> View this full post page here

I've long enjoyed challenges of design, manufacture, repair, and reuse of electronics. It ties together most of my other interests.

The above is an old MP3 media player I reconstructed out of an old Pentium-II laptop that had been sadly thrown out for its obsolescence. The finished project itself is now a bit redundant, fifteen years later I'm streaming most of my favourite music from Spotify rather than playing it from storage.

Things change.

Way back at high school, I was the useful kid that repaired friends' transistor radios. Back then I constructed door entrance alarms, intercoms, audio effect mixers and other gadget like things with plans published in the monthly collected 'Everyday Electronics' magazine.

In 1985, as a result of that hobbyist interest, I did an undergraduate Honours Degree course in Electrical & Electronic Engineering. My final year project was the design of a standalone recorder device to capture Teletext broadcast data pages over to floppy disc.

This wire-wrapped Motorola 6809 microprocessor board is all that remains of it.

At college, I spent many happy times with my college Radio Society mates fooling around with Amateur Radio transmitting equipment, home computers, Hi-Fi, televisions and video recorders.

However, the pastime has unfortunately turned me into a human squirrel!

For years, I've been hiding a "this one day could be useful" personal electronic junk store. There are some items which have been waiting a very long time for their rightful departure destination.

Is that destination eBay or the skip?

March 01, 2017

Interest - Music

>> View this full post page here

Enjoying music is a big interest of mine.

I can't play an instrument, but I do follow a variety of artists and different genres, anything from old school hip-hop to easy listening classics, and a lot of 80s/90s influence. :)

I'm an active Spotify Premium user, daily seeking out my unheard tracks and albums on the millions stored in the data clouds for broadband access, and mobile phone internet streaming that even works when I'm around and about in the car!

Before that, I used to spend a small fortune (really hundreds per year) on CDs bought in record shops, shops online and the remaindered stock in Woolworths.

Now it's £120 per year and enjoyment searching for really good charity shop CDs & LPs. These would mainly be for fallback if I do leave from subscribing.

Though honestly, that doesn't look likely just yet ;-)

March 01, 2017

Interest - Food

>> View this full post page here

Food on a tech blog? Yup, why not!

Though looking at this Thai dish of fried Mussels and Squid, I'm now feeling quite hungry.

Food. I love it. I'll eat most of anything cooked if it's not endangered or outrageously health hazardous.

In fact most days, I'll have most of the following cold salad items alongside some cooked meat; egg; cheese or fish. It's quite tasty, filling and takes minutes to make from a well stocked fridge.

It keeps me away from those mad, bad, salty snacks.

Well, almost ...

:-)


My favourite food type for eating out is Chinese.

Favourite drink? Ah, a well chilled Diet Coke, or a pint or two of Fosters. Cheers! :)

March 01, 2017

Interest - DIY

>> View this full post page here

A few years ago I built a tidy side garage workshop for my DIY and electronics construction use, and storage of tools and junk.

It's my mad inventor working area where wood, metal, plastics obey the rules of 'measure twice, cut once' about 50% of the time.

It's taken a little time to get this organised. Long ago, my starting out tool collection was a bit basic, nothing much more than a screaming rotary hammer drill and a box of rapidly blunted steel drill bits.

Now, it's this tangle of power tools that I regularly rely on.

Just value for money purchases (some even from supermarkets) to assist and extend my reach to fancier DIY projects, that would either be impossible, or indeed very tedious, to attempt with just manual hand tools.

With my risk planning and preparation, I do have a habit of maybe over-engineering my own project creations a teeny bit, but safety is always the main thing. I still have my original fingers :)

March 01, 2017

Interest - HiFi Audio

>> View this full post page here
On balance, I spend much more time listening to music than watching TV, so proportionally much money goes missing from the wallet finding the best equipment for that.

As a kid of the 80s, I grew up with vinyl records - LPs; singles; 12" mixes; compilations, and pre-recorded cassettes, and the naughtily self taped 'Radio 1 Top 40' show.

Every scratch, click, hiss and inadvertent DJ comment became part of my collection, and part of my memory of great events.

The later Digital CD, MiniDisc, MP3/AAC and streaming developments, of course changed some of that; but like many I'm currently taking a trip back to enjoy those old formats played as they originally were, warts and all.

Sometimes older second-hand budget equipment still shines for that. My favourite Pioneer PL-12D turntable is now over 40 years old.

That's a great book by the way ;)

Sometimes I find, that if I've been listening to compressed streaming all day and then putting on an old charity shop bought LP, a copy ideally recorded and pressed before the digital 1980s - I'd still be in awe on how much more alive and 'open' it actually sounds!

And I could say the same for some of my old cassettes; well, them that I recorded on TDK SA90's.

Treat yourself to a listen to a true analogue recording sometime. Digital has certainly lost something ...

February 19, 2017

Making Bootable USB drives from Win7

>> View this full post page here
In preparation, you will need a copy of the BOOTSECT.EXE program that's provided on the Windows 7 DVD/ISO in the 'Boot' directory.

Also the USB device to be used must:
  • Be at least xGB in size
  • Have no data on it that needs preserving (device will be wiped and formatted)
  • Be capable of being configured as a bootable device (many cheap/free USB sticks do not work as bootable devices)

Prepare the USB memory stick
Within an elevated (administrator) command prompt, run DISKPART.

Within the diskpart prompts follow these steps:

LIST DISK
Once you enter the LIST DISK command, it will show the disk number of your USB drive. It will probably be the last in the list - you can tell by its size. Be careful, a mistake here will be disastrous for data on your other attached disk drives!

Let's suppose it's disk 4.

SELECT DISK 4 (Replace “4” with your disk number)
CLEAN
CREATE PARTITION PRIMARY
SELECT PARTITION 1
ACTIVE
FORMAT FS=NTFS QUICK
(Format process may take few seconds)
ASSIGN
EXIT
By now, the drive should be viewable in Windows Explorer with an assigned drive letter.

So make it bootable.
Run the following at the command prompt for the BOOTSECT.EXE executable.

BOOTSECT.EXE /NT60 H: (where H: in this case is the USB drive)
And that's it! :) If this USB stick is for use in deployment of an configured operating system in MDT's Deployment Workbench, the entire contents of your source directory can then be copied using the following command.

robocopy {source path} H:\ /MIR /XD USMT5
The /XD switch above ensures that version 5 of USMT is not copied should it happens to be found in the source, and we don't require it (say, if doing USMT4 based migration from XP to 7).

February 14, 2017

Microsoft Visio 2003, XML for Visio

>> View this full post page here

My past development experience with Microsoft Visio 2003 was a workaround for the dropped CSV import functionality, as featured in previous versions.

Before 2003, 'CSV import' was something that many Excel folks relied on for "drawing" diagrams from their tabulated descriptions in a CSV file.

The worldwide financial data network mapping project that I was working on was affected by this. Initially we were stuck, as unlike other Office application software, Visio had no available COM methods for performing our drawings through VBA automation.

Luckily, after discovering Visio's VDX data format was essentially the hierarchical relationships between library shapes expressed in XML, my workable solution involved just mimicking that data file format using Office VBA together with a bit of XMLT.

Then, soon afterwards in 2004, Microsoft released VXD royalty free as 'DatadiagramML'. And the following documentation I could have done with! Grrrr...
    Overview of DatadiagramML :
    https://msdn.microsoft.com/en-us/library/office/ff768582(v=office.14).asp
I did take a later look at VSDX, the new XML format of Visio 2003, and found it so different. I doubt I would have been able to recreate that file as easily as I did with VDX.
    Introduction to the Visio file format (.vsdx) : https://msdn.microsoft.com/en-us/library/office/jj228622.aspx
Now come forward to Visio 2013 and I sadly find VDX / DatadiagramML is no longer supported!

Aye, things move on yet again! :(

    February 14, 2017

    Microsoft Office, Seen them all off?

    >> View this full post page here
    For me it's been a never ending series of wonder.
    • 1992 - Microsoft Office 4.3
    • 1995 - Office 95
    • 1997 - Office 97
    • 2000 - Office 2000
    • 2002 - Office XP
    • 2003 - Office 2003
    • 2007 - Office 2007
    • 2010 - Office 2010
    • 2013 - Office 2013
    For all these products it was Access, Excel and Word that mostly got my attention, such that I was able to easily code up business applications for these environments using VBA.

    I do need to experience Office 2016 / Office 365 sometime, but there are now so many free office suite alternatives also with programmability features.
    • Google G Suite
    • LibreOffice
    They do have their different strengths and weaknesses though ...

          February 01, 2017

          Linux guest on Vmware ESXi, enabling cut and paste in Vmware Remote Console on Ubuntu desktop

          >> View this full post page here

          Need to ensure that Open VM Tools is installed then reboot the guest OS.


          sudo apt-get install open-vm-tools
          sudo apt-get install open-vm-tools-desktop
          The last line (often missed)
          • Enables resizing of the guest display to match host console window or the VMware Remote Console Window for vSphere
          • Enables text copy and paste operation between host and guest UI (either direction)
          • Enables drag and drop operation between guest and host (either direction) for the VMware Workstation and VMware Fusion products (not supported on vSphere)

          Note this depends on Ubuntu using X (gnome)

          Also the following two lines need adding to the virtual machine configuration


          isolation.tools.copy.disable = false
          isolation.tools.paste.disable = false

          Further details here,

          Clipboard Copy and Paste does not work in vSphere Client 4.1 and later
          https://kb.vmware.com/kb/1026437

          VMware support for Open VM Tools (2073803)
          https://kb.vmware.com/kb/2073803

          January 14, 2017

          Enabling Hyper-V Server 2012 firewall to allow remote MMC managment

          >> View this full post page here

          The firewall settings by default are not enabled, this crashes the MMC client.

          To enable:


          netsh firewall set service type=remoteadmin mode=enable
          then run this:

          netsh advfirewall firewall set rule group="Remote Administration" new enable=yes

          Image Overlay