Skip to main content

5 posts tagged with "script"

View All Tags

Migrate WordPress URLs to nginx (hexo)

· 2 min read

I have migrated my blog from WordPress to hexo, but the old URLs need to be permanently redirected. I'm using NGINX as my web server, so I set up some rules for redirecting the old posts to the new URLs. It's a bit tricky because WordPress used query string param for identifying the page, but it can be sorted out using if and the NGINX $arg_ variable. In order to generate these rules, I wrote a simple node script that runs through the exported Markdown files from WordPress. Markdown files were exported using Jekyll Exporter plugin.)

Extract GPS data from "Tracker" iOS app to GPS

· One min read

Quick script for extracting gps data from the Tracker GPS app

First export data from app com.eofster.tracker using something like iPhone Backup Extractor (http://supercrazyawesome.com/)

mkdir tracker-extract && cd tracker-extract

npm install csvtojson
npm install gps-to-gpx

(cd 'com.eofster.tracker/Library/Application Support/com.eofster.tracker' && sqlite3 -header -csv Tracker.sqlite "select * from ZTRACKPOINT order by ZTIMESTAMP;" > out.csv)

Create index.js:

var Converter = require("csvtojson").Converter;
var converter = new Converter({});

const createGpx = require('gps-to-gpx').default;

//end_parsed will be emitted once parsing finished
converter.on("end_parsed", function (jsonArray) {
//console.log(jsonArray);
const converted = jsonArray.map(pos => {
return {
latitude: pos.ZLATITUDE,
longitude: pos.ZLONGITUDE,
elevation: pos.ZALTITUDE,
time: new Date((pos.ZTIMESTAMP+978307200)*1000).toISOString()
};
});

const gpx = createGpx(converted, {
activityName: 'tur',
startTime: converted[0].time,
});

console.log(gpx);
});

//read from file
require("fs").createReadStream("out.csv").pipe(converter);

Run:

node . > out.gpx

XBMC memory leak remedy

· One min read

XBMC (now Kodi) has always had a tendency of leaking memory, so that it will eventually thrash and crash. My simple solution to this is to run xbmc inside a for loop instead of directly (just run the script from .xinitrc):

xbmc_angel.sh:

#!/bin/bash
while [ 1 ]; do
xbmc
nohup sleep 10
done

...And add the following to the local XBMC user's crontab:

0 4 * * *       killall xbmc.bin

This will kill XBMC every night at 4 o'clock. And give you a fresh XBMC every day!

How to download videos from Pepper Flash on linux

· One min read

The new Pepper Flash plugin broke my old script for listing/downloading cached flash/flv videos.

Here is a new script. Uses sudo because the /proc/$PID/fd directory is root only. This solution is based on silviot's solution here: http://superuser.com/questions/622606/how-do-i-save-the-buffered-flash-video-on-linux.

#!/bin/bash
for FLASHPID in $( pgrep -f chrom ) ; do (for FLASHFILE in $(sudo ls -l /proc/$FLASHPID/fd|egrep "(/tmp/Flash|Pepper Data)" | sed -r 's/^.* ([0-9]+) -> .*$/\1/'); do echo /proc/$FLASHPID/fd/$FLASHFILE; done ); done

Then you can just copy the file into home, like:

cp /proc/26493/fd/30 ~/

Hvordan laste ned / rippe video fra VGTV

· 2 min read

Det er overraskende enkelt å lagre video fra VGTV.

Jeg har laget et python-skript som automatisk henter ut adressen. Last ned skriptet her.

Kopier lenken til videoen du vil ha, feks. http://www.vgtv.no/?id=33283&category=1

Bruk python fra komandolinja og hent ut adressen ved hjelp av skriptet, eks.:

python vgtv_url.py http://www.vgtv.no/?id=33283
python.exe vgtv_url.py http://www.vgtv.no/?id=33283

(Windows CMD)

Du vil så få en rtmp:// URL. Åpne denne i VLC og fortell VLC å automatisk lagre videostrømmen.

Eventuelt, bruk VLC eller mplayer på kommandolinjen med en av disse one-linerne:

vlc "$(python vgtv_url.py http://www.vgtv.no/?id=X)" --demux=dump --demuxdump-file=video.mp4
mplayer -dumpfile video.mp4 -dumpstream "$(python vgtv_url.py http://www.vgtv.no/?id=X)"

Gammel (manuell) metode:

  1. Ta URL-en til en video, f.eks.: http://www.vgtv.no/?id=33283&category=1

  2. Notér id (her: 33283)

  3. Gå inn på: http://www.vgtv.no/api/?do=playlist&id=NOTERT_ID F.eks.: http://www.vgtv.no/api/?do=playlist&id=33283

  4. Fra XML-filen, hent ut rtmp-adressen under følgende hierarki (prøv et vilkårlig location-element): <playlist> <trackList> <track> <location>

Åpne så denne URL-en i MPlayer. F.eks.:

mplayer -dumpfile video.mp4 -dumpstream rtmp://88.87.43.102/streaming/mp4:storage/compressed//33283/flash_1000.mp4

Dette kan også gjøres med VLC:

vlc rtmp://88.87.43.98/streaming/mp4:storage/compressed//33283/flash_1000.mp4 --demux=dump --demuxdump-file=video.mp4

Vent, og du har snart videoen på disk.