/default.py
Python | 2278 lines | 2212 code | 36 blank | 30 comment | 16 complexity | dc4570ae00bc0c3bddc2854e7b8891c6 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- #!/usr/bin/python
- #Icefilms.info v1.0.10 - anarchintosh / daledude / westcoast13 2011-07-02
- # Quite convoluted code. Needs a good cleanup for v1.1.0
- #standard module imports
- import sys,os
- import time,re
- import urllib,urllib2,cookielib,base64
- import xbmc,xbmcplugin,xbmcgui,xbmcaddon
- import unicodedata
- import random
- import copy
- #imports of things bundled with addon
- import clean_dirs,htmlcleaner
- from xgoogle.BeautifulSoup import BeautifulSoup,BeautifulStoneSoup
- from xgoogle.search import GoogleSearch
- from mega import megaroutines
- from metautils import metahandlers
- def getSiteURL():
- ao = xbmcaddon.Addon(id='plugin.video.icefilms')
- url = ao.getSetting('icefilms-url')
- return url
- # global constants
- ICEFILMS_URL = getSiteURL()
- ICEFILMS_AJAX = ICEFILMS_URL+'membersonly/components/com_iceplayer/video.phpAjaxResp.php'
- ICEFILMS_REFERRER = 'http://www.icefilms.info'
- USER_AGENT = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'
- def xbmcpath(path,filename):
- translatedpath = os.path.join(xbmc.translatePath( path ), ''+filename+'')
- return translatedpath
-
- def Notify(typeq,title,message,times):
- #simplified way to call notifications. common notifications here.
- if title == '':
- title='Icefilms Notification'
- if typeq == 'small':
- if times == '':
- times='5000'
- smallicon=handle_file('smallicon')
- xbmc.executebuiltin("XBMC.Notification("+title+","+message+","+times+","+smallicon+")")
- if typeq == 'big':
- dialog = xbmcgui.Dialog()
- dialog.ok(' '+title+' ', ' '+message+' ')
- if typeq == 'megaalert1':
- ip = xbmc.getIPAddress()
- title='Megaupload Alert for IP '+ip
- message="Either you've reached your daily download limit\n or your IP is already downloading a file."
- dialog = xbmcgui.Dialog()
- dialog.ok(' '+title+' ', ' '+message+' ')
- if typeq == 'megaalert2':
- ip = xbmc.getIPAddress()
- title='Megaupload Info for IP '+ip
- message="No problems! You have not reached your limit."
- dialog = xbmcgui.Dialog()
- dialog.ok(' '+title+' ', ' '+message+' ')
- addon = xbmcaddon.Addon(id='plugin.video.icefilms')
- #get path to me
- icepath = addon.getAddonInfo('path')
- #paths etc need sorting out. do for v1.1.0
- icedatapath = 'special://profile/addon_data/plugin.video.icefilms'
- metapath = icedatapath+'/mirror_page_meta_cache'
- downinfopath = icedatapath+'/downloadinfologs'
- transdowninfopath = xbmcpath(downinfopath,'')
- transmetapath = xbmcpath(metapath,'')
- translatedicedatapath = xbmcpath(icedatapath,'')
- art = icepath+'/resources/art'
- def handle_file(filename,getmode=''):
- #bad python code to add a get file routine.
- if filename == 'captcha':
- return_file = xbmcpath(icedatapath,'CaptchaChallenge.txt')
- elif filename == 'mirror':
- return_file = xbmcpath(icedatapath,'MirrorPageSource.txt')
- elif filename == 'episodesrc':
- return_file = xbmcpath(icedatapath,'EpisodePageSource.txt')
- elif filename == 'pageurl':
- return_file = xbmcpath(icedatapath,'PageURL.txt')
- elif filename == 'mediapath':
- return_file = xbmcpath(downinfopath,'MediaPath.txt')
- #extra thing to provide show name with year if going via episode list.
- elif filename == 'mediatvshowname':
- return_file = xbmcpath(downinfopath,'TVShowName.txt')
- #extra thing to provide season name.
- elif filename == 'mediatvseasonname':
- return_file = xbmcpath(downinfopath,'TVSeasonName.txt')
- elif filename == 'videoname':
- return_file = xbmcpath(metapath,'VideoName.txt')
- elif filename == 'sourcename':
- return_file = xbmcpath(metapath,'SourceName.txt')
- elif filename == 'description':
- return_file = xbmcpath(metapath,'Description.txt')
- elif filename == 'poster':
- return_file = xbmcpath(metapath,'Poster.txt')
- elif filename == 'mpaa':
- return_file = xbmcpath(metapath,'mpaa.txt')
- elif filename == 'listpic':
- return_file = xbmcpath(metapath,'listpic.txt')
- elif filename == 'smallicon':
- return_file = xbmcpath(art,'smalltransparent2.png')
- elif filename == 'homepage':
- return_file = xbmcpath(art,'homepage.png')
- elif filename == 'movies':
- return_file = xbmcpath(art,'movies.png')
- elif filename == 'music':
- return_file = xbmcpath(art,'music.png')
- elif filename == 'tvshows':
- return_file = xbmcpath(art,'tvshows.png')
- elif filename == 'movies_fav':
- return_file = xbmcpath(art,'movies_fav.png')
- elif filename == 'tvshows_fav':
- return_file = xbmcpath(art,'tvshows_fav.png')
- elif filename == 'other':
- return_file = xbmcpath(art,'other.png')
- elif filename == 'search':
- return_file = xbmcpath(art,'search.png')
- elif filename == 'standup':
- return_file = xbmcpath(art,'standup.png')
- elif filename == 'megapic':
- return_file = xbmcpath(art,'megaupload.png')
- elif filename == 'shared2pic':
- return_file = xbmcpath(art,'2shared.png')
- if getmode == '':
- return return_file
- if getmode == 'open':
- try:
- opened_return_file=openfile(return_file)
- return opened_return_file
- except:
- print 'opening failed'
-
- #useful global strings:
- iceurl = ICEFILMS_URL
- def openfile(filename):
- fh = open(filename, 'r')
- contents=fh.read()
- fh.close()
- return contents
- def save(filename,contents):
- fh = open(filename, 'w')
- fh.write(contents)
- fh.close()
- def appendfile(filename,contents):
- fh = open(filename, 'a')
- fh.write(contents)
- fh.close()
- def DLDirStartup(selfAddon):
- # Startup routines for handling and creating special download directory structure
- SpecialDirs=selfAddon.getSetting('use-special-structure')
- if SpecialDirs == 'true':
- mypath=str(selfAddon.getSetting('download-folder'))
- if mypath != '' or mypath is not None:
-
- if os.path.exists(mypath):
- initial_path=os.path.join(mypath,'Icefilms Downloaded Videos')
- tvpath=os.path.join(initial_path,'TV Shows')
- moviepath=os.path.join(initial_path,'Movies')
- tv_path_exists=os.path.exists(tvpath)
- movie_path_exists=os.path.exists(moviepath)
- if tv_path_exists == False or movie_path_exists == False:
- #IF BASE DIRECTORY STRUCTURE DOESN'T EXIST, CREATE IT
- #Also Add README files to TV Show and Movies direcories.
- #(readme files stops folders being deleted when running the DirCleaner)
- if tv_path_exists == False:
- os.makedirs(tvpath)
- tvreadme='Add this folder to your XBMC Library, and set it as TV to scan for metadata with TVDB.'
- tvreadmepath=os.path.join(tvpath,'README.txt')
- save(tvreadmepath,tvreadme)
- if movie_path_exists == False:
- os.makedirs(moviepath)
- moviereadme='Add this folder to your XBMC Library, and set it as Movies to scan for metadata with TheMovieDB.'
- moviereadmepath=os.path.join(moviepath,'README.txt')
- save(moviereadmepath,moviereadme)
- else:
- #IF DIRECTORIES EXIST, CLEAN DIRECTORY STRUCTURE (REMOVE EMPTY DIRECTORIES)
- cl=clean_dirs.DirCleaner()
- cl.DelEmptyFolders(tvpath)
- cl.DelEmptyFolders(moviepath)
- def LoginStartup(selfAddon):
- #Get whether user has set an account to use.
- Account = selfAddon.getSetting('megaupload-account')
- mu=megaroutines.megaupload(translatedicedatapath)
- #delete old logins
- mu.delete_login()
-
- if Account == 'false':
- print 'Account: '+'no account set'
- elif Account == 'true':
- #check for megaupload login and do it
-
- megauser = selfAddon.getSetting('megaupload-username')
- megapass = selfAddon.getSetting('megaupload-password')
- login=mu.set_login(megauser,megapass)
-
- if megapass != '' and megauser != '':
- if login is False:
- print 'Account: '+'login failed'
- Notify('big','Megaupload','Login failed. Megaupload will load with no account.','')
- elif login is True:
- print 'Account: '+'login succeeded'
- HideSuccessfulLogin = selfAddon.getSetting('hide-successful-login-messages')
- if HideSuccessfulLogin == 'false':
- Notify('small','Megaupload', 'Account login successful.','')
-
- if megapass == '' or megauser == '':
- print 'no login details specified, using no account'
- Notify('big','Megaupload','Login failed. Megaupload will load with no account.','')
-
- def ContainerStartup(selfAddon):
- #delete zips from the 'downloaded meta zips' dir that have equivalent text files.
- #have to do this at startup because it is not possible to delete the original file
- #after extracting, because the file is extracted by a built in xbmc function not python
- # (python won't wait until file has finished extracting before going on to run next lines)
- #define dl directory
- dlzips=os.path.join(translatedicedatapath,'downloaded meta zips')
-
- try:
- thefiles=os.listdir(dlzips)
- for thefile in thefiles:
- filestring=str(thefile)
- if filestring.endswith('.txt'):
- filestring=re.sub('.txt','.zip',filestring)
- os.remove(os.path.join(dlzips,filestring))
- except:
- print 'could not delete original file!'
- else:
- print 'deleted unnecessary zip.'
- metapath=os.path.join(translatedicedatapath,'meta_caches')
- #delete the meta folder if there are no covers. (cleanup failed installs)
- if os.path.exists(metapath):
- if not os.path.exists(os.path.join(metapath,'themoviedb','covers','tt0011130')):
- import shutil
- try:
- shutil.rmtree(metapath)
- except:
- print 'Failed to delete meta folder'
- return False
-
- #Quick hack for v1.0.0 --- only run if meta_caches does not exist
- if not os.path.exists(metapath):
-
- #Movie Meta Container Strings
- mv_date='9/Feb/2011'
- mv_db='http://www.megaupload.com/?d=U1RTPGQS'
- mv_base='http://www.megaupload.com/?d=CE07S1EJ'
- mv_db_base_size=230
- mv_additional=''
- mv_additional_size=0
- #TV Meta Container Strings
- tv_date=''
- tv_db=''
- tv_base=''
- tv_db_base_size=0
- tv_additional=''
- tv_additional_size=0
- #Offer to download the metadata
-
- dialog = xbmcgui.Dialog()
- ret = dialog.yesno('Download Meta Containers '+mv_date+' ?', 'There is a metadata container avaliable.','Install it to get images and info for movies.', 'Would you like to get it? Its a large '+str(mv_db_base_size)+'MB download.','Remind me later', 'Install')
- if ret==True:
-
- #download dem files
- get_db_zip=Zip_DL_and_Install(mv_db,'themoviedb','database')
- get_cover_zip=Zip_DL_and_Install(mv_base,'themoviedb','covers')
- #do nice notification
- if get_db_zip==True and get_cover_zip==True:
- Notify('small','Metacontainer Installation Success','','')
- elif get_db_zip==False or get_cover_zip==False:
- Notify('small','Metacontainer Installation Failure','','')
- def Zip_DL_and_Install(url,dbtype,installtype):
- #define dl directory
- dlzips=os.path.join(translatedicedatapath,'downloaded meta zips')
- #get the download url
- mu=megaroutines.megaupload(translatedicedatapath)
- print 'URL:',url
- thefile=mu.resolve_megaup(url)
- #define the path to save it to
- filepath=os.path.normpath(os.path.join(dlzips,thefile[1]))
-
- print 'FILEPATH: ',filepath
- filepath_exists=os.path.exists(filepath)
- #if zip does not already exist, download from url, with nice display name.
- if filepath_exists==False:
- do_wait(thefile[3])
-
- print 'downloading zip'
-
- Download(thefile[0],filepath,dbtype+' '+installtype)
- #make a text file with the same name as zip, to act as a very simple download log.
- textfile=re.sub('.zip','',thefile[1])
- textfilepath=os.path.join(dlzips,textfile+'.txt')
- save(textfilepath,' ')
-
- elif filepath_exists==True:
- print 'zip already downloaded, attempting extraction'
- print '!!!!handling meta install!!!!'
- mc=metahandlers.MetaContainer()
- install=mc.Install_Icefilms_Container(translatedicedatapath,filepath,dbtype,installtype)
- return install
- def Startup_Routines(selfAddon):
-
- # avoid error on first run if no paths exists, by creating paths
- if not os.path.exists(translatedicedatapath):
- os.makedirs(translatedicedatapath)
- if not os.path.exists(transmetapath):
- os.makedirs(transmetapath)
- if not os.path.exists(transdowninfopath):
- os.makedirs(transdowninfopath)
- dlzips=os.path.join(translatedicedatapath,'downloaded meta zips')
- if not os.path.exists(dlzips):
- os.makedirs(dlzips)
-
- #force refresh addon repositories, to check for updates.
- #xbmc.executebuiltin('UpdateAddonRepos')
-
- # Run the startup routines for special download directory structure
- DLDirStartup(selfAddon)
- # Run the login startup routines
- LoginStartup(selfAddon)
-
- # Run the container checking startup routines, if enable meta is set to true
- EnableMeta = selfAddon.getSetting('use-meta')
- if EnableMeta=='true':
- ContainerStartup(selfAddon)
- def CATEGORIES(): # (homescreen of addon)
- #get settings
- selfAddon = xbmcaddon.Addon(id='plugin.video.icefilms')
- #run startup stuff
- Startup_Routines(selfAddon)
- print 'Homescreen'
- #get necessary paths
- homepage=handle_file('homepage','')
- tvshows=handle_file('tvshows','')
- movies=handle_file('movies','')
- music=handle_file('music','')
- standup=handle_file('standup','')
- other=handle_file('other','')
- search=handle_file('search','')
- #add directories
- HideHomepage = selfAddon.getSetting('hide-homepage')
-
- addDir('TV Shows',iceurl+'tv/a-z/1',50,tvshows)
- addDir('Movies',iceurl+'movies/a-z/1',51,movies)
- addDir('Music',iceurl+'music/a-z/1',52,music)
- addDir('Stand Up Comedy',iceurl+'standup/a-z/1',53,standup)
- addDir('Other',iceurl+'other/a-z/1',54,other)
- if HideHomepage == 'false':
- addDir('Homepage',iceurl+'index',56,homepage)
- addDir('Favourites',iceurl,57,os.path.join(art,'favourites.png'))
- addDir('Search',iceurl,55,search)
- def prepare_list(directory,dircontents):
- #create new empty list
- stringList = []
- #Open all files in dir
- for thefile in dircontents:
- try:
- filecontents=openfile(os.path.join(directory,thefile))
- #add this to list
- stringList.append(filecontents)
-
- except:
- print 'problem with opening a favourites item'
- #sort list alphabetically and return it.
- tupleList = [(x.lower(), x) for x in stringList]
- tupleList.sort()
- return [x[1] for x in tupleList]
- def favRead(string):
- try:
- splitter=re.split('\|+', string)
- name=splitter[0]
- url=splitter[1]
- mode=int(splitter[2])
- try:
- imdb_id=str(splitter[3])
- except:
- imdb_id=''
- except:
- return None
- else:
- return name,url,mode,imdb_id
- def addFavourites(enablemetadata,directory,dircontents):
- #get the strings of data from the files, and return them alphabetically
- stringlist=prepare_list(directory,dircontents)
- if enablemetadata == True:
- metaget=metahandlers.MovieMetaData(translatedicedatapath)
-
- #for each string
- for thestring in stringlist:
- #split it into its component parts
- info = favRead(thestring)
- if info is not None:
- if enablemetadata == True:
- #return the metadata dictionary
- if info[3] is not None:
- meta=metaget.get_movie_meta(info[3])
-
- if meta is None:
- #add all the items without meta
- addDir(info[0],info[1],info[2],'',delfromfav=True)
- else:
- #add directories with meta
- addDir(info[0],info[1],info[2],'',metainfo=meta,delfromfav=True,imdb=info[3])
- else:
- #add all the items without meta
- addDir(info[0],info[1],info[2],'',delfromfav=True)
- else:
- #add all the items without meta
- addDir(info[0],info[1],info[2],'',delfromfav=True)
- def setView(content, viewType):
- #get settings
- selfAddon = xbmcaddon.Addon(id='plugin.video.icefilms')
- # kept for reference only
- #movies_view = selfAddon.getSetting('movies-view')
- #tvshows_view = selfAddon.getSetting('tvshows-view')
- #episodes_view = selfAddon.getSetting('episodes-view')
- # set content type so library shows more views and info
- xbmcplugin.setContent(int(sys.argv[1]), content)
- if selfAddon.getSetting('auto-view') == 'true':
- xbmc.executebuiltin("Container.SetViewMode(%s)" % selfAddon.getSetting(viewType) )
- # set sort methods - probably we don't need all of them
- xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_UNSORTED )
- xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_LABEL )
- xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_VIDEO_RATING )
- xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_DATE )
- xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_PROGRAM_COUNT )
- xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_VIDEO_RUNTIME )
- xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_GENRE )
- def FAVOURITES(url):
- #Favourites folder.
- #get necessary paths
- tvshows=handle_file('tvshows_fav','')
- movies=handle_file('movies_fav','')
- addDir('TV Shows',iceurl,570,tvshows)
- addDir('Movies',iceurl,571,movies)
- #Movie Favourites folder.
- def MOVIE_FAVOURITES(url):
- #get settings
- selfAddon = xbmcaddon.Addon(id='plugin.video.icefilms')
- favpath=os.path.join(translatedicedatapath,'Favourites')
- moviefav=os.path.join(favpath,'Movies')
- try:
- moviedircontents=os.listdir(moviefav)
- except:
- moviedircontents=None
- if moviedircontents == None:
- Notify('big','No Movie Favourites Saved','To save a favourite press the C key on a movie or\n TV Show and select Add To Icefilms Favourites','')
- else:
- #add clear favourites entry - Not sure if we must put it here, cause it will mess up the sorting
- #addExecute('* Clear Favourites Folder *',url,58,os.path.join(art,'deletefavs.png'))
- #handler for all movie favourites
- if moviedircontents is not None:
- #get the necessary meta stuff
- use_meta=os.path.exists(os.path.join(translatedicedatapath,'meta_caches'))
- meta_setting = selfAddon.getSetting('use-meta')
- #add without metadata -- imdb is still passed for use with Add to Favourites
- if use_meta==False or meta_setting=='false':
- addFavourites(False,moviefav,moviedircontents)
- #add with metadata -- imdb is still passed for use with Add to Favourites
- elif use_meta==True and meta_setting=='true':
- addFavourites(True,moviefav,moviedircontents)
- else:
- print 'moviedircontents is none!'
- # Enable library mode & set the right view for the content
- setView('movies', 'movies-view')
- #TV Shows Favourites folder
- def TV_FAVOURITES(url):
- #get settings
- selfAddon = xbmcaddon.Addon(id='plugin.video.icefilms')
- favpath=os.path.join(translatedicedatapath,'Favourites')
- tvfav=os.path.join(favpath,'TV')
- try:
- tvdircontents=os.listdir(tvfav)
- except:
- tvdircontents=None
- if tvdircontents == None:
- Notify('big','No TV Favourites Saved','To save a favourite press the C key on a movie or\n TV Show and select Add To Icefilms Favourites','')
- else:
- #add clear favourites entry - Not sure if we must put it here, cause it will mess up the sorting
- #addExecute('* Clear Favourites Folder *',url,58,os.path.join(art,'deletefavs.png'))
- #handler for all tv favourites
- if tvdircontents is not None:
- #get the necessary meta stuff
- use_meta=os.path.exists(os.path.join(translatedicedatapath,'meta_caches'))
- meta_setting = selfAddon.getSetting('use-meta')
- #add without metadata -- imdb is still passed for use with Add to Favourites
- if use_meta==False or meta_setting=='false':
- addFavourites(False,tvfav,tvdircontents)
- #add with metadata -- imdb is still passed for use with Add to Favourites
- elif use_meta==True and meta_setting=='true':
- addFavourites(True,tvfav,tvdircontents)
- else:
- print 'tvshows dircontents is none!'
- # Enable library mode & set the right view for the content
- setView('movies', 'tvshows-view')
- def URL_TYPE(url):
- #Check whether url is a tv episode list or movie/mirrorpage
- if url.startswith(iceurl+'ip'):
- print 'url is a mirror page url'
- return 'mirrors'
- elif url.startswith(iceurl+'tv/series'):
- print 'url is a tv ep list url'
- return 'episodes'
- def METAFIXER(url):
- #Icefilms urls passed to me will have their proper names and imdb numbers returned.
- source=GetURL(url)
- url_type=URL_TYPE(url)
- #get proper name from the page. (in case it is a weird name)
-
- if url_type=='mirrors':
- #get imdb number.
- match=re.compile('<a class=iframe href=http://www.imdb.com/title/(.+?)/ ').findall(source)
- #check if it is an episode.
- epcheck=re.search('<a href=/tv/series/',source)
- #if it is, return the proper series name as opposed to the mirror page name.
- if epcheck is not None:
- tvget=re.compile('<a href=/tv/series/(.+?)>').findall(source)
- tvurl=iceurl+'tv/series/'+str(tvget[0])
- #load ep page and get name from that. sorry icefilms bandwidth!
- tvsource=GetURL(tvurl)
- name=re.compile('<h1>(.+?)<a class').findall(tvsource)
- #return mirror page name.
- if epcheck is None:
- name=re.compile('''<span style="font-size:large;color:white;">(.+?)</span>''').findall(source)
-
- name=CLEANUP(name[0])
- return name,match[0]
- elif url_type=='episodes':
- #TV
- name=re.compile('<h1>(.+?)<a class').findall(source)
- match=re.compile('href="http://www.imdb.com/title/(.+?)/"').findall(source)
- name=CLEANUP(name[0])
- return name,match[0]
-
-
- def ADD_TO_FAVOURITES(name,url,imdbnum):
- #Creates a new text file in favourites folder. The text file is named after the items name, and contains the name, url and relevant mode.
- print 'Adding to favourites: name: %s, imdbnum: %s, url: %s' % (name, imdbnum, url)
- if name is not None and url is not None:
- #Set favourites path, and create it if it does'nt exist.
- favpath=os.path.join(translatedicedatapath,'Favourites')
- tvfav=os.path.join(favpath,'TV')
- moviefav=os.path.join(favpath,'Movies')
-
- try:
- os.makedirs(tvfav)
- except:
- pass
- try:
- os.makedirs(moviefav)
- except:
- pass
- #Check what kind of url it is and set themode and savepath (helpful for metadata) accordingly
-
- #fix name and imdb number for Episode List entries in Search.
- if imdbnum == 'nothing':
- metafix=METAFIXER(url)
- name=metafix[0]
- imdbnum=metafix[1]
-
- url_type=URL_TYPE(url)
- if url_type=='mirrors':
- themode='100'
- savepath=moviefav
-
- elif url_type=='episodes':
- themode='12'
- savepath=tvfav
- print 'NAME:',name,'URL:',url,'IMDB NUMBER:',imdbnum
- #encode the filename to the safe string
- adjustedname=base64.urlsafe_b64encode(name)
- #Save the new favourite if it does not exist.
- NewFavFile=os.path.join(savepath,adjustedname+'.txt')
- if not os.path.exists(NewFavFile):
- #Use | as separators that can be used by re.split when reading favourites folder.
- favcontents=name+'|'+url+'|'+themode+'|'+imdbnum
- save(NewFavFile,favcontents)
- else:
- print 'favourite already exists'
- else:
- print 'name or url is none:'
- print 'NAME: ',name
- print 'URL: ',url
-
- def DELETE_FROM_FAVOURITES(name,url):
- #encode the filename to the safe string
- name=base64.urlsafe_b64encode(name)
-
- favpath=os.path.join(translatedicedatapath,'Favourites')
- url_type=URL_TYPE(url)
- if url_type=='mirrors':
- itempath=os.path.join(favpath,'Movies',name+'.txt')
- elif url_type=='episodes':
- itempath=os.path.join(favpath,'TV',name+'.txt')
- if os.path.exists(itempath):
- os.remove(itempath)
- def CLEAR_FAVOURITES(url):
-
- dialog = xbmcgui.Dialog()
- ret = dialog.yesno('WARNING!', 'Delete all your favourites?','','','Cancel','Go Nuclear')
- if ret==True:
- import shutil
- favpath=os.path.join(translatedicedatapath,'Favourites')
- tvfav=os.path.join(favpath,'TV')
- moviefav=os.path.join(favpath,'Movies')
- try:
- shutil.rmtree(tvfav)
- except:
- pass
- try:
- shutil.rmtree(moviefav)
- except:
- pass
- def ICEHOMEPAGE(url):
- addDir('Recently Added',iceurl+'index',60,os.path.join(art,'recently added.png'))
- addDir('Latest Releases',iceurl+'index',61,os.path.join(art,'latest releases.png'))
- addDir('Being Watched Now',iceurl+'index',62,os.path.join(art,'being watched now.png'))
- #delete tv show name file
- tvshowname=handle_file('mediatvshowname','')
- try:
- os.remove(tvshowname)
- except:
- pass
- def RECENT(url):
- link=GetURL(url)
- homepage=re.compile('<h1>Recently Added</h1>(.+?)<h1>Statistics</h1>').findall(link)
- for scrape in homepage:
- scrape='<h1>Recently Added</h1>'+scrape+'<h1>Statistics</h1>'
- recadd=re.compile('<h1>Recently Added</h1>(.+?)<h1>Latest Releases</h1>').findall(scrape)
- for scraped in recadd:
- mirlinks=re.compile('<a href=(.+?)>(.+?)</a>').findall(scraped)
- for url,name in mirlinks:
- url=iceurl+url
- name=CLEANUP(name)
- addDir(name,url,100,'',disablefav=True)
-
- def LATEST(url):
- link=GetURL(url)
- homepage=re.compile('<h1>Recently Added</h1>(.+?)<h1>Statistics</h1>').findall(link)
- for scrape in homepage:
- scrape='<h1>Recently Added</h1>'+scrape+'<h1>Statistics</h1>'
- latrel=re.compile('<h1>Latest Releases</h1>(.+?)<h1>Being Watched Now</h1>').findall(scrape)
- for scraped in latrel:
- mirlinks=re.compile('<a href=(.+?)>(.+?)</a>').findall(scraped)
- for url,name in mirlinks:
- url=iceurl+url
- name=CLEANUP(name)
- addDir(name,url,100,'',disablefav=True)
- def WATCHINGNOW(url):
- link=GetURL(url)
- homepage=re.compile('<h1>Recently Added</h1>(.+?)<h1>Statistics</h1>').findall(link)
- for scrape in homepage:
- scrapy='<h1>Recently Added</h1>'+scrape+'<h1>Statistics</h1>'
- watnow=re.compile('<h1>Being Watched Now</h1>(.+?)<h1>Statistics</h1>').findall(scrapy)
- for scraped in watnow:
- mirlinks=re.compile('href=(.+?)>(.+?)</a>').findall(scraped)
- for url,name in mirlinks:
- url=iceurl+url
- name=CLEANUP(name)
- addDir(name,url,100,'',disablefav=True)
- def SEARCH(url):
- kb = xbmc.Keyboard('', 'Search Icefilms.info', False)
- kb.doModal()
- if (kb.isConfirmed()):
- search = kb.getText()
- if search != '':
- tvshowname=handle_file('mediatvshowname','')
- seasonname=handle_file('mediatvseasonname','')
- DoEpListSearch(search)
- DoSearch(search,0)
- DoSearch(search,1)
- DoSearch(search,2)
- #delete tv show name file, do the same for season name file
- try:
- os.remove(tvshowname)
- except:
- pass
- try:
- os.remove(seasonname)
- except:
- pass
-
-
- def DoSearch(search,page):
- gs = GoogleSearch('site:http://www.icefilms.info/ip '+search+'')
- gs.results_per_page = 25
- gs.page = page
- results = gs.get_results()
- for res in results:
- name=res.title.encode('utf8')
- name=CLEANSEARCH(name)
- url=res.url.encode('utf8')
- addDir(name,url,100,'')
- def DoEpListSearch(search):
- tvurl='http://www.icefilms.info/tv/series'
- # use urllib.quote_plus() on search instead of re.sub ?
- searcher=urllib.quote_plus(search)
- #searcher=re.sub(' ','+',search)
- url='http://www.google.com/search?hl=en&q=site:'+tvurl+'+'+searcher+'&btnG=Search&aq=f&aqi=&aql=&oq='
- link=GetURL(url)
- match=re.compile('<h3 class="r"><a href="'+tvurl+'(.+?)"(.+?)">(.+?)</h3>').findall(link)
-
- for myurl,interim,name in match:
- if len(interim) < 80:
- name=CLEANSEARCH(name)
- hasnameintitle=re.search(search,name,re.IGNORECASE)
- if hasnameintitle is not None:
- myurl=tvurl+myurl
- myurl=re.sub('&','',myurl)
- addDir(name,myurl,12,'')
-
- def CLEANSEARCH(name):
- name=re.sub('<em>','',name)
- name=re.sub('</em>','',name)
- name=re.sub('DivX - icefilms.info','',name)
- name=re.sub('</a>','',name)
- name=re.sub('<b>...</b>','',name)
- name=re.sub('- icefilms.info','',name)
- name=re.sub('.info','',name)
- name=re.sub('- icefilms','',name)
- name=re.sub(' -icefilms','',name)
- name=re.sub('-icefilms','',name)
- name=re.sub('icefilms','',name)
- name=re.sub('DivX','',name)
- name=re.sub('- Episode List','- Episode List',name)
- name=re.sub('-Episode List','- Episode List',name)
- #name=re.sub(''',"'",name)
- #name=re.sub('&','&',name)
- return name
- def CLEANUP(name):
- # clean names of annoying garbled text
- name=re.sub('</a>','',name)
- name=re.sub('<b>HD</b>',' *HD*',name)
- #name=re.sub('ô','o',name)
- #name=re.sub('é',"e",name)
- #name=re.sub('ë',"e",name)
- #name=re.sub('Æ','AE',name)
- #name=re.sub(''',"'",name)
- #name=re.sub('í','i',name)
- #name=re.sub('½',' 1/2',name)
- #name=re.sub('½',' 1/2',name)
- #name=re.sub('&','&',name)
- #name=re.sub('"','',name)
- return name
- def TVCATEGORIES(url):
- caturl = iceurl+'tv/'
- setmode = '11'
- addDir('A-Z Directories',caturl+'a-z/1',10,os.path.join(art,'az directories.png'))
- ADDITIONALCATS(setmode,caturl)
-
- def MOVIECATEGORIES(url):
- caturl = iceurl+'movies/'
- setmode = '2'
- addDir('A-Z Directories',caturl+'a-z/1',1,os.path.join(art,'az directories.png'))
- ADDITIONALCATS(setmode,caturl)
-
- def MUSICCATEGORIES(url):
- caturl = iceurl+'music/'
- setmode = '2'
- addDir('A-Z List',caturl+'a-z/1',setmode,os.path.join(art,'az lists.png'))
- ADDITIONALCATS(setmode,caturl)
- def STANDUPCATEGORIES(url):
- caturl = iceurl+'standup/'
- setmode = '2'
- addDir('A-Z List',caturl+'a-z/1',setmode,os.path.join(art,'az lists.png'))
- ADDITIONALCATS(setmode,caturl)
- def OTHERCATEGORIES(url):
- caturl = iceurl+'other/'
- setmode = '2'
- addDir('A-Z List',caturl+'a-z/1',setmode,os.path.join(art,'az lists.png'))
- ADDITIONALCATS(setmode,caturl)
- def ADDITIONALCATS(setmode,caturl):
- if caturl == iceurl+'movies/':
- addDir('HD 720p',caturl,63,os.path.join(art,'HD 720p.png'))
- PopRatLat(setmode,caturl,'1')
- addDir('Genres',caturl,64,os.path.join(art,'genres.png'))
- def PopRatLat(modeset,caturl,genre):
- if caturl == iceurl+'tv/':
- setmode = '11'
- elif caturl is not iceurl+'tv/':
- setmode = '2'
- addDir('Popular',caturl+'popular/'+genre,setmode,os.path.join(art,'popular.png'))
- addDir('Highly Rated',caturl+'rating/'+genre,setmode,os.path.join(art,'highly rated.png'))
- addDir('Latest Releases',caturl+'release/'+genre,setmode,os.path.join(art,'latest releases.png'))
- addDir('Recently Added',caturl+'added/'+genre,setmode,os.path.join(art,'recently added.png'))
- def HD720pCat(url):
- PopRatLat('2',url,'hd')
- def Genres(url):
- addDir('Action',url,70,'')
- addDir('Animation',url,71,'')
- addDir('Comedy',url,72,'')
- addDir('Documentary',url,73,'')
- addDir('Drama',url,74,'')
- addDir('Family',url,75,'')
- addDir('Horror',url,76,'')
- addDir('Romance',url,77,'')
- addDir('Sci-Fi',url,78,'')
- addDir('Thriller',url,79,'')
-
- def Action(url):
- PopRatLat('2',url,'action')
- def Animation(url):
- PopRatLat('2',url,'animation')
- def Comedy(url):
- PopRatLat('2',url,'comedy')
- def Documentary(url):
- PopRatLat('2',url,'documentary')
- def Drama(url):
- PopRatLat('2',url,'drama')
- def Family(url):
- PopRatLat('2',url,'family')
- def Horror(url):
- PopRatLat('2',url,'horror')
- def Romance(url):
- PopRatLat('2',url,'romance')
- def SciFi(url):
- PopRatLat('2',url,'sci-fi')
- def Thriller(url):
- PopRatLat('2',url,'thriller')
-
- def MOVIEA2ZDirectories(url):
- setmode = '2'
- caturl = iceurl+'movies/a-z/'
- #Add number directory
- addDir ('#1234',caturl+'1',setmode,os.path.join(art,'letters','1.png'))
- #Generate A-Z list and add directories for all letters.
- A2Z=[chr(i) for i in xrange(ord('A'), ord('Z')+1)]
- for theletter in A2Z:
- addDir (theletter,caturl+theletter,setmode,os.path.join(art,'letters',theletter+'.png'))
- def TVA2ZDirectories(url):
- setmode = '11'
- caturl = iceurl+'tv/a-z/'
- #Add number directory
- addDir ('#1234',caturl+'1',setmode,os.path.join(art,'letters','1.png'))
- #Generate A-Z list and add directories for all letters.
- A2Z=[chr(i) for i in xrange(ord('A'), ord('Z')+1)]
- for theletter in A2Z:
- addDir (theletter,caturl+theletter,setmode,os.path.join(art,'letters',theletter+'.png'))
-
-
- def MOVIEINDEX(url):
- #Indexer for most things. (Not just movies.)
- #get settings
- selfAddon = xbmcaddon.Addon(id='plugin.video.icefilms')
-
- # set content type so library shows more views and info
- xbmcplugin.setContent(int(sys.argv[1]), 'movies')
- meta_path=os.path.join(translatedicedatapath,'meta_caches')
- use_meta=os.path.exists(meta_path)
- meta_setting = selfAddon.getSetting('use-meta')
- link=GetURL(url)
- scrape=re.compile('<a name=i id=(.+?)></a><img class=star><a href=/(.+?)>(.+?)<br>').findall(link)
- #add without metadata -- imdb is still passed for use with Add to Favourites
- if use_meta==False or meta_setting=='false':
- for imdb_id,url,name in scrape:
- name=CLEANUP(name)
- addDir(name,iceurl+url,100,'',imdb='tt'+str(imdb_id))
-
- #add with metadata
- elif use_meta==True and meta_setting=='true':
- #initialise meta class before loop
- metaget=metahandlers.MovieMetaData(translatedicedatapath)
- for imdb_id,url,name in scrape:
- #clean name of unwanted stuff
- name=CLEANUP(name)
- url=iceurl+url
- #return the metadata dictionary
- meta=metaget.get_movie_meta(imdb_id)
- #debugs
- #print 'meta_name:'+str(name)
- #print 'meta_imdb_id:'+str(imdb_id)
- #print 'meta_video_url:'+str(url)
- #print 'meta_data:'+str(meta)
- #print 'meta_imdb_id:',meta['imdb_id']
-
- if meta is None:
- #add directories without meta
- addDir(name,url,100,'')
- else:
- #add directories with meta
- addDir(name,url,100,'',metainfo=meta,imdb='tt'+str(imdb_id))
- def TVINDEX(url):
- #Indexer for TV Shows only.
-
- link=GetURL(url)
- match=re.compile('<a name=i id=(.+?)></a><img class=star><a href=/(.+?)>(.+?)</a>').findall(link)
- for imdb_id,url,name in match:
- name=CLEANUP(name)
- addDir(name,iceurl+url,12,'')
- def TVSEASONS(url):
- # displays by seasons. pays attention to settings.
- #get settings
- selfAddon = xbmcaddon.Addon(id='plugin.video.icefilms')
- FlattenSingleSeasons = selfAddon.getSetting('flatten-single-season')
- source=GetURL(url)
- #Save the tv show name for use in special download directories.
- tvshowname=handle_file('mediatvshowname','')
- match=re.compile('<h1>(.+?)<a class').findall(source)
- save(tvshowname,match[0])
-
- ep_list = str(BeautifulSoup(source).find("span", { "class" : "list" } ))
- season_list=re.compile('<h4>(.+?)</h4>').findall(ep_list)
- listlength=len(season_list)
- for seasons in season_list:
- if FlattenSingleSeasons==True and listlength <= 1:
- #proceed straight to adding episodes.
- TVEPISODES(seasons,source=ep_list)
- else:
- #save episode page source code
- save(handle_file('episodesrc'),ep_list)
- #add season directories
- addDir(seasons,'',13,'')
- def TVEPISODES(name,url=None,source=None):
- #Save the season name for use in the special download directories.
- save(handle_file('mediatvseasonname'),name)
- #If source was'nt passed to function, open the file it should be saved to.
- if source is None:
- source = openfile(handle_file('episodesrc'))
-
- #special hack to deal with annoying re problems when recieving brackets ( )
- if re.search('\(',name) is not None:
- name = str((re.split('\(+', name))[0])
- #name=str(name[0])
- #quick hack of source code to simplfy scraping.
- source=re.sub('</span>','<h4>',source)
- #get all the source under season heading.
- #Use .+?/h4> not .+?</h4> for The Daily Show et al to work.
- match=re.compile('<h4>'+name+'.+?/h4>(.+?)<h4>').findall(source)
- for seasonSRC in match:
- TVEPLINKS(seasonSRC)
-
- def TVEPLINKS(source):
- # displays all episodes in the source it is passed.
- match=re.compile('<img class="star" /><a href="/(.+?)&">(.+?)</a>').findall(source)
- for url,name in match:
- name=CLEANUP(name)
- addDir(name,iceurl+url,100,'')
-
- def LOADMIRRORS(url):
- # This proceeds from the file page to the separate frame where the mirrors can be found,
- # then executes code to scrape the mirrors
- link=GetURL(url)
- #print link
- posterfile=handle_file('poster','')
- videonamefile=handle_file('videoname','')
- descriptionfile=handle_file('description','')
- mpaafile=handle_file('mpaa','')
- mediapathfile=handle_file('mediapath','')
-
-
- #---------------Begin phantom metadata getting--------
- #Save metadata on page to files, for use when playing.
- # Also used for creating the download directory structures.
-
- try:
- os.remove(posterurl)
- except:
- print 'posterurl does not exist'
- try:
- os.remove(mpaafile)
- except:
- print 'mpaafile does not exist'
-
- # get and save videoname
- namematch=re.compile('''<span style="font-size:large;color:white;">(.+?)</span>''').findall(link)
- save(videonamefile,namematch[0])
- # get and save description
- match2=re.compile('<th>Description:</th><td>(.+?)<').findall(link)
- try:
- save(descriptionfile,match2[0])
- except:
- pass
-
- # get and save poster link
- try:
- imgcheck1 = re.search('<img width=250 src=', link)
- imgcheck2 = re.search('/noref.php\?url=', link)
- if imgcheck1 is not None:
- match4=re.compile('<img width=250 src=(.+?) style').findall(link)
- save(posterfile,match4[0])
- if imgcheck2 is not None:
- match5=re.compile('/noref.php\?url=(.+?)>').findall(link)
- save(posterfile,match5[0])
- except:
- pass
- #get and save mpaa
- mpaacheck = re.search('MPAA Rating:', link)
- if mpaacheck is not None:
- match4=re.compile('<th>MPAA Rating:</th><td>(.+?)</td>').findall(link)
- mpaa=re.sub('Rated ','',match4[0])
- try:
- save(mpaafile,mpaa)
- except:
- pass
- ########### get and save potential file path. This is for use in download function later on.
- epcheck1 = re.search('Episodes</a>', link)
- epcheck2 = re.search('Episode</a>', link)
- if epcheck1 is not None or epcheck2 is not None:
- shownamepath=handle_file('mediatvshowname','')
- if os.path.exists(shownamepath):
- #open media file if it exists, as that has show name with date.
- showname=openfile(shownamepath)
- else:
- #fall back to scraping show name without date from the page.
- print 'USING FALLBACK SHOW NAME'
- fallbackshowname=re.compile("alt\='Show series\: (.+?)'").findall(link)
- showname=fallbackshowname[0]
- try:
- #if season name file exists
- seasonnamepath=handle_file('mediatvseasonname','')
- if os.path.exists(seasonnamepath):
- seasonname=openfile(seasonnamepath)
- save(mediapathfile,'TV Shows/'+showname+'/'+seasonname)
- else:
- save(mediapathfile,'TV Shows/'+showname)
- except:
- print "FAILED TO SAVE TV SHOW FILE PATH!"
- else:
-
- save(mediapathfile,'Movies/'+namematch[0])
- #---------------End phantom metadata getting stuff --------------
- match=re.compile('/membersonly/components/com_iceplayer/(.+?)" width=').findall(link)
- match[0]=re.sub('%29',')',match[0])
- match[0]=re.sub('%28','(',match[0])
- for url in match:
- mirrorpageurl = iceurl+'membersonly/components/com_iceplayer/'+url
- mirror_page=GetURL(mirrorpageurl, save_cookie = True)
- # check for recaptcha
- has_recaptcha = check_for_captcha(mirror_page)
- if has_recaptcha is False:
- GETMIRRORS(mirrorpageurl,mirror_page)
- elif has_recaptcha is True:
- RECAPTCHA(mirrorpageurl)
- def check_for_captcha(source):
- #check for recaptcha in the page source, and return true or false.
- has_recaptcha = re.search('recaptcha_challenge_field', source)
- if has_recaptcha is None:
- return False
- elif has_recaptcha is not None:
- return True
- def RECAPTCHA(url):
- print 'initiating recaptcha passthrough'
- link=GetURL(url)
- match=re.compile('<iframe src="http://www.google.com/recaptcha/api/noscript\?k\=(.+?)" height').findall(link)
- for token in match:
- surl = 'http://www.google.com/recaptcha/api/challenge?k=' + token
- tokenlink=GetURL(surl)
- matchy=re.compile("challenge : '(.+?)'").findall(tokenlink)
- for challenge in matchy:
- imageurl='http://www.google.com/recaptcha/api/image?c='+challenge
- captchafile=handle_file('captcha','')
- pageurlfile=handle_file('pageurl','')
- #hacky method --- save all captcha details and mirrorpageurl to file, to reopen in next step
- save(captchafile, challenge)
- save(pageurlfile, url)
- #addDir uses imageurl as url, to avoid xbmc displaying old cached image as the fresh captcha
- addDir('Enter Captcha - Type the letters',imageurl,99,imageurl)
- def CATPCHAENTER(surl):
- url=handle_file('pageurl','open')
- kb = xbmc.Keyboard('', 'Type the letters in the captcha image', False)
- kb.doModal()
- if (kb.isConfirmed()):
- userInput = kb.getText()
- if userInput != '':
- challengeToken=handle_file('captcha','open')
- print 'challenge token: '+challengeToken
- parameters = urllib.urlencode({'recaptcha_challenge_field': challengeToken, 'recaptcha_response_field': userInput})
- link=GetURL(url, params = parameters)
- has_recaptcha = check_for_captcha(link)
- if has_recaptcha is False:
- GETMIRRORS(url,link)
- elif has_recaptcha is True:
- Notify('big', 'Text does not match captcha image!', 'To try again, close this box and then: \n Press backspace twice, and reselect your video.', '')
- elif userInput == '':
- Notify('big', 'No text entered!', 'To try again, close this box and then: \n Press backspace twice, and reselect your video.', '')
- def GETMIRRORS(url,link):
- # This scrapes the megaupload mirrors from the separate url used for the video frame.
- # It also displays them in an informative fashion to user.
- # Displays in three directory levels: HD / DVDRip etc , Source, PART
- print "getting mirrors for: %s" % url
- #get settings
- selfAddon = xbmcaddon.Addon(id='plugin.video.icefilms')
-
- #hacky method -- save page source to file
- mirrorfile=handle_file('mirror','')
- save(mirrorfile, link)
- #check for the existence of categories, and set values.
- if re.search('<div class=ripdiv><b>DVDRip / Standard Def</b>', link) is not None: dvdrip = 1
- else: dvdrip = 0
-
- if re.search('<div class=ripdiv><b>HD 720p</b>', link) is not None: hd720p = 1
- else: hd720p = 0
-
- if re.search('<div class=ripdiv><b>DVD Screener</b>', link) is not None: dvdscreener = 1
- else: dvdscreener = 0
- if re.search('<div class=ripdiv><b>R5/R6 DVDRip</b>', link) is not None: r5r6 = 1
- else: r5r6 = 0
- FlattenSrcType = selfAddon.getSetting('flatten-source-type')
- #only detect and proceed directly to adding sources if flatten sources setting is true
- if FlattenSrcType == 'true':
- #add up total number of categories.
- total = dvdrip + hd720p + dvdscreener + r5r6
- #if there is only one category, skip to adding sources.
- if total == 1:
- if dvdrip == 1:
- DVDRip(url)
- elif hd720p == 1:
- …
Large files files are truncated, but you can click here to view the full file