• 1
  • 3
  • 4
  • 5
  • 6(current)
  • 7
Your 2nd Add-On: Online Videos!
#76
Hooray -- it works,

download script.modules.requests-2.22.0.zip and install from zip file

Then add into addon.xml file

xml:

<requires>
  <import addon="script.module.requests" version="2.22.0"/>
</requires>

Now add into main.py of the plugin.video.example following snippet

python:

import json
import requests

url = 'http://iptv.server.com/series.json'

VIDEOS = {}
html = requests.get(url)
DATA = json.loads(html.content)
for series in DATA.keys():
    s = series.encode('utf-8')
    #xbmc.log(s, xbmc.LOGNOTICE)
    VIDEOS = []
    for episode in DATA[series]:
        name  = episode['name'].encode('utf-8')
        genre = episode['genre'].encode('utf-8')
        #xbmc.log(name, xbmc.LOGNOTICE)
        #xbmc.log(genre, xbmc.LOGNOTICE)
        e = { "name": name, "thumb": episode["thumb"], "video": episode["video"], "genre": genre }
        VIDEOS[s].append(e)
[/s]
Reply
#77
Hi,

you know an addon to create .strm files ?
Reply
#78
Are you asking for a program example or an add-on specifically for creating .strm files?
Reply
#79
(2020-06-01, 00:26)robertus Wrote: Hi,

you know an addon to create .strm files ?
here is py code for the function from my addon.

strmPath = ('special://profile/addon_data/plugin.video.addon-name/strm_dir/')
if not xbmcvfs.exists(strmPath):
    xbmcvfs.mkdir(strmPath)
strmPath = xbmc.translatePath(strmPath)
...
...
def makeStrm(name,movieurl):

    try:
        fileObj = open((strmPath + str(name).replace(':','-').replace('/','-').replace('?','').replace("'","").replace('\\','_').replace('#', ' ').replace('&','and') +'.strm'),'w')
        fileObj.write(movieurl)
        fileObj.close()
    except:
        pass

/Shooty
Reply
#80
(2020-06-05, 19:16)shooty Wrote:
(2020-06-01, 00:26)robertus Wrote: Hi,

you know an addon to create .strm files ?
here is py code for the function from my addon.

strmPath = ('special://profile/addon_data/plugin.video.addon-name/strm_dir/')
if not xbmcvfs.exists(strmPath):
    xbmcvfs.mkdir(strmPath)
strmPath = xbmc.translatePath(strmPath)
...
...
def makeStrm(name,movieurl):

    try:
        fileObj = open((strmPath + str(name).replace(':','-').replace('/','-').replace('?','').replace("'","").replace('\\','_').replace('#', ' ').replace('&','and') +'.strm'),'w')
        fileObj.write(movieurl)
        fileObj.close()
    except:
        pass

/Shooty
Thanks!
but how can i use it? Sorry but i'm a newbie
Reply
#81
(2020-06-10, 00:12)robertus Wrote:
(2020-06-05, 19:16)shooty Wrote:
(2020-06-01, 00:26)robertus Wrote: Hi,

you know an addon to create .strm files ?
here is py code for the function from my addon.

strmPath = ('special://profile/addon_data/plugin.video.addon-name/strm_dir/')
if not xbmcvfs.exists(strmPath):
    xbmcvfs.mkdir(strmPath)
strmPath = xbmc.translatePath(strmPath)
...
...
def makeStrm(name,movieurl):

    try:
        fileObj = open((strmPath + str(name).replace(':','-').replace('/','-').replace('?','').replace("'","").replace('\\','_').replace('#', ' ').replace('&','and') +'.strm'),'w')
        fileObj.write(movieurl)
        fileObj.close()
    except:
        pass

/Shooty
Thanks!
but how can i use it? Sorry but i'm a newbie
If you just want a program or script, you can see if context.dandy.strm.generator is still available.
Google it.
/Shooty
Reply
#82
I found the original script interesting and tried to write my own add-on.

My script is scraping a website for videos and builds a dictionary of subfolders with video links. The amount of leveled folders is very different each time, like this:

Category1
--- Date1
------ Video1
------ Video2
--- Date2 and so on...
Category2
--- Subcategory1
------ Date1
--------- Video1
--- Subcategory2

I can't know in advance the entire folder structure which also changes from time to time. I thought about building a nested dictionary and at the end parsing it to build the folder items for the add-on.
The example here only uses one fixed level of folders and videos as sub-items.

Now I've hit quite a road block. I've tried something recursive but can't get it right. Is there an easy way to know at which level the add-on gets called using the query string and build the folder item list of that level?
Reply
#83
@Roman_V_M

I am using your plugin.video.example for my own video plugin and I would appreciate it if you could help me out:

