Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 629de12cb7
...
compare: 2f77bcf2a5
Checking mergeability… Don't worry, you can still create the pull request.
  • 12 commits
  • 8 files changed
  • 0 commit comments
  • 2 contributors
View
12 lib/regexes.py 100644 → 100755
@@ -23,12 +23,12 @@
# Show.Name.S01E02.S01E03.Source.Quality.Etc-Group
# Show Name - S01E02 - S01E03 - S01E04 - Ep Name
'''
- ^(?P<series_name>.+?)[. _-]+ # Show_Name and separator
+ ^(?P<series_name>.+?)[. \[_-]+ # Show_Name and separator
s(?P<season_num>\d+)[. _-]* # S01 and optional separator
e(?P<ep_num>\d+) # E02 and separator
([. _-]+s(?P=season_num)[. _-]* # S01 and optional separator
e(?P<extra_ep_num>\d+))+ # E03/etc and separator
- [. _-]*((?P<extra_info>.+?) # Source_Quality_Etc-
+ [. \]_-]*((?P<extra_info>.+?) # Source_Quality_Etc-
((?<![. _-])-(?P<release_group>[^-]+))?)?$ # Group
'''),
@@ -36,12 +36,12 @@
# Show.Name.1x02.1x03.Source.Quality.Etc-Group
# Show Name - 1x02 - 1x03 - 1x04 - Ep Name
'''
- ^(?P<series_name>.+?)[. _-]+ # Show_Name and separator
+ ^(?P<series_name>.+?)[. \[_-]+ # Show_Name and separator
(?P<season_num>\d+)x # 1x
(?P<ep_num>\d+) # 02 and separator
([. _-]+(?P=season_num)x # 1x
(?P<extra_ep_num>\d+))+ # 03/etc and separator
- [. _-]*((?P<extra_info>.+?) # Source_Quality_Etc-
+ [. \]_-]*((?P<extra_info>.+?) # Source_Quality_Etc-
((?<![. _-])-(?P<release_group>[^-]+))?)?$ # Group
'''),
@@ -53,12 +53,12 @@
# Show Name - S01E02-03 - My Ep Name
# Show.Name.S01.E02.E03
'''
- ^((?P<series_name>.+?)[. _-]+)? # Show_Name and separator
+ ^((?P<series_name>.+?)[. \[_-]+)? # Show_Name and separator
s(?P<season_num>\d+)[. _-]* # S01 and optional separator
e(?P<ep_num>\d+) # E02 and separator
(([. _-]*e|-) # linking e/- char
(?P<extra_ep_num>(?!(1080|720)[pi])\d+))* # additional E03/etc
- [. _-]*((?P<extra_info>.+?) # Source_Quality_Etc-
+ [. \]_-]*((?P<extra_info>.+?) # Source_Quality_Etc-
((?<![. _-])-(?P<release_group>[^-]+))?)?$ # Group
'''),
View
62 pchtrakt.py
@@ -48,6 +48,8 @@
from urllib2 import Request, urlopen, URLError, HTTPError
from urllib import quote
+class PchTraktException(Exception):
+ pass
tvdb = tvdb_api.Tvdb()
@@ -63,14 +65,14 @@ def __str__(self):
self.parsedInfo.episode_numbers,
self.oStatus.percent,
self.oStatus.status,
- tvdb[self.parsedInfo.name]['id'])
+ self.parsedInfo.id)
else:
msg = 'Movie : {0} - Year : {1} - ' \
'{2}% - IMDB: {3}'.format(
self.parsedInfo.name,
self.parsedInfo.year,
self.oStatus.percent,
- self.id)
+ self.parsedInfo.id)
return msg
myMedia = media()
@@ -151,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:
@@ -167,44 +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}&y={1}&r=xml'.format(
- quote(myMedia.parsedInfo.name),
- myMedia.parsedInfo.year))
- # ImdbAPIurl = ('http://www.deanclatworthy.com/imdb/?q={0}&year={1}&type=xml'.format(
- # quote(myMedia.parsedInfo.name),
- # myMedia.parsedInfo.year))
- oResponse = urlopen(ImdbAPIurl)
- oXml = ElementTree.XML(oResponse.read())
- myMedia.id = oXml.find('movie').get('id')
- # myMedia.id = oXml.find('imdbid').text
- 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
@@ -258,19 +227,29 @@ def stopTrying():
'{0} :::'.format(pchtrakt.lastPath))
Debug(msg)
pchtrakt.logger.warning(msg)
+ sleep(sleepTime)
except utils.AuthenticationTraktError as e:
stopTrying()
Debug(':::{0}::'.format(e))
pchtrakt.logger.error(e)
+ sleep(sleepTime)
except utils.MaxScrobbleError as e:
stopTrying()
Debug(':::{0}:::'.format(e))
pchtrakt.logger.error(e)
+ sleep(sleepTime)
except MovieResultNotFound as e:
stopTrying()
msg = ':::Movie not found - {0}:::'.format(e.file_name)
Debug(msg)
pchtrakt.logger.error(msg)
+ sleep(sleepTime)
+ except PchTraktException as e:
+ stopTrying()
+ msg = ':::PchTraktException - {0}:::'.format(e)
+ Debug(msg)
+ pchtrakt.logger.error(msg)
+ sleep(sleepTime)
except Exception as e:
stopTrying()
Debug('::: {0} :::'.format(pchtrakt.lastPath))
@@ -278,4 +257,5 @@ def stopTrying():
pchtrakt.logger.exception('This should never happend! Please contact me with the error if you read this')
pchtrakt.logger.exception(pchtrakt.lastPath)
pchtrakt.logger.exception(e)
+ sleep(sleepTime)
pchtrakt.logger.info('Pchtrakt STOP')
View
8 pchtrakt/config.py
@@ -18,6 +18,11 @@
# along with pchtrakt. If not, see <http://www.gnu.org/licenses/>.
import ConfigParser
import pchtrakt
+import socket
+s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+s.connect(("gmail.com",80))
+myIp = s.getsockname()[0]
+s.close()
config = ConfigParser.RawConfigParser()
@@ -26,7 +31,8 @@
ipPch = config.get('PCHtrakt', 'pch_ip')
sleepTime = float(config.get('PCHtrakt', 'sleep_time'))
ignored_repertory = [x.strip() for x in config.get('PCHtrakt', 'ignored_repertory').split(',')]
-OnPCH = (ipPch == '127.0.0.1')
+
+OnPCH = (ipPch in ['127.0.0.1',myIp])
#Trakt
TraktUsername = config.get('Trakt', 'login')
View
49 pchtrakt/mediaparser.py
@@ -17,6 +17,10 @@
# 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
@@ -24,11 +28,6 @@
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):
@@ -36,13 +35,50 @@ def __init__(self,file_name,name,season_number,episode_numbers):
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):
@@ -54,7 +90,6 @@ def __init__(self):
self.MovieParser = MovieParser()
def parse(self, file_name):
- #TODO(achtus): try to detect tv show with 00x00 or 0x00 or s00e00 or s0e0 or s0e00
try:
parsedResult = self.TVShowParser.parse(file_name)
oResultTVShow = MediaParserResultTVShow(file_name,parsedResult.series_name,parsedResult.season_number,parsedResult.episode_numbers)
View
11 pchtrakt/movieparser.py
@@ -22,13 +22,6 @@
import mediaparser
regexes_movies = [
- ("imdbid", # not works
- # foobar.[ID ttxxxxxx]
- """
- ^[\[]ID[ ](?P<imdbid>.+?[.])[\]]
- """
- )
- ,
("movie_year", # bug sometimes 1080 = year
# Movie.Title.(year) or Movie.Title.[year]
"""
@@ -36,6 +29,8 @@
[\(\[]{0,1}(?P<year>[0-9]{4})[\)\]]{0,1}
"""
)
+ ,
+ ("movie_only", "^(?P<movie_title>.+).[A-Za-z]{3,4}$")
]
class MovieParser():
@@ -63,7 +58,7 @@ def parse(self,file_name):
tmp_year = None
tmp_imdbid = None
named_groups = match.groupdict().keys()
-
+
if 'movie_title' in named_groups:
tmp_movie_title = self.clean_movie_name(match.group('movie_title'))
View
60 pchtrakt/scrobble.py
@@ -20,39 +20,61 @@ class EnumScrobbleResult:
def showStarted(myMedia):
if TraktScrobbleTvShow:
- responce = utilities.watchingEpisodeOnTrakt(myMedia.id,
+ response = utilities.watchingEpisodeOnTrakt(myMedia.parsedInfo.id,
myMedia.parsedInfo.name,
- myMedia.year,
+ myMedia.parsedInfo.year,
str(myMedia.parsedInfo.season_number),
str(myMedia.parsedInfo.episode_numbers[myMedia.idxEpisode]),
str(myMedia.oStatus.totalTime),
str(myMedia.oStatus.percent))
- msg = 'Video playing: %s - %s' %(responce['status'],responce['message'])
+ msg = 'Sending play: {0} {1} {2} {3}' \
+ ' {4} {5} {6}'.format(myMedia.parsedInfo.id,
+ myMedia.parsedInfo.name,
+ myMedia.parsedInfo.year,
+ str(myMedia.parsedInfo.season_number),
+ str(myMedia.parsedInfo.episode_numbers[myMedia.idxEpisode]),
+ str(myMedia.oStatus.totalTime),
+ str(myMedia.oStatus.percent))
+ Debug(msg)
+ pchtrakt.logger.info(msg)
+ if response != None:
+ msg = 'Video playing: %s - %s' %(response['status'],response['message'])
+
+ else:
+ msg = 'No response from Trakt.tv'
Debug(msg)
pchtrakt.logger.info(msg)
-
def movieStarted(myMedia):
- responce = utilities.watchingMovieOnTrakt(myMedia.id,
+ response = utilities.watchingMovieOnTrakt(myMedia.parsedInfo.id,
myMedia.parsedInfo.name,
- myMedia.year,
+ myMedia.parsedInfo.year,
str(myMedia.oStatus.totalTime),
str(myMedia.oStatus.percent))
- msg = 'Video playing: %s - %s' %(responce['status'],responce['message'])
+ if response != None:
+ msg = 'Video playing: %s - %s' %(response['status'],response['message'])
+ else:
+ msg = 'No response from Trakt.tv'
Debug(msg)
pchtrakt.logger.info(msg)
def showStopped():
- responce = utilities.cancelWatchingEpisodeOnTrakt()
- msg = 'Video stopped: %s - %s' %(responce['status'],responce['message'])
+ response = utilities.cancelWatchingEpisodeOnTrakt()
+ if response != None:
+ msg = 'Video stopped: %s - %s' %(response['status'],response['message'])
+ else:
+ msg = 'No response from Trakt.tv'
Debug(msg)
pchtrakt.logger.info(msg)
def movieStopped():
- responce = utilities.cancelWatchingMovieOnTrakt()
- msg = 'Video stopped: %s - %s' %(responce['status'],responce['message'])
+ response = utilities.cancelWatchingMovieOnTrakt()
+ if response != None:
+ msg = 'Video stopped: %s - %s' %(response['status'],response['message'])
+ else:
+ msg = 'No response from Trakt.tv'
Debug(msg)
pchtrakt.logger.info(msg)
@@ -110,15 +132,15 @@ def showIsEnding(myMedia):
pchtrakt.logger.info(e)
if TraktScrobbleTvShow:
result = 0
- responce = utilities.scrobbleEpisodeOnTrakt(myMedia.id,
+ response = utilities.scrobbleEpisodeOnTrakt(myMedia.parsedInfo.id,
myMedia.parsedInfo.name,
- myMedia.year,
+ myMedia.parsedInfo.year,
str(myMedia.parsedInfo.season_number),
str(myMedia.parsedInfo.episode_numbers[myMedia.idxEpisode]),
str(myMedia.oStatus.totalTime),
str(myMedia.oStatus.percent))
- if responce:
- msg = '(Trakt) Video is ending: %s - %s ' %(responce['status'],responce['message'])
+ if response:
+ msg = '(Trakt) Video is ending: %s - %s ' %(response['status'],response['message'])
Debug(msg)
pchtrakt.logger.info(msg)
result = 1
@@ -131,13 +153,13 @@ def showIsEnding(myMedia):
def movieIsEnding(myMedia):
- responce = utilities.scrobbleMovieOnTrakt(myMedia.id,
+ response = utilities.scrobbleMovieOnTrakt(myMedia.parsedInfo.id,
myMedia.parsedInfo.name,
- myMedia.year,
+ myMedia.parsedInfo.year,
str(myMedia.oStatus.totalTime),
str(myMedia.oStatus.percent))
- if responce != None:
- msg = 'Video is ending: %s - %s ' %(responce['status'],responce['message'])
+ if response != None:
+ msg = 'Video is ending: %s - %s ' %(response['status'],response['message'])
Debug(msg)
pchtrakt.logger.info(msg)
return 1
View
2  scripts_install/appinfo.json
@@ -1,7 +1,7 @@
{
appinfo_format = "1",
name = "pchtrakt",
- version = "0.4.12",
+ version = "0.4.17",
enabled = "1",
daemon_script = "daemon.sh",
crontab="0 */2 * * * pyhton #PATH#/update.py"
View
BIN  scripts_install/pchtrakt.zip
Binary file not shown

No commit comments for this range

Something went wrong with that request. Please try again.