help with my Plugin
#1
After a week of reading pulling my hair out

I have this Python code that works sort of

PHP Code:
from lib import exifread
import os
systime
import xbmcaddon
xbmcplugin xbmcguixbmc
'''
http://mirrors.xbmc.org/docs/python-docs/16.x-jarvis/

This will copy file JPG and look at the date the photo taken
create a destion folder as for the movie file it will look at the date the file
was last Last Modified Date

StartFrom -
          | Year -
                 | ## ### - (monthnumber monthname) eg 05 May 
                          | the files
The reason I formated the month folder number then name only
because its in sort order by its number
'''
# Plugin constants
__addon__     xbmcaddon.Addon()
__addonname__ __addon__.getAddonInfo('name'
# Shared resourse
PCS_CopyTo      __addon__.getSetting('CopyTo')
PCS_MoveThem    __addon__.getSetting('MoveThem')
PCS_FindExt     __addon__.getSetting('FindExt')
PCS_Target_Mess __addon__.getLocalizedString(30103)
PCS_LastTime    __addon__.getSetting('LastTime')
PCS_MonName     = [' ','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
PCS_StartFrom   xbmcgui.Dialog().browse(0,PCS_Target_Mess,'files',PCS_FindExt.replace(',','|').lower(),True,False,PCS_LastTime)
__addon__.setSetting('LastTime',PCS_StartFrom)
PCS_Count 0

pDialog 
xbmcgui.DialogProgress()

#
def Get_exif(f):
    
tags exifread.process_file(open(f'rb'))
    
ItsFile os.path.basename(f)
    
#print "comment :%s" % tags['EXIF UserComment']
    
if tags not in ('JPEGThumbnail''TIFFThumbnail''Filename''EXIF MakerNote'):
        try: 
# try and read the EXIF DateTimeOriginal
            
ctime time.strptime(str(tags['EXIF DateTimeOriginal']), '%Y:%m:%d %H:%M:%S')
            
This_Month '%s %s' % (str(ctime.tm_mon),MonName[ctime.tm_mon])
            return 
str(ctime.tm_year),This_Month,ItsFile
        except KeyError
# Bugger can't read it so i get the date is was Last Modified
            
ctime time.strptime(time.ctime(os.path.getmtime(f)),"%a %b %d %H:%M:%S %Y")
            
This_Month '%s %s' % (str(ctime.tm_mon),MonName[ctime.tm_mon])
            return 
str(ctime.tm_year),This_Month,ItsFile

# This is for testing am i doing it right                
line1 ">> " PCS_StartFrom
line2 
"<<  =================================== >>"
line3 ">> " PCS_CopyTo

PCS_YesNo 
xbmcgui.Dialog().yesno(__addonname__line1line2line3)
pDialog.create(__addonname__'Initializing script...')

if 
PCS_YesNo == 1:
    for 
subdir,dirs,files in os.walk(PCS_StartFrom):   
        for 
file in files:
            
filename os.path.join(subdir,file)
            
ext filename[filename.rfind('.'):]
            if 
ext.upper() in PCS_FindExt.upper():
                
PCS_Count += 1
                xx 
Get_exif(filename)
                
# Just Display What I got back from Get_exif() this will tell me if working
                
xbmcgui.Dialog().ok(__addonname__,xx[0],xx[1],file)
                if 
not xbmcvfs.exists(os.path.join(PCS_CopyTo,xx[0],xx[1]),'/'):
                    
success xbmcvfs.mkdirs(os.path.join(PCS_CopyTo,xx[0],xx[1])) 
                
#success = xbmcvfs.copy(filename,os.path.join(PCS_CopyTo,xx[0],xx[1],file))
                #pDialog.update(0,"Copied .. " + file) 
pDialog.close()
xbmcgui.Dialog().ok(__addonname____addon__.getLocalizedString(30104) + " " str(PCS_Count))
# =========================================================== 

it works I see everything I should see
but i dont see the xbmcgui.Dialog().ok(__addonname__,xx[0],xx[1],file)
and i dont see the pDialog But I think that just form running to fast




only Error im seeing in log is

09:46:57 T:140631750236160 ERROR: Misplaced [
09:46:57 T:140631750236160 ERROR: Error parsing boolean expression !String.IsEmpty($INFO[ListItem.PictureOrientatio$
09:46:57 T:140631750236160 ERROR: Misplaced [
09:46:57 T:140631750236160 ERROR: Error parsing boolean expression !String.IsEmpty($INFO[ListItem.PictureProcess])
09:47:19 T:140631750236160 ERROR: GetDirectory - Error getting plugin://script.photo.copier/
09:47:19 T:140631750236160 ERROR: CGUIMediaWindow::GetDirectory(plugin://script.photo.copier/) failed


folder setup like
script.photo.copier
addon.py
addon.xml
changelog.txt
icon.png
LICENSE.txt
/lib
__init__.py
/exifread
all its bits in there
/resources

/language


are there some more manual to read What you see is what i know about python
Reply
#2
you're mixing up scripts and plugins. don't. ;-)

the problem is likely in to be found in your addon.xml file.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
thanks

Think thats were im getting Lost scripts and plugins

heres my addon.xml

PHP Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.photo.copier" name="Photo Copier" version="1.0.0" provider-name="StePhan McKillen">
  <requires>
    <import addon="xbmc.python" version="2.1.0"/>
  </requires>
  <extension point="xbmc.python.pluginsource" library="addon.py">
    <provides>image</provides>
  </extension>
  <extension point="xbmc.addon.metadata">
    <summary lang="en_gb">Copy Photos</summary>
    <description lang="en_gb">Copy Photo BUT looks at date taken
 create a year folder month folder and place photo there
Destination -
                 | Year -
                       | ## ### - (monthnumber monthname) eg 05 May
                                | the files [From Target]                            
</description>
    <disclaimer lang="en_gb"></disclaimer>
    <language>en</language>
    <platform>all</platform>
    <license></license>
    <forum></forum>
    <website></website>
    <email></email>
    <source></source>
  </extension>
</addon> 

look like back to more reading
Reply
#4
change

<extension point="xbmc.python.pluginsource" library="addon.py">
to
<extension point="xbmc.python.script" library="addon.py">

still not working
Reply
#5
(2016-04-03, 04:31)myle Wrote: change

<extension point="xbmc.python.pluginsource" library="addon.py">
to
<extension point="xbmc.python.script" library="addon.py">

still not working

yup, that change is correct.


please post a Debug Log of the error you're getting now.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#6
been testing rewriting code for last week leaning Heaps I Think

2 questions

1. I have

PHP Code:
PCS_FindExt     __addon__.getSetting('FindExt')
..
..
..
..
PCS_StartFrom   xbmcgui.Dialog().browse(0,PCS_Target_Mess,'files',PCS_FindExt.replace(',','|').lower(),True,False,PCS_LastTime

PCS_FindExt = ".JPG,.MPG,.MP4"

is there a way to show the Images in the browser window


Q2.
why am i getting this error
KODI LOG SAYS

for file in os.listdir(os.path.join(PCS_StartFrom)):
OSerror(2,'No such file or directory','smb//BEAST/KODI/temp/')

where PCS_StartFrom = "smb//BEAST/KODI/temp/" <= i have 4 images in the temp folder taken from the xbmcgui.Dialog().browse()
Reply
#7
1 no idea

2 afaik you cn't use the os module to browse smb shares. you should use xbmcvfs instead.
also, not sure if it's a typo, but smb path should start with smb://
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#8
(2016-04-06, 15:09)ronie Wrote: 1 no idea

2 afaik you cn't use the os module to browse smb shares. you should use xbmcvfs instead.
also, not sure if it's a typo, but smb path should start with smb://

Yes that was typo

I try xbmcvfs

Thanks for you help so far Big Grin
Reply
#9
change the for to look at the xbmcvfs

for file, folder in xbmcvfs.listdir(os.path.join(PCS_StartFrom)):

PCS_StartFrom = "/storage/extsd/pic/"

Kodo log says

for file, folder in xbmcvfs.listdir(os.path.join(PCS_StartFrom)):
ValueError: need more than 0 values to unpack

have I got the file , folder right way


I have double check and yes there are 3 .jpg file there

in kodi if I goto file manager and drill down to "/storage/extsd/pic/"
I see the images

still cant see the images in browse window with below command


PCS_StartFrom = xbmcgui.Dialog().browse(0,PCS_Target_Mess,'files',PCS_FindExt.replace(',','|').lower(),True,True,PCS_LastTime)

PCS_FindExt.replace(',','|').lower() is doing its job ".jpg|.mpg|.mp4"

even if i just put the '.jpg' I still dont see anything

pulling hear out here. Huh
Reply
#10
(2016-04-07, 09:24)myle Wrote: change the for to look at the xbmcvfs

for file, folder in xbmcvfs.listdir(os.path.join(PCS_StartFrom)):

PCS_StartFrom = "/storage/extsd/pic/"

Kodo log says

for file, folder in xbmcvfs.listdir(os.path.join(PCS_StartFrom)):
ValueError: need more than 0 values to unpack

have I got the file , folder right way

the error comes from:
Code:
os.path.join(PCS_StartFrom)

in your example, there's no need to use os.path.join()

try this:
Code:
for file, folder in xbmcvfs.listdir(PCS_StartFrom):
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#11
work out the xbmcvfs.listdir()
Reply
#12
update Think im just about there

install it on my main Box which has kodi 17 on it Do like the new skin


if a plug a USB stick in and run it WORKS very happy camper

thought I get SMART

change the Target location "smb://DROBO/Media/Photo/~ToSort"

I get this error

08:33:25 T:139952337602304 WARNING: SMBFile::OpenForWrite() called with overwriting enabled! - smb://192.168.1.5/Media/XBMC/Thumbnails/9/99fbee31.jpg
08:33:25 T:139952625276672 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.IOError'>
Error Contents: (2, 'No such file or directory', 'smb://DROBO/Media/Photo/~ToSort/20141225_200529.jpg')
Traceback (most recent call last):
File "/home/kodi/.kodi/addons/script.photo.copier/addon.py", line 77, in <module>
xx = Get_exif(filename)
File "/home/kodi/.kodi/addons/script.photo.copier/addon.py", line 43, in Get_exif
tags = exifread.process_file(open(f, 'rb'))
IOError: (2, 'No such file or directory', 'smb://DROBO/Media/Photo/~ToSort/20141225_200529.jpg')
-->End of Python script error report<--
08:33:26 T:139954308601856 ERROR: GetDirectory - Error getting plugin://script.photo.copier/
08:33:26 T:139954308601856 ERROR: CGUIMediaWindow::GetDirectory(plugin://script.photo.copier/) failed

here is the New addon.py

PHP Code:
from lib import exifread
import os
systime
import xbmcaddon
xbmcplugin xbmcguixbmc,xbmcvfs
'''
http://mirrors.xbmc.org/docs/python-docs/16.x-jarvis/

This will copy file JPG and look at the date the photo taken
create a destion folder as for the movie file it will look at the date the file
was last Last Modified Date

StartFrom -
          | Year -
                 | ## ### - (monthnumber monthname) eg 05 May 
                          | the files
The reason I formated the month folder number then name only
because its in sort order by its number
'''
# Plugin constants
__addon__     xbmcaddon.Addon()
__addonname__ __addon__.getAddonInfo('name'
# Shared resourse
PCS_CopyTo      __addon__.getSetting('CopyTo')
PCS_MoveThem    __addon__.getSetting('MoveThem')
PCS_FindExt     __addon__.getSetting('FindExt')
PCS_Target_Mess __addon__.getLocalizedString(30103)
PCS_LastTime    __addon__.getSetting('LastTime')
PCS_Debug       __addon__.getSetting('Debug')
PCS_OverWrite   __addon__.getSetting('Overwrite')
PCS_ext         =""
PCS_MonName     = [' ','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
PCS_StartFrom   xbmcgui.Dialog().browse(0,PCS_Target_Mess,'files',PCS_FindExt.replace(',','|').lower(),True,True,PCS_LastTime)
__addon__.setSetting('LastTime',PCS_StartFrom)
PCS_Count 0
if PCS_Debug == "true":
    
PCS_Debug 1
else:
    
PCS_Debug 

xbmc
.log(__addonname__ ' Initializing script...',PCS_Debug)

#
def Get_exif(f):
    
tags exifread.process_file(open(f'rb'))
    
ItsFile os.path.basename(f)
    
#print "comment :%s" % tags['EXIF UserComment']
    
if tags not in ('JPEGThumbnail''TIFFThumbnail''Filename''EXIF MakerNote'):
        try: 
# try and read the EXIF DateTimeOriginal
            
ctime time.strptime(str(tags['EXIF DateTimeOriginal']), '%Y:%m:%d %H:%M:%S')
            
This_Month '%s %s' % (str(ctime.tm_mon),PCS_MonName[ctime.tm_mon])
            return 
str(ctime.tm_year),This_Month,ItsFile
        except KeyError
# Bugger can't read it so i get the date is was Last Modified
            
ctime time.strptime(time.ctime(os.path.getmtime(f)),"%a %b %d %H:%M:%S %Y")
            
This_Month '%s %s' % (str(ctime.tm_mon),PCS_MonName[ctime.tm_mon])
            return 
str(ctime.tm_year),This_Month,ItsFile

# This is for testing am i doing it right  

dirsfiles xbmcvfs.listdir(os.path.join(PCS_StartFrom))

              
line1 "FROM >> " PCS_StartFrom
line2 
""
line3 "TO >> " PCS_CopyTo " YYYY " "m MMM"
# for file, folder in xbmcvfs.listdir(os.path.join(PCS_StartFrom)):
PCS_YesNo xbmcgui.Dialog().yesno(__addonname__line1line2line3)
if 
PCS_YesNo == 1:
    for 
file in files:
        
filename os.path.join(PCS_StartFrom,file)
        
xbmc.log('Found : ' file ,PCS_Debug)
        
#xbmcgui.Dialog().ok(__addonname__,filename)
        
PCS_ext os.path.splitext(filename)[1][1:].strip().upper()
        
xbmc.log('EXT :' PCS_ext,PCS_Debug)
        if 
PCS_ext in PCS_FindExt.upper():
            
#xbmcgui.Dialog().ok(__addonname__,'Working on :' + filename, str(PCS_Debug))
            
PCS_Count += 1
            xx 
Get_exif(filename)
            
#xbmcgui.Dialog().ok(__addonname__,'Working :','Year '+xx[0],'Month '+ xx[1])
            
success xbmcvfs.exists(os.path.join(PCS_CopyTo,xx[0],xx[1]))
            
#xbmcgui.Dialog().ok(__addonname__, str(success))
            
success xbmcvfs.mkdirs(os.path.join(PCS_CopyTo,xx[0],xx[1])) 
            
#xbmcgui.Dialog().ok(__addonname__, str(success))
            
success xbmcvfs.copy(filename,os.path.join(PCS_CopyTo,xx[0],xx[1],file))
xbmcgui.Dialog().notification(__addonname__"Copied " str(PCS_Count) + " Files")

# =========================================================== 

could some point why the smb to smb error and i check said image is there
Reply
#13
(2016-04-07, 22:46)myle Wrote: 08:33:26 T:139954308601856 ERROR: GetDirectory - Error getting plugin://script.photo.copier/
08:33:26 T:139954308601856 ERROR: CGUIMediaWindow::GetDirectory(plugin://script.photo.copier/) failed

there's still a problem with your addon.xml file.
you are creating a script, not a plugin. looks you are still using the pluginsource extension point...

(2016-04-07, 22:46)myle Wrote:
Code:
tags = exifread.process_file(open(f, 'rb'))

python has no support for smb:// files. you need to use xbmcvfs for all file operations.

i'm not familiar with the exifread module, but chances are you might need to modify it as well to get it to work with smb:// files (if possible at all).
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#14
thanks ronie

Will read more

tested it on a android kodi worked Smile
tested on a apple runing kodi it worked Smile

smb to smb is not a problem for me that was part of the testing

I built it getting my photos off the Camera in into kodi which it doing easy as

Just plug the camera into KODI run the script and photos on server sorted into there folders job done
THANKS again for you help
next time see in a pub i bye the beers

but will fix the plugin error

about change the exifread module that be over my head at this point of time.
Reply

Logout Mark Read Team Forum Stats Members Help
help with my Plugin0