From 914bcb92345f484044b06857eddb51947073e0d1 Mon Sep 17 00:00:00 2001 From: Famille Bollu Date: Fri, 27 Jul 2018 07:40:45 +0200 Subject: [PATCH] Added logging --- addon.xml | 2 ++ peertube.py | 3 +++ service.py | 14 +++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index 9000f15..285b1ab 100644 --- a/addon.xml +++ b/addon.xml @@ -20,6 +20,8 @@ cyrille.bollu2@gmail.com https://github.com/StCyr/plugin.video.peertube +0.0.3 +Second PoC (download in background is almost there) 0.0.2 First PoC (download not in background) 0.0.1 diff --git a/peertube.py b/peertube.py index 7b3583d..106df11 100755 --- a/peertube.py +++ b/peertube.py @@ -30,6 +30,7 @@ class PeertubeAddon(): """ """ + xbmc.log('PeertubeAddon: Initialising', xbmc.LOGINFO) # Nothing to play at initialisation self.play = 0 self.torrent_name = '' @@ -119,6 +120,7 @@ class PeertubeAddon(): :return: None """ + xbmc.log('PeertubeAddon: Received metadata_downloaded signal, will start playing media', xbmc.LOGINFO) self.play = 1 self.torrent_name = data['name'] @@ -131,6 +133,7 @@ class PeertubeAddon(): :return: None """ + xbmc.log('PeertubeAddon: playing video ' + magnet_f, xbmc.LOGINFO) # Start a downloader thread AddonSignals.sendSignal('start_download', {'magnet_f': magnet_f}) diff --git a/service.py b/service.py index 8725869..27a535e 100644 --- a/service.py +++ b/service.py @@ -24,6 +24,7 @@ class PeertubeDownloader(Thread): :return: None """ + xbmc.log('PeertubeDownloader: Starting a torrent download', xbmc.LOGINFO) # Open bitTorrent session ses = libtorrent.session() ses.listen_on(6881, 6891) @@ -33,6 +34,7 @@ class PeertubeDownloader(Thread): magnet = f.read() # Add torrent + xbmc.log('PeertubeDownloader: Adding torrent ' + magnet, xbmc.LOGINFO) fpath = xbmc.translatePath('special://temp') h = ses.add_torrent({'url': magnet, 'save_path': fpath}) @@ -42,10 +44,11 @@ class PeertubeDownloader(Thread): # Download torrent signal_sent = 0 while not h.is_seed(): - time.sleep(1) + xbmc.sleep(1000) s = h.status() # Inform addon that all the metadata has been downloaded and that it may start playing the torrent if s.state >=3 and signal_sent == 0: + xbmc.log('PeertubeDownloader: Received all torrent metadata, notifying PeertubeAddon', xbmc.LOGINFO) AddonSignals.sendSignal('metadata_downloaded', {'name': h.name()} ) signal_sent = 1 @@ -61,6 +64,7 @@ class PeertubeService(): PeertubeService initialisation function """ + xbmc.log('PeertubeService: Initialising', xbmc.LOGINFO) # Create our temporary directory fpath = xbmc.translatePath('special://temp') + '/plugin.video.peertube' if not xbmcvfs.exists(fpath): @@ -73,8 +77,11 @@ class PeertubeService(): :return: None """ + xbmc.log('PeertubeService: Received a start_download signal', xbmc.LOGINFO) downloader = PeertubeDownloader(data['magnet_f']) downloader.start() + + return def run(self): """ @@ -86,15 +93,20 @@ class PeertubeService(): AddonSignals.registerSlot('plugin.video.peertube', 'start_download', self.download_torrent) # Monitor Kodi's shutdown signal + xbmc.log('PeertubeService: service started, Waiting for signals', xbmc.LOGINFO) monitor = xbmc.Monitor() while not monitor.abortRequested(): if monitor.waitForAbort(1): # Abort was requested while waiting. We must exit # TODO: I must delete all temp files before exiting break + + return if __name__ == '__main__': # Start a peertubeService instance + xbmc.log('PeertubeService: Starting', xbmc.LOGINFO) service = PeertubeService() service.run() + xbmc.log('PeertubeService: Exiting', xbmc.LOGINFO)