Is it possible to do something when a video "stops" or "ends"?

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
snavaro Offline
Member
Posts: 81
Joined: Mar 2012
Reputation: 0
Post: #46
(2012-06-19 02:15)datalore44 Wrote:  Hi. Has anyone managed to get this working yet?
I tried Snavaro`s code and all it did was to lock up!
Could not a separate script be made that could give you the delete option after you press stop?

Hi datalore,

I have been working on the lockup issues. Several things apparently come into play. First, there is no way currently to determine when the CleanLibrary function is finished, and apparently if the Container is Refreshed while cleaning is in progress.. it just locks up. To solve that issue, I have moved the PreviousMenu and Container.Refresh commands ahead of the Cleaning function. That way,I did not have to worry about setting sleep delays that varied by computer speed, library size etc.
From what I have learned, monitoring the Clean function will be possible in Frodo, as it has been implemented in the recent builds via Library.IsScanningVideo.
Here is my updated code. Try it and let me know what other bugs there are.
Code:
import xbmc, xbmcgui, os,  sys
import xbmcvfs
import ntpath

file = xbmc.getInfoLabel( "ListItem.FilenameAndPath" )
title1 = xbmc.getInfoLabel( "ListItem.TVShowTitle" )
title2 = xbmc.getInfoLabel( "ListItem.Title" )
#either title1 or title2 will be a null string
title = title1 + title2
print "file = " + file
filename = ntpath.basename(file)
filename1, ext = os.path.splitext(filename)
# for future development to delete ancillary files
file1 = filename1 + ".nfo" #...same filename different extension
file2 = filename1 + ".tbn"

if title == title1:
    category = "TvShowTitles"
else:
    category = "MovieTitles"
#------------above category code not needed for now----------

if (not xbmc.abortRequested):
    if xbmcvfs.exists(file):
        xbmcvfs.delete(file)
        #comment out above line for testing...remove comment hash to implement
        print "Deleting " + file  #for debugging only ..can be deleted
        xbmc.executebuiltin("XBMC.Notification(%s, %s, %i)" % ('Deleting File',filename + ' is being deleted.',4000)) # Screen notification of file deletion process
        xbmc.sleep(4000)
    else:
        print "File does not exist!"
        xbmc.executebuiltin("XBMC.Notification(%s, %s, %i)" % ('File Not Found',filename + ' not found in database!',4000))

# Check for deletion process to finish before cleaning.
while (xbmcvfs.exists(file) and not xbmc.abortRequested):
    xbmc.sleep(3000)
    print "File deletion not yet complete..."


# Check if the library is being updated before cleaning up
while (xbmc.getCondVisibility("Library.IsScanningVideo")):
    xbmc.sleep(5000)
    xbmc.executebuiltin("Notification(Library Scan in Progress,Waiting Until Library Scan Completes...,5000)")
    
if (not xbmcvfs.exists(file)):
    print "File has been deleted."
    # refresh display
    xbmc.executebuiltin("xbmc.action(PreviousMenu)")
    xbmc.sleep(1000)
    xbmc.executebuiltin("Container.Refresh")
    
    xbmc.executebuiltin("XBMC.CleanLibrary(video)")
    print "Cleaning library"
    
    # The following will only work in Eden 12.0
    #while (xbmc.getCondVisibility('Library.IsScanningVideo')) : #wait while CleanLibrary finishes
    #    xbmc.sleep(5000)
Hope this helps.
find quote
datalore44 Offline
Junior Member
Posts: 9
Joined: Jun 2012
Reputation: 0
Post: #47
Great stuff I will try it and let you know.
Will this code work on any skin?
find quote
snavaro Offline
Member
Posts: 81
Joined: Mar 2012
Reputation: 0
Post: #48
(2012-06-19 20:58)datalore44 Wrote:  Great stuff I will try it and let you know.
Will this code work on any skin?

I am not sure. I have only tried it on the default Confluence skin. I presume that you were able to create a Delete button in DialogVideoInfo.xml and run the script from there. If you need help let me know.
find quote
datalore44 Offline
Junior Member
Posts: 9
Joined: Jun 2012
Reputation: 0
Post: #49
(2012-06-19 21:55)snavaro Wrote:  
(2012-06-19 20:58)datalore44 Wrote:  Great stuff I will try it and let you know.
Will this code work on any skin?

I am not sure. I have only tried it on the default Confluence skin. I presume that you were able to create a Delete button in DialogVideoInfo.xml and run the script from there. If you need help let me know.


Hmmm. I will be needing your help with the delete button. I know nothing about coding for xbmc, I am just a computer engineer.
When I ran the first code you posted, the delete button appeared in the settings menu once. When I restarted xbmc it was no longer there!
That is why i think it would have been nice to have a standalone script, that could be applied to any skin. But I realise that it cannot be done because each skin has its own individual folders and .xml files.
Where does the new code you wrote go, and do I still use any of the old code you wrote?

Looking at your old code, am I right in thinking that this:
In MyVideoNav add the following after line 5:
<onload condition="Window.Previous(FullScreenVideo) + Skin.HasSetting(DeleteEps)">Delete</onload>
Was the delete function.
And the coding that went into Custom Settings_1111 was the creation of the button to enable it?
I am sorry for my ignorance, but I am fascinated by the inner workings of the skin coding.
(This post was last modified: 2012-06-20 00:05 by datalore44.)
find quote
snavaro Offline
Member
Posts: 81
Joined: Mar 2012
Reputation: 0
Post: #50
No problem. Here is what I did, step by step.
To add the option to delete shows after watching, add this code to CustomSettings_111.xml at about line 296:
Code:
<!--deleteafterwatching-->
                    <control type="radiobutton" id="2003">
                    <width>750</width>
                    <height>40</height>
                    <font>font13</font>
                    <textcolor>grey2</textcolor>
                    <focusedcolor>white</focusedcolor>
                    <texturefocus>MenuItemFO.png</texturefocus>
                    <texturenofocus>MenuItemNF.png</texturenofocus>
                    <label>Enable DELETE After Watching TV Episodes</label>
                    <onclick>Skin.ToggleSetting(DeleteEps)</onclick>
                    <selected>Skin.HasSetting(DeleteEps)</selected>
                    <include>button_Settings</include>
                    </control>
In DialogVideoInfo.xml search for this line: <control type="togglebutton" id="8"> or the words "Play/Browse" These will be the buttons that show up as "Play" Refresh Cast Trailer etc. Add a new button control for the Delete button as follows:
Code:
<control type="button" id="7"><!--new button control to Delete program-->
                        <description>Delete</description>
                        <include>ButtonInfoDialogsCommonValues</include>
                        <label>184</label><!--label changed to read "Delete" in strings.xml file--->
                        <onclick>xbmc.RunScript(special://skin/scripts/deletefile.py)</onclick>
                        <visible>Skin.HasSetting(DeleteEps)</visible> <!--button is visible only through Settings-->
                    </control>
You can either comment out the Refresh button control so it does not appear or leave it on, your choice. Put the Delete button control code directly after the Refresh button control or in place of it.

You will notice in the above code that label 184 will show on the Delete control. Find string.xml in the confluence/language/English folder for XBMC. Search for label 184 and replace the text (which I think is the word "Refresh" with the word Delete.
make a new folder called scripts under the confluence skin folder (but not in the 720p folder). Place the script (which I named deletefile.py) in that folder.
Restart XBMC and you should be good to go.Don't forget to go into Settings/Video and enable the Delete After Watching option. That is the only way that the Delete button will appear for you.
find quote
datalore44 Offline
Junior Member
Posts: 9
Joined: Jun 2012
Reputation: 0
Post: #51
Ok, I am getting there, but
I cannot find the word "Refresh" or "Label 184" in my strings.xml?
I assume I create the deletefile.py by copying your code from you earlier post #46, pasting it into notepad++ and saving it as a python script?
Slightly confused by this comment:
You can either comment out the Refresh button control so it does not appear or leave it on, your choice. Put the Delete button control code directly after the Refresh button control or in place of it.
Not quite sure where the Refresh button control code is?
I have pasted it here:

<control type="togglebutton" id="8">
<description>Play/browse to Show</description>
<include>ButtonInfoDialogsCommonValues</include>
<label>208</label>
<alttexturefocus border="2">button-focus.png</alttexturefocus>
<alttexturenofocus border="2">button-nofocus.png</alttexturenofocus>
<altlabel>1024</altlabel>
<usealttexture>Container.Content(TVShows)</usealttexture>
</control>
<control type="button" id="7"><!--new button control to Delete program-->
<description>Delete</description>
<include>ButtonInfoDialogsCommonValues</include>
<label>184</label><!--label changed to read "Delete" in strings.xml file--->
<onclick>xbmc.RunScript(special://skin/scripts/deletefile.py)</onclick>
<visible>Skin.HasSetting(DeleteEps)</visible> <!--button is visible only through Settings-->
</control>
(This post was last modified: 2012-06-20 01:41 by datalore44.)
find quote
snavaro Offline
Member
Posts: 81
Joined: Mar 2012
Reputation: 0
Post: #52
OK. To comment out a line in xml, just begin with this <!-- and end with this --> If you do this in Notepad ++ everything in between will turn green and be ignored.

You are correct about saving my code in #46 as deletefile.py in Notepad++.

Here is the Refresh button control code:
<control type="button" id="6">
<description>Refresh</description>
<include>ButtonInfoDialogsCommonValues</include>
<label>184</label>
</control>
Find that ( it should be below the control id=8 code). Delete it or comment out using <!-- before the word <control> and --< after the word </control>.

I am sorry, I gave you the wrong directory for the strings file (there are actually 3 strings files). Look in Program Files/XBMC/language/English). This is the strings file that is independent of the skin being used.
Good luck!
(This post was last modified: 2012-06-20 02:49 by snavaro.)
find quote
datalore44 Offline
Junior Member
Posts: 9
Joined: Jun 2012
Reputation: 0
Post: #53
I have tried your code but it does not do anything when I press "stop" (keyboard x). I have checked all the info you have sent me and it appears to be in the right place. The enable delete button is in the skin setting.
I am able to delete it using the information panel (Keyboard i) which has replaced the refresh option.
After it deletes the file it goes through a library cleanup, which I assume you have intended it to do to remove it from the library database.
I am not sure that the deletefile.py is being activated though. Unless I have not created the file properly.

On a different subject, have you heard of voxcommander? It is supposed to be very good voice activation software and can control XBMC very well from what I have seen on You Tube. I am taking a look at it because it can be voice controlled via a mobile phone over wifi using skype.
find quote
datalore44 Offline
Junior Member
Posts: 9
Joined: Jun 2012
Reputation: 0
Post: #54
Snavaro, Are you still there?
find quote
snavaro Offline
Member
Posts: 81
Joined: Mar 2012
Reputation: 0
Post: #55
Sorry.. I had some personal matters to attend to. My code was designed to work using the Video OSD Stop button. I am sure there is a way to trap your keystroke and run the script, but I am no expert. let me check it out and see what I can find, or maybe someone else can chip in.
find quote
datalore44 Offline
Junior Member
Posts: 9
Joined: Jun 2012
Reputation: 0
Post: #56
I tried the osd stop button and that did not do anything either?
find quote
Post Reply