xbmcvfs.translatePath not working in Android
#16
(2023-07-16, 14:59)lpence Wrote: 2023-07-16 08:55:53.740 T:31404   debug <general>: My addon's special path is: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.rtd/
2023-07-16 08:55:53.740 T:31404   debug <general>: My addon's translated addon path is: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.rtd/
2023-07-16 08:55:53.740 T:31404   debug <general>: My addon's special profile path is: special://profile/addon_data/plugin.video.rtd/
2023-07-16 08:55:53.740 T:31404   debug <general>: My addon's translated profile path is: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/userdata/addon_data/plugin.video.rtd/

2023-07-16 08:55:53.741 T:31404   debug <general>: My DB file was not found
That is the correct path for Android, so if you're using the example code from above, either your DB file is named something different (BTW, capitalization matters on several platforms) or there is an Android permissions issue that means Kodi can't see the db file.
Reply
#17
(2023-07-16, 15:12)pkscout Wrote:
(2023-07-16, 14:59)lpence Wrote: 2023-07-16 08:55:53.740 T:31404   debug <general>: My addon's special path is: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.rtd/
2023-07-16 08:55:53.740 T:31404   debug <general>: My addon's translated addon path is: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.rtd/
2023-07-16 08:55:53.740 T:31404   debug <general>: My addon's special profile path is: special://profile/addon_data/plugin.video.rtd/
2023-07-16 08:55:53.740 T:31404   debug <general>: My addon's translated profile path is: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/userdata/addon_data/plugin.video.rtd/

2023-07-16 08:55:53.741 T:31404   debug <general>: My DB file was not found
That is the correct path for Android, so if you're using the example code from above, either your DB file is named something different (BTW, capitalization matters on several platforms) or there is an Android permissions issue that means Kodi can't see the db file.
Thanks, I will double check my android permissions and let you know because my db file does not have capitalization..."rtd_films.db"
Reply
#18
(2023-07-17, 01:48)lpence Wrote:
(2023-07-16, 15:12)pkscout Wrote:
(2023-07-16, 14:59)lpence Wrote: 2023-07-16 08:55:53.740 T:31404   debug <general>: My addon's special path is: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.rtd/
2023-07-16 08:55:53.740 T:31404   debug <general>: My addon's translated addon path is: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.rtd/
2023-07-16 08:55:53.740 T:31404   debug <general>: My addon's special profile path is: special://profile/addon_data/plugin.video.rtd/
2023-07-16 08:55:53.740 T:31404   debug <general>: My addon's translated profile path is: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/userdata/addon_data/plugin.video.rtd/

2023-07-16 08:55:53.741 T:31404   debug <general>: My DB file was not found
That is the correct path for Android, so if you're using the example code from above, either your DB file is named something different (BTW, capitalization matters on several platforms) or there is an Android permissions issue that means Kodi can't see the db file.
Thanks, I will double check my android permissions and let you know because my db file does not have capitalization..."rtd_films.db"
I don't want to get nitpicky, but in your first post you had this:
python:
DB_FILMS_FILE = "films.db"

But above you reference "rtd_films.db."  Are you sure your code is looking for the right database name?
Reply
#19
(2023-07-17, 13:35)pkscout Wrote:
(2023-07-17, 01:48)lpence Wrote:
(2023-07-16, 15:12)pkscout Wrote: That is the correct path for Android, so if you're using the example code from above, either your DB file is named something different (BTW, capitalization matters on several platforms) or there is an Android permissions issue that means Kodi can't see the db file.
Thanks, I will double check my android permissions and let you know because my db file does not have capitalization..."rtd_films.db"
I don't want to get nitpicky, but in your first post you had this:
python:
DB_FILMS_FILE = "films.db"

But above you reference "rtd_films.db."  Are you sure your code is looking for the right database name?
Yep, The correct file name is "rtd_films.db" ! 
Question: when you talk about capitalization, do you also refer to for example this 'DB_FILMS_FILE =' ... Should I change that one to be on the safe side?
Reply
#20
(2023-07-17, 13:46)lpence Wrote:
(2023-07-17, 13:35)pkscout Wrote:
(2023-07-17, 01:48)lpence Wrote: Thanks, I will double check my android permissions and let you know because my db file does not have capitalization..."rtd_films.db"
I don't want to get nitpicky, but in your first post you had this:
python:
DB_FILMS_FILE = "films.db"

