Avoid to use torrent files from TEMP directory.
parent
f4c76b1ebf
commit
16c344f029
|
@ -182,39 +182,39 @@ class AnteoLoader:
|
||||||
return filelist
|
return filelist
|
||||||
|
|
||||||
def saveTorrent(self, torrentUrl):
|
def saveTorrent(self, torrentUrl):
|
||||||
if not xbmcvfs.exists(torrentUrl) or re.match("^http.+$", torrentUrl):
|
#if not xbmcvfs.exists(torrentUrl) or re.match("^http.+$", torrentUrl):
|
||||||
if re.match("^magnet\:.+$", torrentUrl):
|
if re.match("^magnet\:.+$", torrentUrl):
|
||||||
self.magnetLink = torrentUrl
|
self.magnetLink = torrentUrl
|
||||||
self.magnetToTorrent(torrentUrl)
|
self.magnetToTorrent(torrentUrl)
|
||||||
self.magnetLink = None
|
self.magnetLink = None
|
||||||
return self.torrentFile
|
return self.torrentFile
|
||||||
else:
|
|
||||||
if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath)
|
|
||||||
torrentFile = os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent')
|
|
||||||
try:
|
|
||||||
if not re.match("^http\:.+$", torrentUrl):
|
|
||||||
content = xbmcvfs.File(torrentUrl, "rb").read()
|
|
||||||
else:
|
|
||||||
request = urllib2.Request(torrentUrl)
|
|
||||||
request.add_header('Referer', torrentUrl)
|
|
||||||
request.add_header('Accept-encoding', 'gzip')
|
|
||||||
result = urllib2.urlopen(request)
|
|
||||||
if result.info().get('Content-Encoding') == 'gzip':
|
|
||||||
buf = StringIO(result.read())
|
|
||||||
f = gzip.GzipFile(fileobj=buf)
|
|
||||||
content = f.read()
|
|
||||||
else:
|
|
||||||
content = result.read()
|
|
||||||
|
|
||||||
localFile = xbmcvfs.File(torrentFile, "w+b")
|
|
||||||
localFile.write(content)
|
|
||||||
localFile.close()
|
|
||||||
except Exception, e:
|
|
||||||
print 'Unable to save torrent file from "' + torrentUrl + '" to "' + torrentFile + '" in Torrent::saveTorrent' + '. Exception: ' + str(
|
|
||||||
e)
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
torrentFile = torrentUrl
|
if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath)
|
||||||
|
torrentFile = os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent')
|
||||||
|
try:
|
||||||
|
if not re.match("^http\:.+$", torrentUrl):
|
||||||
|
content = xbmcvfs.File(torrentUrl, "rb").read()
|
||||||
|
else:
|
||||||
|
request = urllib2.Request(torrentUrl)
|
||||||
|
request.add_header('Referer', torrentUrl)
|
||||||
|
request.add_header('Accept-encoding', 'gzip')
|
||||||
|
result = urllib2.urlopen(request)
|
||||||
|
if result.info().get('Content-Encoding') == 'gzip':
|
||||||
|
buf = StringIO(result.read())
|
||||||
|
f = gzip.GzipFile(fileobj=buf)
|
||||||
|
content = f.read()
|
||||||
|
else:
|
||||||
|
content = result.read()
|
||||||
|
|
||||||
|
localFile = xbmcvfs.File(torrentFile, "w+b")
|
||||||
|
localFile.write(content)
|
||||||
|
localFile.close()
|
||||||
|
except Exception, e:
|
||||||
|
log('Unable to rename torrent file from %s to %s in AnteoLoader::saveTorrent. Exception: %s' %
|
||||||
|
(torrentUrl, torrentFile, str(e)))
|
||||||
|
return
|
||||||
|
#else:
|
||||||
|
#torrentFile = torrentUrl
|
||||||
if xbmcvfs.exists(torrentFile) and not os.path.exists(torrentFile):
|
if xbmcvfs.exists(torrentFile) and not os.path.exists(torrentFile):
|
||||||
if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath)
|
if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath)
|
||||||
torrentFile = os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent')
|
torrentFile = os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent')
|
||||||
|
@ -239,7 +239,7 @@ class AnteoLoader:
|
||||||
self.torrentFile = torrent.torrentFile
|
self.torrentFile = torrent.torrentFile
|
||||||
except:
|
except:
|
||||||
self.torrentFile = magnet
|
self.torrentFile = magnet
|
||||||
log('[AnteoLoader][magnetToTorrent]: self.torrentFile '+str(self.torrentFile))
|
log('['+author+'Loader][magnetToTorrent]: self.torrentFile '+str(self.torrentFile))
|
||||||
|
|
||||||
class AnteoPlayer(xbmc.Player):
|
class AnteoPlayer(xbmc.Player):
|
||||||
__plugin__ = sys.modules["__main__"].__plugin__
|
__plugin__ = sys.modules["__main__"].__plugin__
|
||||||
|
@ -278,15 +278,15 @@ class AnteoPlayer(xbmc.Player):
|
||||||
self.setup_nextep()
|
self.setup_nextep()
|
||||||
while True:
|
while True:
|
||||||
if self.buffer():
|
if self.buffer():
|
||||||
log('[AnteoPlayer]: ************************************* GOING LOOP')
|
log('['+author+'Player]: ************************************* GOING LOOP')
|
||||||
if self.setup_play():
|
if self.setup_play():
|
||||||
self.setup_subs()
|
self.setup_subs()
|
||||||
self.loop()
|
self.loop()
|
||||||
WatchedHistoryDB().add(self.basename, foldername(self.getContentList()[self.contentId]['title']), self.watchedTime, self.totalTime, self.contentId, self.fullSize)
|
WatchedHistoryDB().add(self.basename, foldername(self.getContentList()[self.contentId]['title']), self.watchedTime, self.totalTime, self.contentId, self.fullSize)
|
||||||
else:
|
else:
|
||||||
log('[AnteoPlayer]: ************************************* break')
|
log('['+author+'Player]: ************************************* break')
|
||||||
break
|
break
|
||||||
log('[AnteoPlayer]: ************************************* GO NEXT?')
|
log('['+author+'Player]: ************************************* GO NEXT?')
|
||||||
if self.next_dl and self.next_contentId != False and isinstance(self.next_contentId, int) and self.iterator == 100:
|
if self.next_dl and self.next_contentId != False and isinstance(self.next_contentId, int) and self.iterator == 100:
|
||||||
if not self.next_play:
|
if not self.next_play:
|
||||||
xbmc.sleep(3000)
|
xbmc.sleep(3000)
|
||||||
|
@ -296,7 +296,7 @@ class AnteoPlayer(xbmc.Player):
|
||||||
break
|
break
|
||||||
self.contentId = self.next_contentId
|
self.contentId = self.next_contentId
|
||||||
continue
|
continue
|
||||||
log('[AnteoPlayer]: ************************************* NO! break')
|
log('['+author+'Player]: ************************************* NO! break')
|
||||||
break
|
break
|
||||||
|
|
||||||
xbmc.Player().stop()
|
xbmc.Player().stop()
|
||||||
|
@ -455,7 +455,7 @@ class AnteoPlayer(xbmc.Player):
|
||||||
else:
|
else:
|
||||||
self.next_dl = False
|
self.next_dl = False
|
||||||
self.next_play = self.__settings__.getSetting('next_play') == 'true'
|
self.next_play = self.__settings__.getSetting('next_play') == 'true'
|
||||||
log('[AnteoPlayer]: next_dl - %s, next_play - %s, ids_video - %s' % (str(self.next_dl), str(self.next_play), str(self.ids_video)))
|
log('['+author+'Player]: next_dl - %s, next_play - %s, ids_video - %s' % (str(self.next_dl), str(self.next_play), str(self.ids_video)))
|
||||||
|
|
||||||
def setup_play(self):
|
def setup_play(self):
|
||||||
file_status = self.engine.file_status(self.contentId)
|
file_status = self.engine.file_status(self.contentId)
|
||||||
|
@ -474,7 +474,7 @@ class AnteoPlayer(xbmc.Player):
|
||||||
self.next_contentId = int(self.ids_video[next_contentId_index])
|
self.next_contentId = int(self.ids_video[next_contentId_index])
|
||||||
else:
|
else:
|
||||||
self.next_contentId = False
|
self.next_contentId = False
|
||||||
log('[AnteoPlayer][setup_play]: next_contentId: '+str(self.next_contentId))
|
log('['+author+'Player][setup_play]: next_contentId: '+str(self.next_contentId))
|
||||||
try:
|
try:
|
||||||
seasonId = self.get("seasonId")
|
seasonId = self.get("seasonId")
|
||||||
self.episodeId = self.get("episodeId") if not self.episodeId else int(self.episodeId) + 1
|
self.episodeId = self.get("episodeId") if not self.episodeId else int(self.episodeId) + 1
|
||||||
|
@ -494,7 +494,7 @@ class AnteoPlayer(xbmc.Player):
|
||||||
'season': int(seasonId),
|
'season': int(seasonId),
|
||||||
'tvshowtitle': title})
|
'tvshowtitle': title})
|
||||||
except:
|
except:
|
||||||
log('[AnteoPlayer]: Operation INFO failed!')
|
log('['+author+'Player]: Operation INFO failed!')
|
||||||
|
|
||||||
thumbnail = self.get("thumbnail")
|
thumbnail = self.get("thumbnail")
|
||||||
if thumbnail:
|
if thumbnail:
|
||||||
|
@ -510,12 +510,12 @@ class AnteoPlayer(xbmc.Player):
|
||||||
xbmc.sleep(200)
|
xbmc.sleep(200)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
log('[AnteoPlayer]: self.isPlaying() = %s, i = %d, xbmc.abortRequested - %s' % (str(self.isPlaying()), i, str(xbmc.abortRequested)))
|
log('['+author+'Player]: self.isPlaying() = %s, i = %d, xbmc.abortRequested - %s' % (str(self.isPlaying()), i, str(xbmc.abortRequested)))
|
||||||
if not self.isPlaying() or xbmc.abortRequested:
|
if not self.isPlaying() or xbmc.abortRequested:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.seek > 0:
|
if self.seek > 0:
|
||||||
log('[AnteoPlayer]: seekTime - '+str(self.seek))
|
log('['+author+'Player]: seekTime - '+str(self.seek))
|
||||||
self.seekTime(self.seek)
|
self.seekTime(self.seek)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -622,7 +622,7 @@ class AnteoPlayer(xbmc.Player):
|
||||||
if not status:
|
if not status:
|
||||||
status = self.engine.status()
|
status = self.engine.status()
|
||||||
self.engine.check_torrent_error(status)
|
self.engine.check_torrent_error(status)
|
||||||
log('[AnteoPlayer]: %.2f%% complete (down: %.1f kb/s up: %.1f kb/s peers: %d) %s' % \
|
log('['+author+'Player]: %.2f%% complete (down: %.1f kb/s up: %.1f kb/s peers: %d) %s' % \
|
||||||
(status.progress * 100, status.download_rate,
|
(status.progress * 100, status.download_rate,
|
||||||
status.upload_rate, status.num_peers, status.state_str))
|
status.upload_rate, status.num_peers, status.state_str))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue