Archive

Posts Tagged ‘script’

Windows proxy control script

December 2nd, 2010 No comments

Here’s a simple script that lets you toggle on or off your internet proxy in Windows. Save it to a file called Proxy.vbs on your desktop and double-click the file to execute the script.film Despicable Me 3

As shown below, the script will not change the proxy server address, but will simply turn it ON or OFF. If you want to also modify the proxy server and exception list every time you turn it on, update lines 37 and 38, and uncomment lines 40-41.Watch Full Movie Online Streaming Online and Download

Parts of this script come from a comment someone posted on a web site, but I no longer have the link to provide proper attribution.

Const HKCU=&H80000001 'HKEY_CURRENT_USER
Const HKLM=&H80000002 'HKEY_LOCAL_MACHINE

Const REG_SZ		= 1
Const REG_EXPAND_SZ	= 2
Const REG_BINARY	= 3
Const REG_DWORD		= 4
Const REG_MULTI_SZ	= 7
Const HKCU_IE_PROXY	= "Software\Microsoft\Windows\CurrentVersion\Internet Settings"

Set oReg=GetObject("winmgmts:!root/default:StdRegProv")

Main

Sub Main()
	buttons = vbQuestion + vbYesNoCancel + vbDefaultButton1

	If GetValue(HKCU,HKCU_IE_PROXY,"ProxyEnable",REG_DWORD) = 1 AND _
	Len(GetValue(HKCU,HKCU_IE_PROXY,"ProxyServer",REG_SZ)) > 0 Then
		' If Proxy is set then default to turning it off
		buttons = buttons + vbDefaultButton2
	End If

	choice = MsgBox("Enable the internet proxy?", buttons, "Proxy setting")
	If choice = vbYes Then
		SetProxy True
	ElseIf choice = vbNo Then
		SetProxy False
	End If
End Sub

Sub SetProxy(enabled)
	If enabled = False Then
		CreateValue HKCU,HKCU_IE_PROXY,"ProxyEnable",0,REG_DWORD
		MsgBox "Proxy Disabled", vbInformation, "Proxy OFF"
	Else
		strProxyServer = "MyProxySvr:80"
		strProxyOveride = "*.domain.com;*.domain2.com;*domain3.com"
	
		'CreateValue HKCU,HKCU_IE_PROXY,"ProxyServer",strProxyServer,REG_SZ
		'CreateValue HKCU,HKCU_IE_PROXY,"ProxyOverride",strProxyOveride,REG_SZ
		CreateValue HKCU,HKCU_IE_PROXY,"ProxyEnable",1,REG_DWORD
		MsgBox "Proxy Enabled and set to:" & vbcrlf & "(" & strProxyServer & ")", vbInformation, "Proxy ON"
	End If
End Sub

Function CreateValue(Key,SubKey,ValueName,Value,KeyType)
	Select Case KeyType
	Case REG_SZ
		CreateValue = oReg.SetStringValue(Key,SubKey,ValueName,Value)
	Case REG_EXPAND_SZ
		CreateValue = oReg.SetExpandedStringValue(Key,SubKey,ValueName,Value)
	Case REG_BINARY
		CreateValue = oReg.SetBinaryValue(Key,SubKey,ValueName,Value)
	Case REG_DWORD
		CreateValue = oReg.SetDWORDValue(Key,SubKey,ValueName,Value)
	Case REG_MULTI_SZ
		CreateValue = oReg.SetMultiStringValue(Key,SubKey,ValueName,Value)
	End Select
End Function

Function DeleteValue(Key, SubKey, ValueName)
	DeleteValue = oReg.DeleteValue(Key,SubKey,ValueName)
End Function

Function GetValue(Key, SubKey, ValueName, KeyType)
	Dim Ret

	Select Case KeyType
	Case REG_SZ
		oReg.GetStringValue Key, SubKey, ValueName, Value
		Ret = Value
	Case REG_EXPAND_SZ
		oReg.GetExpandedStringValue Key, SubKey, ValueName, Value
		Ret = Value
	Case REG_BINARY
		oReg.GetBinaryValue Key, SubKey, ValueName, Value
		Ret = Value
	Case REG_DWORD
		oReg.GetDWORDValue Key, SubKey, ValueName, Value
		Ret = Value
	Case REG_MULTI_SZ
		oReg.GetMultiStringValue Key, SubKey, ValueName, Value
		Ret = Value
	End Select

	GetValue = Ret
End Function
Categories: Uncategorized Tags: ,

Script to show id3v2 frames present or absent in a file

October 29th, 2009 No comments

This is a very simple script. See the usage at the top of the script starting on line 28.

#!/bin/bash

# Author: Gabriel Burca (gburca dash mp3 at ebixio dot com)
# Version: 1.0
#
# Copyright (C) 2006-2009  Gabriel Burca (gburca dash mp3 at ebixio dot com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


set -o nounset
set -o errexit

