Sunday, November 10, 2013

Python script to get your Movie details from omdbapi.com

This was my first(and the last one till date) Python script. It finds movies in a directory and uses the http://www.omdbapi.com/ to get and print details of the movie on the console.
'''
Copyright Mad Piranha, Apr 10, 2012

Used 2to3.py to convert from python26 to python33
@author: Mad Piranha
'''

import re
import glob
import http.client, urllib.request, urllib.parse, urllib.error
import os
import fnmatch

apiURL="www.omdbapi.com"

# Directory to find movies
movieFolder="G:\MotionPics\__HIGHRES"

# Ignore these directories
ignore=['Sample', 'South Park', 'Tom&Jerry', 'Video clips', 'Subtitles', 'TV Serires', 'TELGU', 'TAMIL', 'MALAYALAM', 'KANNADA', 'HINDI', 'OTHERS', 'Hindi Cinema', 'BOLLYWOOD']

# File name filter regular expression 
FILE_NAME_MATCH_EXPR="(?P.*)\.(avi|divx|mkv|mpg|mp4|wmv|bin|ogm|vob|iso|img|bin|ts)"

# Get RottenTomatoes data
tomato = 'true' 

def moviedetails(moviename):

    # Create URL parameters. Check http://www.omdbapi.com for details
    params = urllib.parse.urlencode({'tomatoes':tomato, 't':moviename})
    connection = http.client.HTTPConnection(apiURL)
    # Connect
    connection.request("GET", "/?"+params);
    response = connection.getresponse();
    # Get/Read response and print
    print(response.status, response.reason)
    data1 = response.read()
    print(data1)
    connection.close()

# Get the movie name from the file name
def movienamefromfile(moviefilename):

    # Remove all characters after these special characters
    substr = re.sub("(\[|\()(.*)$", "", moviefilename, )
    # Remove unnecessary words and anything after that
    substr = re.sub("(?i)(dvdrip|brrip|UNRATED|WEBSCR|KLAXXON|xvid|r5)(.*)$", "", substr, re.I)
    # Remove 4digits in a row (year of the movie ?)
    substr = re.sub("(\d{4})(.*)$", "", substr, )
    # Replace . and _ with space
    substr = re.sub("(\.|_)", " ", substr, )
    print(moviefilename, " -> ", substr)
    return substr.rstrip().lstrip()


def parsemoviefolder(foldername):
    
    # For all the directories in the specified foldername
    for root, dirnames, filenames in os.walk(foldername, ):
    
        # Remove the directories mentioned in the ignore list.
        for val in ignore :
            if val in dirnames:
                dirnames.remove(val)

        for filename in filenames:
            # If the file name matches the movie file name expression
            moviefile = re.match(FILE_NAME_MATCH_EXPR, filename, re.I)
            if moviefile:
                # Get the movie name from the file name
                moviename = movienamefromfile(moviefile.group("name"))
                # Get and print the movie details
                moviedetails(moviename)
                print()
            
parsemoviefolder(movieFolder)

Saturday, November 9, 2013

Location and Size properties of Browser window and Document.

The tables below shows the values of your browser window's and the document's location and size.

Move, Resize or Scroll your browser to see the values update.

Credits:
  http://stackoverflow.com/questions/504052/determining-position-of-the-browser-window-in-javascript
  http://www.w3schools.com/js/js_window.asp
  http://www.w3schools.com/js/js_window_screen.asp


Source for the above tables...
    

Monday, November 28, 2011

Disable Assert dialogs during windows native code debugging

Debugging native code on windows sometimes throws the assert dialog boxes. In some cases you may not be interested in those asserts or as in my case those boxes may be blocking your UI debugging. You can comment/remove all your assert statements from your source. But in some cases the asserts are from the code which you dont have access, or may be you dont want to remove them for some reason.

Here is what I did to stop those assert dialog boxes from coming up.

Add the following code in your DllMain
#ifdef _DEBUG
    _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
#endif
You have to include...
#ifdef _DEBUG
#include "Crtdbg.h"
#endif

For more info, check this MSDN Link...
http://msdn.microsoft.com/en-us/library/1y71x448%28v=vs.80%29.aspx

Remote Debugging .Net Managed Code

Some of the errors that I saw while trying to debug managed(.net) code remotely...
  • Logon failure: unknown username or bad password
  • A firewall may be preventing communication via dcom to the local computer
  • The visual studio remote debugger on the target computer cannot connect back to this computer. Authentication failed.
... and many more.

There was no problem with native code remote debugging.

Here is the setup I had to do to make it work. Tried this with VS2010 to debug a .net 4.0 application. This should also work for other VS IDEs and .net frameworks.
  • Firstly, both the machines should be logged in using the same username(local user) and password. The user has to be an administrator. For example, I created a new local user on both the machines named "madscientist" and added it to the administrators group.
  • Now, Im not sure for which user the following security setting had to be done (local or remote).. i did it for both of them...
  • Open Control panel > Administrative Tools > Local Security Policy
  • Local security settings window > Security settings > Local policies > User rights assignments >
  • Double Click on "Logon as service", listed on the right side and add the user here.
  • Next, Local security settings window > Security settings > Local policies > Security options
  • Double Click "Network access: Sharing and security model for local accounts", select "Classic: Local users authenticate as themselves."
  • In case you are not able to connect machines to each other using hostnames... Edit the C:\WINDOWS\system32\drivers\etc\hosts file on both the machines. Add the name and ipaddress the other machine.   
  • Restart both the machines... everything in windows(and in life) works fine after a restart.
  • Run the remote debugger on the machine where you have the process to be debugged. Make sure you have your debug dlls there.
  • On the local machine open the attach to process window and in the qualifier text enter "username@remotehostname" (ex:madscientist@machinename). Trasnport, default.
This should list all the processes.

Some more things you have to take care is that...
  • Make sure the two machines are connected to each other :)
  • Take care of the firewall... if any warnings appear w.r.t visual studio or the debugger... grant access.
  • You can debug
    • .net 4.0 using VS2010
    • .net 3.0 using VS2008 or later,
    • .net 2.0 using VS2005 or later,
    • .net 1.1 using VS2003 or later