1- Do you think does it make sense to pickle the extracted video object to avoid re-downloading/re-extracting every time plugin runs, and just load the object instead.

2- If that make sense, since the extracted video URL would be outdated(most probably since some extracted from youtube) and fails to be played, the URL has to be updated and pickled again. My question is, where/how can I try the loaded pickle first and if it fails try to update/re-extract it and run it (in the except block)? Maybe inside router function?

python:

def router(paramstring):
    params = dict(parse_qsl(paramstring))
    if params:
        if params['action'] == 'listing':
            list_videos(params['category'])
       elif params['action'] == 'play':
           try:
               play_video(params['video'])
           except (ValueError, KeyError):
               logger.exception('Play video failed!!!')
              # RE-EXTRACT the URL VIDEO, OVERWRITE IT WITH EXISTING PICKLE FILE, RE-PLAY THE VIDEO
        else:
            raise ValueError('Invalid paramstring: {0}!'.format(paramstring))
    else:
       list_categories()​
​​

3- If not, what do you suggest for such a scenario?

Basically, my intention is to cache the extracted working URL in order to speed up the plugin, which is quite slow because of the video extraction. BTW, I already asked a question here

Cheers!
Reply
#84
@pa79 If your site complex hierarchy, it does not make any sense to try to build a data structure for this hierarchy in advance. You should generate the list of sub-sections/media-items for each level dynamically.

@aam137 
1. I is not clear what you mean by "video object". If it is some video URL that is too costly to obtain dynamically, then yes, some caching mechanism is recommended.
2. Definitely not at router() function level because it violates the Single Responsibility principle. Create some get_video() function that check cached items validity and obtains new URLs if necessary. But remember that a video plugin does not play anything by itself. It just passes video URLs to the Kodi player and after that its work is done. So a plugin has no way to know if a video URL has been played successfully or not. You can check validity of URLs in advance in your plugin, for example, by issuing HTTP HEAD requests to the URL to be played but this does not give you a 100% guarantee that the URL will be played successfully.
Reply
#85
(2020-10-05, 12:36)Roman_V_M Wrote: @aam137 
1. I is not clear what you mean by "video object". If it is some video URL that is too costly to obtain dynamically, then yes, some caching mechanism is recommended.
2. Definitely not at router() function level because it violates the Single Responsibility principle. Create some get_video() function that check cached items validity and obtains new URLs if necessary. But remember that a video plugin does not play anything by itself. It just passes video URLs to the Kodi player and after that its work is done. So a plugin has no way to know if a video URL has been played successfully or not. You can check validity of URLs in advance in your plugin, for example, by issuing HTTP HEAD requests to the URL to be played but this does not give you a 100% guarantee that the URL will be played successfully.
@Roman_V_M 
Thanks for the clarification and prompt reply!

1- By the object, I meant the extracted video URL(with other stuff like genre, thumbnail, etc as a dictionary).
Basically, retrieving the URL and saving/loading it was my idea regarding caching, but as it is costly I may forget about it.

2- Alright, based on your explanation, as there is no way to check if the video played successfully or not within the plugin, then I think some sort of caching mechanism would help.
I want to skip the URL extraction part as much as possible to speed up the plugin. 

Do you have any suggestion about the caching mechanism?
Reply
#86
hello @Polar Bear and others.

I tried your json example and added it to romans example but i am getting the following error in the kodi.log

Code:
[s]2020-12-01 12:10:50.431 T:2684    ERROR <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                                    - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                                   Error Type: <class 'TypeError'>
                                                   Error Contents: list indices must be integers or slices, not bytes
                                                   Traceback (most recent call last):
                                                     File "C:\Users\PC\AppData\Roaming\Kodi\addons\plugin.video.example\main.py", line 64, in <module>
                                                       VIDEOS[s].append(e)
                                                   TypeError: list indices must be integers or slices, not bytes
                                                   -->End of Python script error report<--[/s]
 
Code:
[s]xbmc.log(str(s), xbmc.LOGINFO)[/s]
shows
Code:
[s]2020-12-01 12:10:50.430 T:2684     INFO <general>: b'Category1'[/s]

would you mind posting the contents of your json file so i can compare if the formatting is correct. the url in your example is 404.

i have also tried to change the contents of s to an int in the json file but then i get the following error.
IndexError: list index out of range

thx for your time and help guys! Wink

edit: ahh and i forgot to mention that i'm using kodi matrix beta 1 and python3 with @Roman_V_M's Python3 example. Is there a change in the syntax maybe?