function usage () {
    cat << EOF
Checks for particular id3v2 frames in a set of files.
Usage:
    $0 <option> <FRAME> files...

Options:
    -m | --missing  Show files that are missing the frame
    -h | --has      Show files that have the frame
    -s | --show     Show the contents of the frame
    -a | --all      Show all the frames

For example, to find mp3's with no album art:
    $0 -m APIC *.mp3

Some sample frames:
    APIC    - Cover art
    TIT2    - Song name
    TPE1    - Artist
    TALB    - Album
    TCON    - Genre
EOF
}

function FilesWithoutFrame() {
    FRAME=$1
    shift

    for file in $@ ; do
        id3v2 -R "$file" | egrep "^$FRAME " 2>&1 > /dev/null
        if [ $? -gt 0 ]; then
            # $file is missing $FRAME
            echo $file
        fi
    done
}

function FilesWithFrame() {
    FRAME=$1
    shift

    for file in $@ ; do
        id3v2 -R "$file" | egrep "^$FRAME " 2>&1> /dev/null
        if [ $? -eq 0 ]; then
            # $file has $FRAME
            echo $file
        fi
    done
}

function ShowFrameContents() {
    FRAME=$1
    shift

    for file in $@ ; do
        id3v2 -R "$file" | egrep "^$FRAME "
    done
}

function ShowAll() {
    for file in $@; do
        echo
        echo
        id3v2 -R "$file"
    done
}


################################################################################
# main()
################################################################################

if [ $# -lt 2 ]; then
    usage
    exit 1
fi

IFS_orig=$IFS
IFS='
'

case $1 in
    -m | --missing)
        shift
        FilesWithoutFrame $@
        ;;
    -h | --has)
        shift
        FilesWithFrame $@
        ;;
    -s | --show)
        shift
        ShowFrameContents $@
        ;;
    -a | --all)
        shift
        ShowAll $@
        ;;
    *)
        usage
        exit 1
        ;;
esac

IFS=$IFS_orig
Categories: Uncategorized Tags: , , , ,

Convert flac and wav files to mp3

October 22nd, 2009 No comments

In case it might be useful to others, here’s a script that can be used to convert a bunch of *.wav files to *.flac and *.flac files to *.mp3. The script will first first convert all *.wav files (if any) to *.flac, then it will convert all *.flac files to *.mp3. See the usage instructions starting on line 31 below for more details.

I called the script

Watch Full Movie Online Streaming Online and Download

flac2mp3dir.sh

#!/bin/bash

# Author: Gabriel Burca (gburca dash flac2mp3dir at ebixio dot com)
# Version: 1.0
#
# Copyright (C) 2006-2009  Gabriel Burca (gburca dash flac2mp3dir at ebixio dot com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


set -o nounset
set -o errexit

function usage () {
    cat << EOF
Usage:
$0 source/dir dest/dir

All wav/flac files in source/dir and its subdirectories will be converted to
mp3 and placed in dest/dir while maintaining the directory structures. ID3
tags will also be copied from flac to mp3 files.

Existing files (mp3 or flac) will not be overwritten.
Source and destination directories can be the same.

EOF
}

function absname () {
        # Returns the absolute filename of a given file or directory.
        if [ -d "$1" ] ; then   # Only a directory name.
                dir="$1"
                #unset file
                file=""
        elif [ -f "$1" ] ; then # Strip off and save the filename.
                dir=$(dirname "$1")
                file="/"$(basename "$1")
        else
                # The file did not exist.
                # Return null string as error.
                echo
                return 1
        fi
 
        # Change to the directory and display the absolute pathname.
        cd "$dir"  > /dev/null
        echo "${PWD}${file}"
}

function flac2mp3 () {
        INF="$1"
        OUTF=`echo "$INF" | sed 's/\.flac$/.mp3/'`
        PWD=`pwd`
        SUBDIR=${PWD:$SRCDIRLEN}
        #SUBDIR=${PWD#$SRCDIR}

        INF="$PWD/$INF"
        OUTF="$DESTDIR$SUBDIR/$OUTF"
        #echo "$INF ... $PWD $SRCDIRLEN $SUBDIR $OUTF"

        if [ -e "$OUTF" ] ; then
                if [ "$OUTF" -ot "$INF" ] ; then
                        echo "*** Re-converting old file: $OUTF"
                        # rm -f "$OUTF"
                else
                        echo "*** Skip flac2mp3! Output file already exists: $OUTF"
                        return
                fi
        fi

        if [ ! -e "$DESTDIR$SUBDIR" ] ; then
                mkdir -p "$DESTDIR$SUBDIR"
        fi

        # Convert flac to mp3
        echo "${INDENT}flac2mp3 Converting $INF => $OUTF"
        #touch "$OUTF"
        flac -c -d "$INF" | lame --preset standard --replaygain-accurate - "$OUTF"

        # Copy tags to new file
        id3 -D "$INF" -1 -2 "$OUTF"

        # Copy non-flac/non-wav (folder.jpg, etc...) files to dest/dir
        if [[ ! -e "$DESTDIR$SUBDIR/folder.jpg" && -e "folder.jpg" ]] ; then
                cp folder.jpg "$DESTDIR$SUBDIR"
        fi
}

