How to add support play torrent files to my addon?
#1
Hello everyone, I start to learn how to develop some addon but I have only one problem that is play torrent files or magnet links. I will take the Roman's Addon YATP as example, I know that there is a link or key to call the addon something like "plugin://plugin.video.yatp/?action=play&torrent=" but I don't know how is the best form to succes play a file (local or online) because I try so much times with the builtin function "xbmc.executebuiltin (PlayMedia())" but doesnt works and sometimes Kodi crash, I need to know how is the order of elements, the elements that I need and how to test with local files because I put a file called "video.torrent" on root folder of my .py but I don't know how to call it, so I need a few examples to understand how it works I will put my code that i made using Codequick Framework that makes my life easier.

python:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# noinspection PyUnresolvedReferences
from codequick import Route, Resolver, Listitem, utils, run
from codequick.utils import urljoin_partial, bold
import urlquick
import xbmcgui
import re
import resolveurl
import xbmc
import urllib

headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
}

@Route.register
def root(plugin, content_type="segment"):
    resp = urlquick.get(
        "http://bt.etree.org/details.php?torrentId=614621",
        headers=headers,
        max_age=-1,
    )
    root_elem = resp.parse(
        "body", attrs={"bgcolor": "bfd5ba"}
    )
    videos_list = root_elem.iterfind("table[@bgcolor='#CCCCCC']/tbody/tr[4]/td[2]/a")
    for elem in videos_list:
        item = Listitem()
        item.label = elem.text
        linkpart = elem.get("href")
        url = "http://bt.etree.org/"+linkpart
        item.set_callback(play_video, url=url)
        yield item


@Resolver.register
def play_video(plugin, url):
    url = url
    mediaurl = urllib.quote_plus(url)
    xbmc.executebuiltin( "PlayMedia(" + "plugin://plugin.video.yatp/?action=play&torrent="+url +")" )

I guess that is easy to understand but ask me anything if you don't understand something, from what I could investigate the page has legal content so no problem, but with local files I have no idea what to do, thank you for advice.
Reply
#2
It's not clear what your problem is. Generally speaking, you can pass a "plugin://" URL with proper parameters to setResolvedUrl() as it's done in plugins that list Youtube videos and play them via Youtube plugin.

As for YATP, I created it several years ago as a proof of concept when I was interested in technical aspects of playing video files while they are downloaded. Since then my interests changed and YATP is effectively abandoned. I'm not even sure if it works with recent Kodi versions. It certainly does not work on "Matrix", but I'm not sure that it even works on "Leia".
Reply
#3
Thumbs Up 
Sorry for the late response Roman, I have been looking at tutorials of all colors and flavors and I am happy because I finally "finished" my first addon with some error than another but it runs quite well thanks to your advice with the resolve it effectively reproduces the youtube videos and vimeo without problem, I even made my first repository and I am looking for how to do that that you can add a url to your github to install the repository by that means adding it in the file manager but I still cannot find how to do that. As for the YATP Addon I have not managed to make it work, apparently it is some server problem or something like that, I leave you the log fragment that I get

Code:
=Traceback (most recent call last): File "C:\Users\PONCHO\AppData\Roaming\Kodi\addons\plugin.video.yatp\main.py", line 10, in from libs.client.actions import plugin File "C:\Users\PONCHO\AppData\Roaming\Kodi\addons\plugin.video.yatp\libs\client\actions.py", line 11, in import json_requests as jsonrq File "C:\Users\PONCHO\AppData\Roaming\Kodi\addons\plugin.video.yatp\libs\client\json_requests.py", line 14, in json_rpc_url = 'http://127.0.0.1:{0}/json-rpc'.format(addon.server_port) AttributeError: 'Addon' object has no attribute 'server_port' -->End of Python script error report<--
Reply

Logout Mark Read Team Forum Stats Members Help
How to add support play torrent files to my addon?0