2021-12-04, 17:56
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.
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.
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.