edit: Fixed. Actually it was not that hard once i were able to wrap my head around it. If someone needs help with it, feel free to pm me. Thx for your great example @Roman_V_M. It really helped me learn some more about the python! =)
Reply
#87
@Roman_V_M hello, first off thank you for the great template for creating a video plugin.  I've been wanting to make a plugin for a while for Kodi and just never was able to do it.  I have a media network that I started with some friends and I wanted to build a plugin that could be installed and people could access the videos on the site.  I have been able to get MOST of this done with no issues.  However I seem to of hit a couple probably small road blocks.  When I'm generating my structure, I do not believe it is acting how it should.  I originally pulled the Kodi 18 plugin pack and then tried 19 just because.  What I'm finding is this.  When I load the plugin I get my shows and they display which is awesome. However in both versions of Kodi when viewing a media info view I do not see the seasons count.  In 19 I noticed the episodes count is not coming through now as well.  I've hard coded these values for now until I write something to count the values to place into these fields.  I don't know if the issue is due to setting the content type or perhaps the media type.  I've tried a few interations from what I found in the Kodi docs here https://codedocs.xyz/xbmc/xbmc/group__py...957264dbbe but nothing seems to come across.  It also looks like in 19 rating doesn't pull through.  Now I do realize some of these could be skin issues but I wanted to be sure I am placing the information in the correct place.  My plugin for Kodi 18 can be found here https://github.com/SimplySynced/plugin.v...cape.media .  

Currently I'm pulling a feed from a WP plugin for Roku but I may end up writing a WP plugin to accompany this plugin once I've fleshed it out and figure out these small issues.  Appreciate the look
Reply
#88
I followed this example and my add on works great but there is on issue I could not find a solution yet. If I stop playback it always returns to top of list how to force it to stop in the last position
thanks
Reply
#89
I used this tutorial for made a plugin but i got a problem.

The list is generated without problems and the first video selected play whithout problems, but when stop it, cant play any other.

My code: https://paste.kodi.tv/ataziwasip
The log: https://paste.kodi.tv/izoqazohof.kodi
Reply
#90
Can we have a plugin.video.example to use with the .json file ?
with some example to show how to add each data of the json file into kodi like fanart, genre, actor, plot etc...

for example:
{
  "Movies": [
    
     {
        "id":"01",
        "name": "Top Gun Maverick",
        "poster": "https://www.cinemaclock.com/images/posters/1000x1500/70/top-gun-maverick-v-f-2020-affiche.jpg"
        "fanart": "https://cinemaplanet.pt/wp-content/uploads/2019/12/Top-Gun.jpeg"
        "video": "http://testlink/video.mp4"
        "actor": "Tom Cruz"
        "genre": "Action"
        "plot": "bla bla..."
     },
    
     {
        "id":"02",
        "name": "Jurassic World 3",
        "poster": "https://fr.web.img6.acsta.net/c_310_420/pictures/22/04/14/18/30/0040092.jpg"
        "fanart": "https://1.bp.blogspot.com/-pg9Ssgs2Nqs/XlWSiuAFRZI/AAAAAAACbOs/BMwZluI92fc0_C2MgFz4OILokf5w2OcUwCNcBGAsYHQ/s1600/pdc_jurassicworld22.jpg"
        "video": "http://testlink/video2.mp4"
        "actor": "Chris Pratt"
        "genre": "Aventure, Science Fiction"
        "plot": "bla bla..."
     }
  ]   
 
 
 "Tv Show": [
    
     {
        "id":"01",
        "name": "Game of Thrones",
        "poster": "https://awoiaf.westeros.org/thumb.php?f=Season_1_Poster.jpg&width=800"
        "fanart": "https://static1.srcdn.com/wordpress/wp-content/uploads/2019/05/Game-of-Thrones-Finale-Bran-Iron-Throne.jpg?q=50&fit=crop&w=960&h=500&dpr=1.5"
        "video": "http://testlink/video3.mp4"
        "actor": "Emilia Clarke"
        "season": "01"
        "episode": "01"
        "genre": "Aventure"
        "plot": "bla bla..."
     },
    
     {
        "id":"02",
        "name": "Star Trek",
        "poster": "https://artfiles.alphacoders.com/960/thumb-1920-96035.jpg"
        "fanart": "https://static1.srcdn.com/wordpress/wp-content/uploads/2020/12/Star-Trek-TOS-cast.jpg?q=50&fit=crop&w=960&h=500&dpr=1.5"
        "video": "http://testlink/video4.mp4"
        "actor": "Patrick Stewart"
        "season": "01"
        "episode": "01"
        "genre": "Science Fiction"
        "plot": "bla bla..."
     }
  ]   
 
 
}
Reply
  • 1
  • 3
  • 4
  • 5
  • 6(current)
  • 7

Logout Mark Read Team Forum Stats Members Help
Your 2nd Add-On: Online Videos!2