Automatic creation of specific TAGS - Andrea1998 - 2024-10-02
I ask if it is possible to create a script that allows you to generate and assign a specific TAG defined in a button, automatically when the button is pressed.
If there is a concrete possibility to make it work.
Example:
Window XML: "dialogvideoinfo"
.
.
.
xml: <control type="button">
<label>Set -Family- TAG</label>
<onclick>RunScript(script.SetTAG, ... query=Family)</onclick>
</control>
----
script name: "SetTAG"
... (write in python) ...
----
Result:
The movie or TV series in focus in dialogvideoinfo now has the TAG "Family"
This allows me to automatically create lists of Movies or TV series corresponding to a specific category, and use a smart playlist as a folder.
I know the manual step of setting the TAGs inside the skin, but there is a big problem that led me to try to develop this script:
if the last movie or TV series of a specific TAG is removed, the TAG is deleted and must be recreated every time.
Any help will be truly appreciated.
RE: Automatic creation of specific TAGS - Andrea1998 - 2024-10-05
I managed to solve it, here is the code:
python: import xbmc
import xbmcgui
import json
def apply_tag_to_selected_item():
xbmc.log("Script Apply tag avviato", xbmc.LOGINFO)
selected_item_id = xbmc.getInfoLabel('ListItem.DBID')
selected_item_title = xbmc.getInfoLabel('ListItem.Title')
xbmc.log(f"Elemento selezionato: ID={selected_item_id}, Titolo={selected_item_title}", xbmc.LOGINFO)
if selected_item_id:
# Verifica se l'elemento selezionato è un film o una serie TV
media_type = xbmc.getInfoLabel('ListItem.DBTYPE')
xbmc.log(f"Tipo di media selezionato: {media_type}", xbmc.LOGINFO)
if media_type == 'movie':
command = {
"jsonrpc": "2.0",
"method": "VideoLibrary.SetMovieDetails",
"params": {
"movieid": int(selected_item_id),
"tag": ["Nascondi Serie TV non terminata"]
},
"id": 1
}
elif media_type == 'tvshow':
command = {
"jsonrpc": "2.0",
"method": "VideoLibrary.SetTVShowDetails",
"params": {
"tvshowid": int(selected_item_id),
"tag": ["Nascondi Serie TV non terminata"]
},
"id": 1
}
else:
xbmcgui.Dialog().notification('Errore', 'Tipo di media non supportato', xbmcgui.NOTIFICATION_ERROR, 5000)
xbmc.log("Errore: Tipo di media non supportato", xbmc.LOGERROR)
return
xbmc.log(f"Esecuzione comando JSON-RPC: {json.dumps(command)}", xbmc.LOGINFO)
response = xbmc.executeJSONRPC(json.dumps(command))
xbmc.log(f"Risposta JSON-RPC: {response}", xbmc.LOGINFO)
response_data = json.loads(response)
if 'error' in response_data:
xbmcgui.Dialog().notification('Errore', 'Impossibile applicare il tag', xbmcgui.NOTIFICATION_ERROR, 5000)
xbmc.log(f"Errore: {response_data['error']}", xbmc.LOGERROR)
else:
xbmcgui.Dialog().notification('Tag Applicato', f'Tag "Nascondi Serie TV non terminata" a {selected_item_title}', xbmcgui.NOTIFICATION_INFO, 5000)
xbmc.log("Tag applicato con successo", xbmc.LOGINFO)
else:
xbmcgui.Dialog().notification('Errore', 'Nessun elemento selezionato', xbmcgui.NOTIFICATION_ERROR, 5000)
xbmc.log("Errore: Nessun elemento selezionato", xbmc.LOGERROR)
if __name__ == '__main__':
apply_tag_to_selected_item()
|