But above you reference "rtd_films.db."  Are you sure your code is looking for the right database name?
Yep, The correct file name is "rtd_films.db" ! 
Question: when you talk about capitalization, do you also refer to for example this 'DB_FILMS_FILE =' ... Should I change that one to be on the safe side?
Python variables are case sensitive, but you'll normally get errors about a variable not existing if you use it before it's created.  So that probably isn't an issue here.
Reply
#21
I reviewed Android permissions and changed some code capitalization to lower. I keep getting following error:

2023-07-19 14:27:25.317 T:16037   debug <general>: CPythonInvoker(9, /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.rtd/addon.py): instantiating addon using automatically obtained id of "plugin.video.rtd" dependent on version 3.0.0 of the xbmc.python api
2023-07-19 14:27:25.384 T:15817   debug <general>: ------ Window Init (DialogBusy.xml) ------
2023-07-19 14:27:25.561 T:16037   error <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                                    - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                                   Error Type: <class 'sqlite3.OperationalError'>
                                                   Error Contents: unable to open database file
                                                   Traceback (most recent call last):
                                                     File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.rtd/addon.py", line 827, in <module>
                                                       plugin = RTD()
                                                                ^^^^^
                                                     File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.rtd/addon.py", line 91, in __init__
                                                       self._process_request()
                                                     File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.rtd/addon.py", line 122, in _process_request
                                                       self._create_submenu_films(urlparam)
                                                     File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.rtd/addon.py", line 223, in _create_submenu_films
                                                       with self.connect_films_db() as db_con:
                                                            ^^^^^^^^^^^^^^^^^^^^^^^
                                                     File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.rtd/addon.py", line 205, in connect_films_db
                                                       db_con = sqlite3.connect(db_films)
                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^
                                                   sqlite3.OperationalError: unable to open database file
                                                   -->End of Python script error report<--
Reply
#22
This code snipped for this section: 
Code:
db_films_name = "rtd_films.db"
db_films = xbmcvfs.translatePath("special://profile/addon_data/%s/%s" % (PLUGIN_NAME, db_films_name))

    def connect_films_db(self):
        """Connect to films database and create one if it does not exist."""
        db_con = sqlite3.connect(db_films)
        c = db_con.cursor()

        try:
            c.execute("SELECT * FROM films;")
        except sqlite3.OperationalError:
            c.execute("""CREATE TABLE films (
                            title TEXT PRIMARY KEY,
                            poster TEXT,
                            player_link TEXT
                         );""")
            db_con.commit()

        return db_con                                                                           
                                     
    def _create_submenu_films(self, urlparam):
        Texture13DB.clean_database()    
        category = urlparam.split("=")[1]
        with self.connect_films_db() as db_con:
            c = db_con.cursor()        
            self._create_films_list(category, c, db_con)
Reply
#23
(2023-07-19, 21:06)lpence Wrote: db_films_name = "rtd_films.db"
db_films = xbmcvfs.translatePath("special://profile/addon_data/%s/%s" % (PLUGIN_NAME, db_films_name))

A couple of suggestions here.  First, I would instrument the db_films variable before passing it to sqlite3.connect just to ensure you have the file name right.  The error you are getting says it isn't.  Add something like:

Code:
db_films_name = "rtd_films.db"
db_films = xbmcvfs.translatePath("special://profile/addon_data/%s/%s" % (PLUGIN_NAME, db_films_name))
xbmc.log('The value of db_films is: ' + str(db_films) ,  xbmc.LOGINFO)

This will write a message to the kodi.log file so you can see what is going on.  You can change it to LOGDEBUG once you get it working.

Second, the more root cause issue is that I do not believe you can append / join a path this way with Python and xbmcvfs.translatePath across all platforms.  I've always used os.path.join with xbmcvfs.translatePath.  See https://github.com/Conceiva/MezzmoKodiPl...b/media.py lines  176 - 183, with the main focus on line 182.   This is a sample from one of my addons.

Your way may be right.  I can only tell you that I've had no problem on android with my method.


Thanks,

jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#24
(2023-07-20, 01:53)jbinkley60 Wrote: lines  176 - 183

just to be informative, if you are not aware you can link code on github and highlight a section you are talking about - https://github.com/Conceiva/MezzmoKodiPl...#L176,L183
Reply
#25
(2023-07-20, 01:59)jepsizofye Wrote: you can link code on github and highlight a section you are talking about - https://github.com/Conceiva/MezzmoKodiPl...#L176,L183

Thank you. I did not know that. I will use it in the future.

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#26
(2023-07-20, 01:53)jbinkley60 Wrote:
(2023-07-19, 21:06)lpence Wrote: db_films_name = "rtd_films.db"
db_films = xbmcvfs.translatePath("special://profile/addon_data/%s/%s" % (PLUGIN_NAME, db_films_name))

