Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- """ Script to fuck with www.indiangilma.com """
- from xml.dom import minidom
- import urllib2
- import getopt
- import sys
- import re
- class IG:
- def get_xml(self,source):
- """ uses to get the xml source from website """
- file_pointer = urllib2.urlopen(source)
- return file_pointer
- def get_url(self,fp):
- """ gets the url from the xml"""
- try:
- xmldoc = minidom.parse(fp)
- src = xmldoc.getElementsByTagName('src')
- except:
- return 'invalid video key'
- return src[0].firstChild.data
- def get_id(self,url):
- """ Gets the video id from the url
- Sample url:
- http://www.indiangilma.com/video/1257/mumbai-juhu-beach-teen
- """
- l = url.split('/')
- l.reverse()
- try:
- return l[1]
- except IndexError:
- print "Invalid url"
- usage()
- def usage():
- print >>sys.stderr,'Usage: %s [-i video_id][-r video_id_range] [-u video_url] [-f out_file]' % sys.argv[0]
- sys.exit(1)
- if __name__ == '__main__':
- if sys.argv[1:] == []:
- usage()
- try:
- opts,args = getopt.getopt(sys.argv[1:],'u:i:r:f:')
- except getopt.GetoptError:
- usage()
- video_id = []
- out_file = None
- obj = IG()
- for o, a in opts:
- if o == '-u':
- match = re.search('^http://|^www.indiangilma.com',a)
- if match == None:
- usage()
- else:
- video_id.append(obj.get_id(a))
- elif o == '-i':
- video_id.append(a)
- elif o == '-r':
- try:
- video_id = range(1,int(a))
- except:
- print "Invalid range"
- usage()
- elif o == '-f':
- out_file = a
- if out_file:
- outfp = open(out_file,'w')
- for i in video_id:
- source = 'http://www.indiangilma.com/media/player/config.php?vkey='+str(i)
- fp = obj.get_xml(source)
- durl = obj.get_url(fp)
- print durl
- durl = durl+'\n'
- if durl != "invalid video key\n" and out_file:
- outfp.write(durl)
- if out_file:
- outfp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement