Skip to content
Browse files

2 different site for movies

  • Loading branch information...
1 parent aa093c4 commit 6e509ac6b980a7ad1bfca595b5e9d3a25e8ea90c @jlauwers jlauwers committed May 3, 2012
Showing with 48 additions and 58 deletions.
  1. +6 −52 pchtrakt.py
  2. +42 −6 pchtrakt/mediaparser.py
View
58 pchtrakt.py
@@ -153,7 +153,7 @@ def doWork():
myMedia.oStatus = pchtrakt.oPchRequestor.getStatus(ipPch, 5)
if pchtrakt.lastPath != myMedia.oStatus.fullPath:
pchtrakt.StopTrying = 0
- myMedia.id = None
+ myMedia.parsedInfo = None
with open('cache.json','w') as f:
json.dump(pchtrakt.dictSerie, f, separators=(',',':'), indent=4)
if YamjWatched == True:
@@ -169,57 +169,11 @@ def doWork():
EnumStatus.PAUSE]:
pchtrakt.allowedPauseTime = TraktMaxPauseTime
if myMedia.oStatus.status != EnumStatus.LOAD:
- myMedia.parsedInfo = pchtrakt.mediaparser.parse(
- myMedia.oStatus.fileName)
- if isinstance(myMedia.parsedInfo, mp.MediaParserResultTVShow):
- if myMedia.id == None:
- if myMedia.parsedInfo.season_number == 0:
- raise BaseException('No season - maybe anime?')
- if not myMedia.parsedInfo.name in pchtrakt.dictSerie:
- Debug('Added to cache!')
- myMedia.id = tvdb[myMedia.parsedInfo.name]['id']
- year = tvdb[myMedia.parsedInfo.name]['firstaired']
- myMedia.year = ''
- if year != None:
- myMedia.year = (year.split('-')[0])
- pchtrakt.dictSerie[myMedia.parsedInfo.name]={'Year':myMedia.year,
- 'TvDbId':myMedia.id,
- 'Betaseries':''}
- else:
- Debug('Cached!')
- myMedia.id = pchtrakt.dictSerie[myMedia.parsedInfo.name]['TvDbId']
- myMedia.year = pchtrakt.dictSerie[myMedia.parsedInfo.name]['Year']
-
- Debug(myMedia)
- videoStatusHandle(myMedia)
- elif isinstance(myMedia.parsedInfo, mp.MediaParserResultMovie):
- if myMedia.id == None:
- ImdbAPIurl = ('http://www.imdbapi.com/?t={0}&r=xml'.format(
- quote(myMedia.parsedInfo.name)))
- if myMedia.parsedInfo.year != None:
- print 'ok01'
- ImdbAPIurl = ImdbAPIurl + '&y={0}'.format(myMedia.parsedInfo.year)
- else:
- print 'ok2'
- # try to read NFO?
- if os.path.exists(myMedia.oStatus.fullPath):
- print 'ok'
- f = open('', 'r')
- oXml = ElementTree.XML()
-
- oResponse = urlopen(ImdbAPIurl)
- try:
- oXml = ElementTree.XML(oResponse.read())
- except sys.exc_type as e:
- raise PchTraktException('Can\'t parse response: {0}'.format(ImdbAPIurl))
-
- if oXml.find('movie') == None:
- raise PchTraktException('Can\'t find the movie ID on: {0}'.format(ImdbAPIurl))
- else:
- myMedia.id = oXml.find('movie').get('id')
- myMedia.year = myMedia.parsedInfo.year
- Debug(myMedia)
- videoStatusHandle(myMedia)
+ if myMedia.parsedInfo == None:
+ myMedia.parsedInfo = pchtrakt.mediaparser.parse(
+ myMedia.oStatus.fileName)
+ Debug(myMedia)
+ videoStatusHandle(myMedia)
elif (myMedia.oStatus.status == EnumStatus.PAUSE
and pchtrakt.allowedPauseTime > 0):
pchtrakt.allowedPauseTime -= sleepTime
View
48 pchtrakt/mediaparser.py
@@ -17,32 +17,68 @@
# You should have received a copy of the GNU General Public License
# along with pchtrakt. If not, see <http://www.gnu.org/licenses/>.
+from os.path import basename, isfile
+from urllib import quote
+from urllib2 import urlopen, HTTPError
+import json
from lib import parser
from movieparser import *
from lib.tvdb_api import tvdb_exceptions
class MediaParserResult():
def __init__(self,file_name):
self.file_name = file_name
-class MediaParserResultAnime(MediaParserResult):
- def __init__(self,file_name,name,episode_numbers):
- self.file_name = file_name
- self.name = name
- self.episode_numbers = episode_numbers
class MediaParserResultTVShow(MediaParserResult):
def __init__(self,file_name,name,season_number,episode_numbers):
self.file_name = file_name
self.name = name
self.season_number = season_number
self.episode_numbers = episode_numbers
+ if self.name in cacheSerie.dictSerie:
+ self.id = cacheSerie.dictSerie[self.name]['TvDbId']
+ self.year = cacheSerie.dictSerie[self.name]['Year']
+ else:
+ self.id = tvdb[self.name]['id']
+ if tvdb[self.name]['firstaired'] != None:
+ self.year = tvdb[self.name]['firstaired'].split('-')[0]
+ else:
+ self.year = None
+ cacheSerie.dictSerie[self.name]={'Year':self.year,
+ 'TvDbId':self.id}
+
+ with open('cache.json','w') as f:
+ json.dump(cacheSerie.dictSerie, f, separators=(',',':'), indent=4)
class MediaParserResultMovie(MediaParserResult):
def __init__(self,file_name,name,year,imdbid):
self.file_name = file_name
self.name = name
self.year = year
- self.imdbid = imdbid
+
+ ImdbAPIurl = ('http://www.imdbapi.com/?t={0}&y={1}'.format(
+ quote(self.name),
+ self.year))
+
+ try:
+ oResponse = urlopen(ImdbAPIurl,None,5)
+ myMovieJson = json.loads(oResponse.read())
+ self.id = myMovieJson['ID']
+ except HTTPError as e:
+ ImdbAPIurl = ('http://www.deanclatworthy.com/' \
+ 'imdb/?q={0}&year={1}'.format(
+ quote(self.name),
+ self.year))
+
+ try:
+ oResponse = urlopen(ImdbAPIurl,None,5)
+ myMovieJson = json.loads(oResponse.read())
+ self.id = myMovieJson['imdbid']
+ except HTTPError as e:
+ pass
+ # except Exception as e:
+ # Debug(e)
+ # pass
class MediaParserUnableToParse(Exception):
def __init__(self, file_name):

0 comments on commit 6e509ac

Please sign in to comment.
Something went wrong with that request. Please try again.