function wav2mp3 () {
        INF="$1"
        OUTF=`echo "$INF" | sed 's/\.wav$/.flac/'`

        if [ -e "$OUTF" ] ; then
                echo "*** Skip wav2mp3! Output file already exists: $OUTF"
                return
        fi

        echo "${INDENT}wav2mp3 Converting $INF => $OUTF"
        #touch "$OUTF"
        flac -V -o "$OUTF" "$INF"
        flac2mp3 "$OUTF"
}

function traveldir ()
{
        dir="$1"

        pushd "$dir" > /dev/null
        echo "Entering: `pwd`"

        for a in *
        do
                if test -d "$a" ; then
                        traveldir "$a"
                else
                        if [[ `expr match "$a" '.*\\.flac$'` > 0 ]] ; then
                                flac2mp3 "$a"
                        elif [[ `expr match "$a" '.*\\.wav$'` > 0 ]] ; then
                                wav2mp3 "$a"
                        else
                                echo "${INDENT}Skipping: $a"
                        fi
                fi
        done
        popd > /dev/null
}

################################################################################
# main()
################################################################################

if [[ $# < "2" ]] ; then
        usage
        exit 1
fi

SRCDIR="$1"
DESTDIR="$2"

if [[ ! -e "$DESTDIR" ]] ; then
        mkdir -p "$DESTDIR"
fi

if [[ ! -e "$SRCDIR" ]] ; then
        echo "$SRCDIR does not exist!"
        exit 2
fi

# Get absolute directories
SRCDIR=$(absname "$SRCDIR")
DESTDIR=`absname "$DESTDIR"`

SRCDIRLEN=`expr length "$SRCDIR"`
INDENT="    "

pushd . > /dev/null
traveldir "$SRCDIR"
popd > /dev/null
Categories: Uncategorized Tags: , , , , , ,

Inspect the f-stop photo.db file

October 2nd, 2009 3 comments

At one point I had a need to extract various pieces of information from the f-spot photo.db file (that’s where f-spot keeps all the information), so I wrote this script. Posting it here in case others find it useful. I called it

f-spot-list


#!/bin/bash

# Author: Gabriel Burca (gburca dash fspotlist at ebixio dot com)
# Version: 1.0
#
# Copyright (C) 2006-2009  Gabriel Burca (gburca dash fspotlist at ebixio dot com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

set -o nounset
set -o errexit

function usage () {
    cat << EOF
Extracts various pieces of information from an f-spot photo.db file.
Usage:
    $0 <photo.db> <option>

Options:
    -P | --Photo        Pictures in the Photo directory
    -k | --links DIR... All pictures in DIR that are not links
    -a | --all          All pictures in database
    -h | --has TAG...   Show pictures tagged with the tag
    -t | --tags         Show all available tags

<photo.db> is usually "~/.config/f-spot/photos.db"

Ex:
    - Find all photos tagged "Favorites" or "Web":
    $0 photos.db -h Favorites Web | sort | uniq | sed 's|^file://||' \
        | xargs -I linkName readlink -e linkName

EOF
}

function PhotosInPhotoDir() {
    sqlite3 "$PHOTO_DB" "select id, uri from photos where uri like '%Photos%';"
}

function HasTag() {
    for TAG in $@ ; do
        SQL="select base_uri || filename from photos \
            inner join photo_tags on photos.id = photo_tags.photo_id \
            inner join tags on photo_tags.tag_id = tags.id \
            where tags.name like '$TAG';"
        #echo $SQL
        sqlite3 "$PHOTO_DB" "$SQL"
    done
}

function ShowNonLinks() {
        for DIR in $@ ; do
                find "$DIR" -type f
        done
}

function ShowTags() {
    sqlite3 "$PHOTO_DB" "select name from tags order by name;"
}

function ShowAll() {
    sqlite3 "$PHOTO_DB" "select * from photos;"
}

################################################################################
# main()
################################################################################

if [ $# -lt 2 ]; then
    usage
    exit 1
fi

IFS_orig=$IFS
IFS='
'

PHOTO_DB=$1
shift

if [ ! -e "$PHOTO_DB" ]; then
    usage
    exit 2
fi

case $1 in
    -P | --Photo)
        shift
        PhotosInPhotoDir $@
        ;;
    -k | --links)
        shift
        ShowNonLinks $@
        ;;
    -t | --tags)
        shift
        ShowTags $@
        ;;
    -h | --has)
        shift
        HasTag $@
        ;;
    -a | --all)
        shift
        ShowAll $@
        ;;
    *)
        usage
        exit 1
        ;;
esac

IFS=$IFS_orig
Categories: Uncategorized Tags: , , , ,