Replace python-libtorrent with vfs.libtorrent
Now torrents are downloaded with vfs.libtorrent[1]. Some parts of the code were removed as they will probably be useless in the future. For instance, the service is disabled (temporarily?) because the download in background/foreground is now managed by vfs.libtorrent. Use the Read() API of vfs.libtorrent to retrieve the path where the torrent was downloaded. Also: * Display a warning if there are more than 1 file in the torrent because the add-on will play only the first file * Remove the "start downloading" notification since an equivalent message is now displayed by vfs.libtorrent [1]:https://framagit.org/thombet/vfs.libtorrent
This commit is contained in:
parent
11b92d5896
commit
108fea515d
|
@ -1,15 +1,15 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<addon id="plugin.video.peertube" name="PeerTube" version="1.2.0" provider-name="Cyrille B. + Thomas B.">
|
<addon id="plugin.video.peertube" name="PeerTube" version="1.3.0-dev" provider-name="Cyrille B. + Thomas B.">
|
||||||
<requires>
|
<requires>
|
||||||
<import addon="xbmc.python" version="3.0.0"/>
|
<import addon="xbmc.python" version="3.0.0"/>
|
||||||
<import addon="script.module.addon.signals" version="0.0.6"/>
|
<!--<import addon="script.module.addon.signals" version="0.0.6"/>-->
|
||||||
<import addon="script.module.requests" version="2.25.1"/>
|
<import addon="script.module.requests" version="2.25.1"/>
|
||||||
<!-- <import addon="script.module.libtorrent" version="1.2.0"/> -->
|
<import addon="vfs.libtorrent"/>
|
||||||
</requires>
|
</requires>
|
||||||
<extension point="xbmc.python.pluginsource" library="main.py">
|
<extension point="xbmc.python.pluginsource" library="main.py">
|
||||||
<provides>video</provides>
|
<provides>video</provides>
|
||||||
</extension>
|
</extension>
|
||||||
<extension point="xbmc.service" library="service.py"/>
|
<!--<extension point="xbmc.service" library="service.py"/>-->
|
||||||
<extension point="xbmc.addon.metadata">
|
<extension point="xbmc.addon.metadata">
|
||||||
<summary lang="de_DE">Add-on für PeerTube</summary>
|
<summary lang="de_DE">Add-on für PeerTube</summary>
|
||||||
<description lang="de_DE">PeerTube ist eine kostenlose, dezentralisierte und föderierte Alternative zu anderen Videoplattformen (wie YouTube).</description>
|
<description lang="de_DE">PeerTube ist eine kostenlose, dezentralisierte und föderierte Alternative zu anderen Videoplattformen (wie YouTube).</description>
|
||||||
|
|
|
@ -167,13 +167,9 @@ msgctxt "#30413"
|
||||||
msgid "PeerTube cannot play videos without libtorrent\nPlease follow the instructions at {}"
|
msgid "PeerTube cannot play videos without libtorrent\nPlease follow the instructions at {}"
|
||||||
msgstr "PeerTube kann keine Videos ohne libtorrent abspielen\nBitte folgen Sie den Anweisungen unter {}"
|
msgstr "PeerTube kann keine Videos ohne libtorrent abspielen\nBitte folgen Sie den Anweisungen unter {}"
|
||||||
|
|
||||||
msgctxt "#30414"
|
# 30414 is not used anymore
|
||||||
msgid "Download started"
|
|
||||||
msgstr "Download gestartet"
|
|
||||||
|
|
||||||
msgctxt "#30415"
|
# 30415 is not used anymore
|
||||||
msgid "The video will be played soon."
|
|
||||||
msgstr "Das Video wird in kürze abgespielt."
|
|
||||||
|
|
||||||
msgctxt "#30416"
|
msgctxt "#30416"
|
||||||
msgid "Download timeout"
|
msgid "Download timeout"
|
||||||
|
@ -194,3 +190,11 @@ msgstr "{} ist nun die ausgewählte Instanz."
|
||||||
msgctxt "#30420"
|
msgctxt "#30420"
|
||||||
msgid "You can still browse and search videos but you will not be able to play them (except live videos).\nPlease follow the instructions at {}"
|
msgid "You can still browse and search videos but you will not be able to play them (except live videos).\nPlease follow the instructions at {}"
|
||||||
msgstr "Sie können weiterhin Videos durchsuchen und suchen, aber Sie können sie nicht abspielen (außer Live-Videos).\nBefolgen Sie bitte die Anweisungen unter {}"
|
msgstr "Sie können weiterhin Videos durchsuchen und suchen, aber Sie können sie nicht abspielen (außer Live-Videos).\nBefolgen Sie bitte die Anweisungen unter {}"
|
||||||
|
|
||||||
|
msgctxt "#30421"
|
||||||
|
msgid "Download error"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgctxt "#30422"
|
||||||
|
msgid "Error when trying to download the video. Check the log for more information."
|
||||||
|
msgstr ""
|
||||||
|
|
|
@ -167,13 +167,9 @@ msgctxt "#30413"
|
||||||
msgid "PeerTube cannot play videos without libtorrent\nPlease follow the instructions at {}"
|
msgid "PeerTube cannot play videos without libtorrent\nPlease follow the instructions at {}"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
msgctxt "#30414"
|
# 30414 is not used anymore
|
||||||
msgid "Download started"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
msgctxt "#30415"
|
# 30415 is not used anymore
|
||||||
msgid "The video will be played soon."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
msgctxt "#30416"
|
msgctxt "#30416"
|
||||||
msgid "Download timeout"
|
msgid "Download timeout"
|
||||||
|
@ -194,3 +190,11 @@ msgstr ""
|
||||||
msgctxt "#30420"
|
msgctxt "#30420"
|
||||||
msgid "You can still browse and search videos but you will not be able to play them (except live videos).\nPlease follow the instructions at {}"
|
msgid "You can still browse and search videos but you will not be able to play them (except live videos).\nPlease follow the instructions at {}"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
msgctxt "#30421"
|
||||||
|
msgid "Download error"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgctxt "#30422"
|
||||||
|
msgid "Error when trying to download the video. Check the log for more information."
|
||||||
|
msgstr ""
|
||||||
|
|
|
@ -173,13 +173,9 @@ msgctxt "#30413"
|
||||||
msgid "PeerTube cannot play videos without libtorrent\nPlease follow the instructions at {}"
|
msgid "PeerTube cannot play videos without libtorrent\nPlease follow the instructions at {}"
|
||||||
msgstr "PeerTube ne peut pas lire de vidéos sans libtorrent.\nMerci de suivre les instructions depuis {}"
|
msgstr "PeerTube ne peut pas lire de vidéos sans libtorrent.\nMerci de suivre les instructions depuis {}"
|
||||||
|
|
||||||
msgctxt "#30414"
|
# 30414 is not used anymore
|
||||||
msgid "Download started"
|
|
||||||
msgstr "Démarrage du téléchargement"
|
|
||||||
|
|
||||||
msgctxt "#30415"
|
# 30415 is not used anymore
|
||||||
msgid "The video will be played soon."
|
|
||||||
msgstr "La video va être bientôt lue."
|
|
||||||
|
|
||||||
msgctxt "#30416"
|
msgctxt "#30416"
|
||||||
msgid "Download timeout"
|
msgid "Download timeout"
|
||||||
|
@ -200,3 +196,11 @@ msgstr "{} est maintenant l'instance sélectionnée."
|
||||||
msgctxt "#30420"
|
msgctxt "#30420"
|
||||||
msgid "You can still browse and search videos but you will not be able to play them (except live videos).\nPlease follow the instructions at {}"
|
msgid "You can still browse and search videos but you will not be able to play them (except live videos).\nPlease follow the instructions at {}"
|
||||||
msgstr "Vous pouvez parcourir ou chercher des vidéos mais vous ne pourrez pas les lire (sauf les live).\nMerci de suivre les instructions depuis {}"
|
msgstr "Vous pouvez parcourir ou chercher des vidéos mais vous ne pourrez pas les lire (sauf les live).\nMerci de suivre les instructions depuis {}"
|
||||||
|
|
||||||
|
msgctxt "#30421"
|
||||||
|
msgid "Download error"
|
||||||
|
msgstr "Erreur de téléchargement"
|
||||||
|
|
||||||
|
msgctxt "#30422"
|
||||||
|
msgid "Error when trying to download the video. Check the log for more information."
|
||||||
|
msgstr "Une erreur est survenue pendant le téléchargement de la vidéo. Voir le journal pour plus d'informations."
|
||||||
|
|
|
@ -8,11 +8,14 @@
|
||||||
SPDX-License-Identifier: GPL-3.0-only
|
SPDX-License-Identifier: GPL-3.0-only
|
||||||
See LICENSE.txt for more information.
|
See LICENSE.txt for more information.
|
||||||
"""
|
"""
|
||||||
import AddonSignals # Module exists only in Kodi - pylint: disable=import-error
|
import json
|
||||||
|
import os.path
|
||||||
|
from urllib.parse import quote_plus
|
||||||
|
|
||||||
from resources.lib.kodi_utils import kodi
|
from resources.lib.kodi_utils import kodi
|
||||||
from resources.lib.peertube import PeerTube, list_instances
|
from resources.lib.peertube import PeerTube, list_instances
|
||||||
|
|
||||||
|
import xbmcvfs
|
||||||
|
|
||||||
class PeerTubeAddon():
|
class PeerTubeAddon():
|
||||||
"""
|
"""
|
||||||
|
@ -338,57 +341,34 @@ class PeerTubeAddon():
|
||||||
|
|
||||||
:param str torrent_url: URL of the torrent file to download and play
|
:param str torrent_url: URL of the torrent file to download and play
|
||||||
"""
|
"""
|
||||||
# If libtorrent could not be imported, display a message and do not try
|
|
||||||
# download nor play the video as it will fail.
|
|
||||||
if not self.libtorrent_imported:
|
|
||||||
kodi.open_dialog(
|
|
||||||
title=kodi.get_string(30412),
|
|
||||||
message=kodi.get_string(30413).format(self.HELP_URL))
|
|
||||||
return
|
|
||||||
|
|
||||||
kodi.debug("Starting torrent download ({})".format(torrent_url))
|
kodi.debug("Starting torrent download ({})".format(torrent_url))
|
||||||
kodi.notif_info(title=kodi.get_string(30414),
|
|
||||||
message=kodi.get_string(30415))
|
|
||||||
|
|
||||||
# Start a downloader thread
|
# Download the torrent using vfs.libtorrent: the torrent URL must be
|
||||||
AddonSignals.sendSignal("start_download", {"url": torrent_url})
|
# URL encoded to be correctly read by vfs.libtorrent
|
||||||
|
vfs_url = "torrent://{}".format(quote_plus(torrent_url))
|
||||||
|
torrent = xbmcvfs.File(vfs_url)
|
||||||
|
|
||||||
# Wait until the PeerTubeDownloader has downloaded all the torrent's
|
# Download the file
|
||||||
# metadata
|
if(torrent.write("download")):
|
||||||
AddonSignals.registerSlot(kodi.addon_id,
|
|
||||||
"metadata_downloaded",
|
|
||||||
self._play_video_continue)
|
|
||||||
timeout = 0
|
|
||||||
while not self.play and timeout < 10:
|
|
||||||
kodi.sleep(1000)
|
|
||||||
timeout += 1
|
|
||||||
|
|
||||||
# Abort in case of timeout
|
# Get information about the torrent
|
||||||
if timeout == 10:
|
torrent_info = json.loads(torrent.read())
|
||||||
kodi.notif_error(
|
|
||||||
title=kodi.get_string(30416),
|
# Build the path of the downloaded file
|
||||||
message=kodi.get_string(30417).format(torrent_url))
|
self.torrent_file = os.path.join(torrent_info["save_path"],
|
||||||
return
|
torrent_info["files"][0]["path"])
|
||||||
|
|
||||||
|
if torrent_info["nb_files"] > 1:
|
||||||
|
kodi.warning("There are more than 1 file in {} but only the"
|
||||||
|
" first one will be played.".format(torrent_url))
|
||||||
|
|
||||||
|
# Play the file
|
||||||
|
kodi.debug("Starting video playback of {}".format(self.torrent_file))
|
||||||
|
kodi.play(self.torrent_file)
|
||||||
else:
|
else:
|
||||||
# Wait a little before starting playing the torrent
|
kodi.notif_error(title=kodi.get_string(30421),
|
||||||
kodi.sleep(3000)
|
message=kodi.get_string(30422))
|
||||||
|
|
||||||
# Pass the item to the Kodi player for actual playback.
|
|
||||||
kodi.debug("Starting video playback ({})".format(self.torrent_file))
|
|
||||||
kodi.play(self.torrent_file)
|
|
||||||
|
|
||||||
def _play_video_continue(self, data):
|
|
||||||
"""
|
|
||||||
Callback function to let the _play_video method resume when the
|
|
||||||
PeertubeDownloader has downloaded all the torrent's metadata
|
|
||||||
|
|
||||||
:param data: dict of information sent from PeertubeDownloader
|
|
||||||
"""
|
|
||||||
|
|
||||||
kodi.debug(
|
|
||||||
"Received metadata_downloaded signal, will start playing media")
|
|
||||||
self.play = True
|
|
||||||
self.torrent_file = data["file"].encode("utf-8")
|
|
||||||
|
|
||||||
def _select_instance(self, instance):
|
def _select_instance(self, instance):
|
||||||
"""
|
"""
|
||||||
|
@ -455,9 +435,3 @@ class PeerTubeAddon():
|
||||||
# Display the addon's main menu when the plugin is called from
|
# Display the addon's main menu when the plugin is called from
|
||||||
# Kodi UI without any parameters
|
# Kodi UI without any parameters
|
||||||
self._home_page()
|
self._home_page()
|
||||||
|
|
||||||
# Display a warning if libtorrent could not be imported
|
|
||||||
if not self.libtorrent_imported:
|
|
||||||
kodi.open_dialog(
|
|
||||||
title=kodi.get_string(30412),
|
|
||||||
message=kodi.get_string(30420).format(self.HELP_URL))
|
|
||||||
|
|
|
@ -258,6 +258,15 @@ class KodiUtils:
|
||||||
"""
|
"""
|
||||||
xbmc.sleep(time_us)
|
xbmc.sleep(time_us)
|
||||||
|
|
||||||
|
def translate_path(self, path):
|
||||||
|
"""Translate a path using Kodi specialprotocol to an actual path
|
||||||
|
|
||||||
|
:param str path: Path using Kodi special protocol
|
||||||
|
:return: Translated path
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
return xbmc.translatePath(path)
|
||||||
|
|
||||||
def update_call_info(self, argv):
|
def update_call_info(self, argv):
|
||||||
"""Update the attributes related to the current call of the add-on
|
"""Update the attributes related to the current call of the add-on
|
||||||
|
|
||||||
|
@ -267,4 +276,18 @@ class KodiUtils:
|
||||||
self.addon_handle = int(argv[1])
|
self.addon_handle = int(argv[1])
|
||||||
self.addon_parameters = argv[2]
|
self.addon_parameters = argv[2]
|
||||||
|
|
||||||
|
def warning(self, message, prefix=None):
|
||||||
|
"""Log a message in Kodi's log with the level xbmc.LOGWARNING
|
||||||
|
|
||||||
|
The message will be prefixed with the prefix passed as argument or with
|
||||||
|
the name of the add-on.
|
||||||
|
|
||||||
|
:param str message: Message to log
|
||||||
|
:param str prefix: String to prefix the message with
|
||||||
|
"""
|
||||||
|
if not prefix:
|
||||||
|
prefix = self.addon_name
|
||||||
|
|
||||||
|
xbmc.log("[{}] {}".format(prefix, message), xbmc.LOGWARNING)
|
||||||
|
|
||||||
kodi = KodiUtils()
|
kodi = KodiUtils()
|
||||||
|
|
Loading…
Reference in New Issue