A couple of suggestions here.  First, I would instrument the db_films variable before passing it to sqlite3.connect just to ensure you have the file name right.  The error you are getting says it isn't.  Add something like:

Code:
db_films_name = "rtd_films.db"
db_films = xbmcvfs.translatePath("special://profile/addon_data/%s/%s" % (PLUGIN_NAME, db_films_name))
xbmc.log('The value of db_films is: ' + str(db_films) ,  xbmc.LOGINFO)

This will write a message to the kodi.log file so you can see what is going on.  You can change it to LOGDEBUG once you get it working.

Second, the more root cause issue is that I do not believe you can append / join a path this way with Python and xbmcvfs.translatePath across all platforms.  I've always used os.path.join with xbmcvfs.translatePath.  See https://github.com/Conceiva/MezzmoKodiPl...b/media.py lines  176 - 183, with the main focus on line 182.   This is a sample from one of my addons.

Your way may be right.  I can only tell you that I've had no problem on android with my method.


Thanks,

jeff
Thanks Jeff, I will try the code sample from you addon. In the mean time here is what I get from the xbmc.log. I beleive is correct:

2023-07-19 20:33:53.103 T:12664    info <general>: The value of db_films is: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/userdata/addon_data/plugin.video.rtd/rtd_films.db
Reply
#27
@Jeff
Would you tell me how to implement the proposed code into the one I posted above. I want to be sure how I use it. tks
Reply
#28
(2023-07-20, 02:50)lpence Wrote:
(2023-07-20, 01:53)jbinkley60 Wrote:
(2023-07-19, 21:06)lpence Wrote: db_films_name = "rtd_films.db"
db_films = xbmcvfs.translatePath("special://profile/addon_data/%s/%s" % (PLUGIN_NAME, db_films_name))

A couple of suggestions here.  First, I would instrument the db_films variable before passing it to sqlite3.connect just to ensure you have the file name right.  The error you are getting says it isn't.  Add something like:

Code:
db_films_name = "rtd_films.db"
db_films = xbmcvfs.translatePath("special://profile/addon_data/%s/%s" % (PLUGIN_NAME, db_films_name))
xbmc.log('The value of db_films is: ' + str(db_films) ,  xbmc.LOGINFO)

This will write a message to the kodi.log file so you can see what is going on.  You can change it to LOGDEBUG once you get it working.

Second, the more root cause issue is that I do not believe you can append / join a path this way with Python and xbmcvfs.translatePath across all platforms.  I've always used os.path.join with xbmcvfs.translatePath.  See https://github.com/Conceiva/MezzmoKodiPl...b/media.py lines  176 - 183, with the main focus on line 182.   This is a sample from one of my addons.

Your way may be right.  I can only tell you that I've had no problem on android with my method.


Thanks,

jeff
Thanks Jeff, I will try the code sample from you addon. In the mean time here is what I get from the xbmc.log. I beleive is correct:

2023-07-19 20:33:53.103 T:12664    info <general>: The value of db_films is: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/userdata/addon_data/plugin.video.rtd/rtd_films.db

The file name looks right, although I'd typically create a new folder below plugin.video.rtd (i.e. plugin.video.rtd/databases/ ) or use the Kodi databases folder like I did.  I used the Kodi databases folder to avoid issue with addon updates impacting the database file.  Note that for SQLite connections the folder must be writable with a 755 type of permissions.  This is because SQlite writes temporary files into the folder when processing database requests. So ensure that plugin.video.rtd has this level of permissions or you will get the same error.


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#29
(2023-07-20, 03:16)lpence Wrote: @Jeff
Would you tell me how to implement the proposed code into the one I posted above. I want to be sure how I use it. tks
Try:

Code:
db_films = os.path.join(xbmcvfs.translatePath("special://profile/addon_data/"), PLUGIN_NAME, db_films_name)


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#30
(2023-07-20, 02:50)lpence Wrote: 2023-07-19 20:33:53.103 T:12664    info <general>: The value of db_films is: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/userdata/addon_data/plugin.video.rtd/rtd_films.db

I looked at your path again and I think you are on the right track with regard to using the profile addon_data approach.  No subfolder should be needed.  This feels like a folder permissions issue.  You could try a different special protocol path like special://home or special://database to see if they work.  That will tell you whether it is a permissions vs. code issue.


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply

Logout Mark Read Team Forum Stats Members Help
xbmcvfs.translatePath not working in Android0