From 7388bed370e4f5a5621a743607b8b653d92d2ccf Mon Sep 17 00:00:00 2001 From: Ratan Sunder Parai Date: Thu, 12 Nov 2015 08:07:02 +0600 Subject: [PATCH] make adjustment to .gitignore to upload lib files --- .gitignore | 1 - resources/lib/__init__.py | 1 + resources/lib/cinehub.py | 184 +++++++++++++++++++++++++++++++++++ resources/lib/movieinfo.py | 38 ++++++++ resources/lib/tmdbscraper.py | 137 ++++++++++++++++++++++++++ 5 files changed, 360 insertions(+), 1 deletion(-) create mode 100644 resources/lib/__init__.py create mode 100644 resources/lib/cinehub.py create mode 100644 resources/lib/movieinfo.py create mode 100644 resources/lib/tmdbscraper.py diff --git a/.gitignore b/.gitignore index ba74660..7bade20 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,6 @@ dist/ downloads/ eggs/ .eggs/ -lib/ lib64/ parts/ sdist/ diff --git a/resources/lib/__init__.py b/resources/lib/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/resources/lib/__init__.py @@ -0,0 +1 @@ + diff --git a/resources/lib/cinehub.py b/resources/lib/cinehub.py new file mode 100644 index 0000000..c5ccf44 --- /dev/null +++ b/resources/lib/cinehub.py @@ -0,0 +1,184 @@ +# -*- coding: utf-8 -*- + +''' + Genesis Add-on + Copyright (C) 2015 Ratan Sunder Parai + + 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 3 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, see . +''' + +from urllib import urlopen +from BeautifulSoup import BeautifulSoup +import requests +from movieinfo import movieinfo +from tmdbscraper import tmdbscraper +import xbmcaddon +import urllib +import base64 + +class cinehub: + + # Perform login task and return request.session() object + def login(self): + + # Login url + loginUrl = "http://www.cinehub24.com/auth/login" + + myAddon = xbmcaddon.Addon() + + + USERNAME = myAddon.getSetting("user_name") + PASSWORD = myAddon.getSetting("user_password") + + + + if USERNAME == "" or PASSWORD == "" : + myAddon.openSettings() + + session_requests = requests.session() + + # Create payload + payload = { + "user_name": USERNAME, + "user_password": PASSWORD, + 'doLogin' : 'true', + 'submit' : 'Login' + } + + # Perform login + result = session_requests.post(loginUrl, data = payload, headers = dict(referer = loginUrl)) + + # check if login successfull + # TODO + + return session_requests + + def getAllMovieList(self, session, page=1): + URL = "http://www.cinehub24.com/net/section/english-movie/onlineContent.aspx/" + str(page) + return self.getMovieList(session, URL, page) + + + def getMovieList(self, session, URL, page = 1 ): + # url for all movie list + #URL = "http://www.cinehub24.com/net/section/english-movie/onlineContent.aspx/" + str(page) + + # get the html + result = session.get(URL).content + + # make it ready for scraping + soup = BeautifulSoup(result) + + # get movie list box + movieBoxs = soup.findAll('div', attrs={'class': ['movie-list-hldr' , 'movie-list-hldr movielist-active']}) + + + + movielist = [] + + for movieBox in movieBoxs: + # movie link + movieLink = movieBox.find('div', attrs={'class' : 'movie-list-des'}).find('a') + #print movieLink['href'] + + # get real movie links + links = movieLink['href'] + + minfo = movieinfo() + + minfo.url = self.getVideoLink(session, links) + + #self.getVideoLink(session, links) + + if minfo.url : + + #movie title + movieTitle = movieLink.find('b') + #print movieTitle.string + minfo.name = movieTitle.string + + movielist.append(minfo) + + + return movielist + + def getVideoLink(self, session, URL): + + # get html file + result = session.get(URL).content + + # create soup for scrapping + soup = BeautifulSoup(result) + + linkTable = soup.find('table', attrs={'id': 'travel'}) + + tdId = 1 + for i in range(1,5): + try: + tempName = linkTable.find('tbody').findAll('td')[tdId].find('b').string + #print tempName + + # video file format mp4, avi and mkv and not containing sample + if tempName.find('.mp4') != -1 or tempName.find('.avi') != -1 or tempName.find('.mkv') != -1 : + if tempName.lower().find("sample") != -1 or tempName.lower().find("trailer") != -1 : + pass + else: + tempVideoLink = linkTable.find('tbody').findAll('td')[tdId+3].find('a')['href'] + result = session.get(tempVideoLink).content + soup = BeautifulSoup(result) + link = soup.find('div', attrs={'id': 'download_btn_r'}).find('a')['href'] + return link.strip() + else: + tdId += 5 + except: + break + + + def getMyMovieInfoList(self, page = 1): + session = self.login() + mymovieinfos = self.getAllMovieList(session, page) + + movieList = [] + + print "getting mymovieinfo..." + for mymovieinfo in mymovieinfos: + tScrap = tmdbscraper() + mymovieinfo = tScrap.getMovieInfo(mymovieinfo) + + if mymovieinfo.imdbid: + movieList.append(mymovieinfo) + print mymovieinfo.title + + return movieList + + def searchMovies(self, searchTerm): + searchTerm = searchTerm.strip() + searchTerm = searchTerm.replace(" ", "+") + URL = "http://www.cinehub24.com/search/{0}.aspx".format(searchTerm) + + session = self.login() + mymovieinfos = self.getMovieList(session, URL, 1) + + movieList = [] + for mymovieinfo in mymovieinfos: + tScrap = tmdbscraper() + mymovieinfo = tScrap.getMovieInfo(mymovieinfo) + try: + if mymovieinfo.imdbid: + movieList.append(mymovieinfo) + print mymovieinfo.title + except: + pass + return movieList + + diff --git a/resources/lib/movieinfo.py b/resources/lib/movieinfo.py new file mode 100644 index 0000000..d5fada4 --- /dev/null +++ b/resources/lib/movieinfo.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- + +''' + Genesis Add-on + Copyright (C) 2015 Ratan Sunder Parai + + 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 3 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, see . +''' + +class movieinfo: + name = '' + url = '' + title = '' + imdbid = '' + genres = '' + rating = '' + runtime = '' + tagline = '' + totalVote = '' + releaseDate = '' + overview = '' + posterImage = '' + backdropImage = '' + year = '' + writer = '' + director = '' + castandrole = [] \ No newline at end of file diff --git a/resources/lib/tmdbscraper.py b/resources/lib/tmdbscraper.py new file mode 100644 index 0000000..b69ca3e --- /dev/null +++ b/resources/lib/tmdbscraper.py @@ -0,0 +1,137 @@ +# -*- coding: utf-8 -*- + +''' + Genesis Add-on + Copyright (C) 2015 Ratan Sunder Parai + + 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 3 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, see . +''' + +from urllib import urlopen +import json +from movieinfo import movieinfo +import re +import urllib +import base64 + + +class tmdbscraper: + + API = base64.urlsafe_b64decode("N2U5MTYyMjM1NWFjZjI3NDM3ODQzNjcyMzRlOTFhODU=") + + def searchMovie(self, name, year=""): + URL = "http://api.themoviedb.org/3/search/movie?api_key="+self.API+"&query=" + urllib.quote_plus(name) + "&year=" + str(year) + result = urlopen(URL) + moviejson = json.load(result) + + if moviejson['total_results'] == 0 : + return 0 + + return moviejson['results'][0]['id'] + + def getMovieInfo(self, myMovieInfo): + name = myMovieInfo.name + + # delete first bracket ( from name + name = name.replace("(", "") + name = name.replace(")", "") + name = name.replace("[", "") + name = name.replace("]", "") + name = name.replace(".", " ") + name = name.replace("_", " ") + name = name.replace("{", "") + name = name.replace("}", "") + + mgroup = re.split('[0-9]{4}', name) + + if mgroup : + searchName = mgroup[0].strip() + else: + searchName = name + + m = re.search('[0-9]{4}', name) + if m: + searchYear = m.group(0) + else: + searchYear = "" + + # invoke search + movieId = self.searchMovie(searchName, searchYear) + + print "tmdbid : " + str(movieId) + + if movieId == 0 : + return myMovieInfo + + DETAIL_URL = "http://api.themoviedb.org/3/movie/"+ str(movieId) +"?api_key="+self.API + + CREDIT_URL = "http://api.themoviedb.org/3/movie/"+ str(movieId) + "/credits?api_key="+ self.API + + result = urlopen(DETAIL_URL) + mJson = json.load(result) + + creditResult = urlopen(CREDIT_URL) + cJson = json.load(creditResult) + + # encode strings to "utf-8" becuase kodi give error while showing unicode character + myMovieInfo.title = mJson['title'].encode('utf-8') + print "title = " + myMovieInfo.title + myMovieInfo.imdbid = mJson['imdb_id'].encode('utf-8') + myMovieInfo.totalVote = mJson['vote_average'] #rating + myMovieInfo.rating = mJson['vote_count'] + myMovieInfo.overview = mJson['overview'].encode('utf-8') + myMovieInfo.runtime = mJson['runtime'] * 60 + myMovieInfo.tagline = mJson['tagline'].encode('utf-8') #short description + myMovieInfo.releaseDate = mJson['release_date'].encode('utf-8') + tYear = mJson['release_date'].encode('utf-8') + myMovieInfo.year = tYear[0:4] + + gList = [] + for genre in mJson['genres'] : + gList.append(genre['name'].encode('utf-8')) + + genres = ' / '.join(gList) + + myMovieInfo.genres = genres + + try: + myMovieInfo.posterImage = "https://image.tmdb.org/t/p/w396" + mJson['poster_path'] + except: + pass + try: + myMovieInfo.backdropImage = "https://image.tmdb.org/t/p/w780" + mJson['backdrop_path'] + except: + pass + + try: + myMovieInfo.director = cJson['crew'][0]['name'] + myMovieInfo.writer = cJson['crew'][1]['name'] + except: + pass + + listCast = cJson['cast'] + + castName = [] + castChar = [] + for cast in listCast: + name = cast['name'] + castName.append(name) + character = cast['character'] + castChar.append(character) + + myMovieInfo.castandrole = zip(castName, castChar) + + return myMovieInfo + + \ No newline at end of file