Python Line Counter

Yesterday I was looking for a Python source code line counter to give me a summary of some source files, but I couldn’t find a free one that would do the job as I wanted. So I created one. And you can have it for free (GNU GPL) – download it here:

Download Python Line Counter

Sample usage:

cmd> plc.py tubecore.py tubewx.py tubewxdialogs.py

Input files:
tubecore.py
tubewx.py
tubewxdialogs.py

Total lines:   1510
Code lines:    1111
Comment lines: 139
Blank lines:   260

-Wayne

Tubecaster 2.0.1 Released!

I’m pleased to report that Tubecaster 2.0.1 for Windows is now available for download.  Click here to go to the downloads page on the Tubecaster homepage.

Highlights of this release:

  • Supported media formats:
    • MP3
    • FLAC
    • WAV
    • Ogg Vorbis
    • AVI
    • MPG
    • MP4
    • 3GP
  • Additional language support: Afrikaans
  • Automatically downloads HD version of the chosen video if available
  • Proxy server support
  • Login support – for downloading videos marked as private or age restricted

I’m keen to get feedback on what people would like to see in the next release.  You can report bugs or request new features here.  On that same site you can also vote for features that have already been requested.  The more votes a feature gets the more likely and quickly it is to be implemented.

-Wayne

DPAPI user-mode access in Python

In the latest version of Tubecaster I’ve come to the point of needing to give users the option of storing passwords on disk. Needless to say the very thought sent shivers down my spine. I was stressing over the problem of how to store passwords for automatic retrieval and use by the software, but at the same time making them secure enough that they can’t easily be retrieved by nasty people. This led me to make this post on Stack Overflow.

Read More →

Python proxy client connections requiring authentication using urllib2 ProxyHandler

I’ve been playing around with trying to pass HTTP connections through a proxy server requiring authentication from Python and after a few hours of hunting around I’ve managed to find enough bits of information to cobble together into a working example.  Since I couldn’t find such an example myself I’ve put this one together.  It looks simple now, which it is (thanks Python!), but unfortunately I couldn’t find any documentation that presented it this clearly.

Just substitute the appropriate variable values and it should run as is.

# urllib2_proxy_handler.py
#
# Author: Wayne Koorts
# Date:   27/10/2008
#
# Example for using urllib2.urlopen() with a proxy server requiring authentication

import urllib2

uri = "http://www.python.org"
http_proxy_server = "someproxyserver.com"
http_proxy_port = "3128"
http_proxy_realm = http_proxy_server # Worked in my (limited) testing environment.
http_proxy_user = "username"
http_proxy_passwd = "password"

# Next line = "http://username:password@someproxyserver.com:3128"
http_proxy_full_auth_string = "http://%s:%s@%s:%s" % (http_proxy_user,
                                                      http_proxy_passwd,
                                                      http_proxy_server,
                                                      http_proxy_port)

def open_url_no_proxy():
    urllib2.urlopen(uri)
    
    print "Apparent success without proxy server!"
        
def open_url_installed_opener():
    proxy_handler = urllib2.ProxyHandler({"http": http_proxy_full_auth_string})
    
    opener = urllib2.build_opener(proxy_handler)
    urllib2.install_opener(opener)
    urllib2.urlopen(uri)
    
    print "Apparent success through proxy server!"
    
if __name__ == "__main__":
    open_url_no_proxy()
    open_url_installed_opener()

Tested using an Ubuntu 8.04 Server Edition proxy server with a mostly out-of-the-box Squid installation using ncsa_auth authentication.

-Wayne

Tubecaster: First Linux version

If you’d like to try an early version of my port of Tubecaster to Linux, you can download it here.

Please see the readme file within the archive for dependency details. Basically run “python tubecasterWX.py” after installing the “ffmpeg” and “python-wxgtk2.8” packages from your distro’s package manager. Tested on Ubuntu 8.04.

It pretty much works 100% except for a bug I get on my system which I haven’t had a chance to fix yet:

– After downloading one video and the interface resets itself the window doesn’t refresh properly anymore.  It’s hard to explain but basically the app keeps working in the background but the window and its contents don’t “repaint” themselves so you just see the outline of the window.  Very bizarre and I’m hoping it’s just because I’m running my test box in a virtual machine and I have a dodgy ATi video card.

Enjoy!

-Wayne