Kodi Community Forum
[RELEASE] TV Show Next Aired (Script) Addon - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: Add-on Support (https://forum.kodi.tv/forumdisplay.php?fid=27)
+---- Forum: Program Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=151)
+---- Thread: [RELEASE] TV Show Next Aired (Script) Addon (/showthread.php?tid=79493)



RE: [RELEASE] TV Show Next Aired (Script) Addon - rbiez - 2012-10-25

(2012-10-25, 01:18)ronie Wrote: i'm afraid i can't follow your logic.

the script already converts the scraped datetime to your local date&time (see def localize_show_datetime(self, current_show))
and uses the local date & time throughout the rest of the script.

so if a show is listed as 2012-10-24 21:00:00 -0400UTC on tvrage
it will show up in the tv guide as being aired on the 25th at 02:00 (if you're in gmt+1)

I know, all my shows, except for the ones airing "today" works fine, with correct date and time, adjusted to localized timezones.
Believe it has to do with tvrage, as they dont do the timezone localization, hence the "nextdate" will always be pushed ahead one week, and instead you have to compare to latest episode to get it right..


RE: [RELEASE] TV Show Next Aired (Script) Addon - jurrabi - 2012-11-05

Yesterday I found a string encoding issue in the script in frodo.

From the first post I guess there is no official support for frodo yet in this script. Is this right?

Anyway, right now (I'm at work and don't have xbmc access here) I can't confirm script version or details about the error.

But, as with many other python scripts for xbmc, the problem resides in the handling of no ascii strings, mainly related with file paths. This arises more in windows with non-English file systems where non-utf8 file encoding is used.

I found also an easy fix. I can't precise more right now (I found errors in 3 other scripts yesterday and have the causes all mixed in my head).

I can post it here later (if you are interested) or do a pull request if you let me know where the official repository resides.


RE: [RELEASE] TV Show Next Aired (Script) Addon - ronie - 2012-11-05

(2012-11-05, 17:40)jurrabi Wrote: Yesterday I found a string encoding issue in the script in frodo.

From the first post I guess there is no official support for frodo yet in this script. Is this right?

Anyway, right now (I'm at work and don't have xbmc access here) I can't confirm script version or details about the error.

But, as with many other python scripts for xbmc, the problem resides in the handling of no ascii strings, mainly related with file paths. This arises more in windows with non-English file systems where non-utf8 file encoding is used.

I found also an easy fix. I can't precise more right now (I found errors in 3 other scripts yesterday and have the causes all mixed in my head).

I can post it here later (if you are interested) or do a pull request if you let me know where the official repository resides.

all true, many addon (developpers) struggle with it.
for me, it's the most annoying thing in python.

looking forward to hear all the details Smile


RE: [RELEASE] TV Show Next Aired (Script) Addon - jurrabi - 2012-11-06

Ups, couldn't yesterday. Promise it will come today.

(2012-11-05, 18:56)ronie Wrote: all true, many addon (developpers) struggle with it.
for me, it's the most annoying thing in python.

Totally agree. I think the problem is a combination of really poor string encoding support in python 2 (why does it assume all strings to be ascii if you don't say otherwise?) and lack of perspective from programmers.

Me, as I'm Spanish borne and worked with data interfaces all my life, encoding issues have been my bread for many years.

Just for arguing sakes, I leave here a piece of my mind about python encoding support: in my opinion string encoding issues in python 2 would go away if they just added the "encoding" attribute to srt objects. That way implicit decodings and encodings (that happen all the time without the knowledge of programmers and are the source of most unicode decode errors) wouldn't have to assume (incorrectly most of the time) anything and conversions will work almost always. I can't understand why something so implicit to the nature of the content of a variable (totally analog for strings to the type of number - integer signed/unsigned, float, etc) is not stored in the variable...

As far as I know (haven't played with it yet, just now some bit I have read on papers) python 3 doesn't address the issue at all. Their solution is to go "all unicode". But if you need (or are forced) to work with str objects (for interfacing or compatibility) you have to keep track manually of the encoding every str object uses...



RE: [RELEASE] TV Show Next Aired (Script) Addon - jurrabi - 2012-11-06

Can you tell me where is the home repository of this addon? (if it is public, of course)


RE: [RELEASE] TV Show Next Aired (Script) Addon - ronie - 2012-11-06

(2012-11-06, 22:27)jurrabi Wrote: Can you tell me where is the home repository of this addon? (if it is public, of course)

the repo for next aired (as well as all my other addons) is:
https://code.google.com/p/ronie/

if you want commit access, just pm me the email address associated with your google account.


RE: [RELEASE] TV Show Next Aired (Script) Addon - jurrabi - 2012-11-07

OK. I have reviewed the changes I did to the script to fix the encoding errors. First here is a log of a sample Crash (not the full log, just the python error): http://pastebin.com/vuZpMNux

You can see that I use to check for encoding issues a windows portable installation in a path with non-ascii chars (C:\Users\Jesús\) This always troubles scripts that doesn't keep track in their programming that each str variable is encoded either using "utf-8" (all strings returned by xbmc modules) or "mbcs" (Python uses the name “mbcs” to refer to whatever the currently configured encoding is for the filesystem. Don't know how it handles when the system has 2 filesystems with different encodings, if that's possible).

When programming if you don't want to keep in mind the encoding of each srt variable the easiest thing to do is decode them (to unicode) as soon as you load them. Luckily most Python standard libraries and xbmc modules accept unicode variables perfectly. And for the ones that don't you can encode on the fly to the adequate encoding (I have never needed to encode for a system call. Just a few xbmc calls require utf-8 strs).

But enough bla bla lets check TV Show Next Aired Problems...

In the log we see the error:
Code:
File "C:\Users\Jesús\Programas\XBMC12\portable_data\addons\script.tv.show.next.aired\default.py", line 140, in update_data
                                                elif time() - os.path.getmtime(dbfile) > 86400:
...
                                            WindowsError: (3, 'El sistema no puede encontrar la ruta especificada', 'C:\\Users\\Jes\xc3\xbas\\Programas\\XBMC12\\portable_data\\userdata\\addon_data\\script.tv.show.next.aired\\next_aired.db')
This spanish texts means that the system can't find the path. That is because we passed a utf-8 encoded string to a system call when the filesystem encoding is "latin". So the path in fact doesn't exist.
And how do I know dbfile is utf-8 encoded? Let's backtrack the code:

Line 140: elif time() - os.path.getmtime(dbfile) > 86400: #dbfile is defined in:
Line 134: dbfile = os.path.join( DATA_PATH , "next_aired.db" ) #DATA_PATH is defined in:
Line 23: DATA_PATH = os.path.join( xbmc.translatePath( "special://profile/addon_data/" ), __addonid__ )

So in the beginning DATA_PATH is obtained from a call to a xbmc module (translatePath) that is passed to a system call (os.path.join).
This, in concept, is already a programming error since we are giving a system call (that accepts unicode or "mbcs" encoded strings) a "utf-8" encoded string. In the practice this kind of works because all os.path.join does is appending strings with the adecuate path separator ("\" or "/" depending on the system) so we get a string path encoded with "utf-8".

But this utf-8 encoding is not good for os.path.getmtime in line 140 and we get the "file not found" error

One way to fix this specific problem will be to decode/reencode the dbfile string adequately:
Code:
elif time() - os.path.getmtime(dbfile.decode("utf-8").encode("mbcs")) > 86400:

This fix that crash, but is not the nicest solution, nor my style. Also we will get more errors from the implicit error in DATA_PATH.

As I said in the beginning the best way is to decode things to unicode as soon as we get the value. Most modules will work fine with unicode.

So finally this are the changes I did (I have to declare that I'm doing the changes again as I write this because when I got the old version back to compare the changes I destroyed the new version DAHH Sad ):

Line 17: __cwd__ = __addon__.getAddonInfo('path').decode("utf-8")
Line 23: DATA_PATH = os.path.join( xbmc.translatePath( "special://profile/addon_data/" ).decode("utf-8"), __addonid__ )
Line 24: RESOURCES_PATH = xbmc.translatePath( os.path.join( __cwd__, 'resources' ).encode("utf-8") ).decode("utf-8") #When in doubt I prefer to pass xbmc modules utf-8 strings and then decode to unicode the final path
Line 37: #Redefine the whole log procedure:
def log(txt): #Changes to admit both unicode strings and str encoded with "utf-8" (or ascii). will fail with other encodings.
> if isinstance (txt,str):
>> txt = txt.decode("utf-8")
#if it is str we assume it's "utf-8" encoded. will fail if called with other encodings (latin, etc) BE ADVISED!
#At this point we are sure txt is a unicode string.
> message = u'%s: %s' % (__addonid__, txt)
> xbmc.log(msg=message.encode("utf-8"), level=xbmc.LOGDEBUG

Sorry about the formatting. I have to go pick up my wife and don't have any more time. I hope it is good enough.

If needed I can push the changes or send a diff or whatever you think is convenient.

Cheers.


RE: [RELEASE] TV Show Next Aired (Script) Addon - jurrabi - 2012-11-07

(2012-11-06, 23:14)ronie Wrote: if you want commit access, just pm me the email address associated with your google account.

I leave it to your preferences. Review the proposed changes and if you like them and you want I can push them this evening.

I'll pm the gmail account just in case.


RE: [RELEASE] TV Show Next Aired (Script) Addon - Martijn - 2012-11-07

(2012-11-07, 09:48)jurrabi Wrote:
(2012-11-06, 23:14)ronie Wrote: if you want commit access, just pm me the email address associated with your google account.

I leave it to your preferences. Review the proposed changes and if you like them and you want I can push them this evening.

I'll pm the gmail account just in case.

Perhaps placing it on Git would be easier to use?



RE: [RELEASE] TV Show Next Aired (Script) Addon - ronie - 2012-11-08

(2012-11-07, 09:48)jurrabi Wrote:
(2012-11-06, 23:14)ronie Wrote: if you want commit access, just pm me the email address associated with your google account.

I leave it to your preferences. Review the proposed changes and if you like them and you want I can push them this evening.

I'll pm the gmail account just in case.

thanx a lot jurrabi !
your comments are spot on, xbmc.log() has been giving me headaches for as long as i can remeber.
no matter what combinations i tried, it always seemed to unicodedecode error on me one way or another.

the path thing, i was aware of and i'd already changed it in several script...
though i have to admit i never fully understood the why, when and how's about it.

i'll make the needed changes to next aired in a bit.
i've granted you commit access as well, so in the future to commit whatever you see fit.


cheers,
ronie


RE: [RELEASE] TV Show Next Aired (Script) Addon - ronie - 2012-11-08

(2012-11-07, 10:00)Martijn Wrote: Perhaps placing it on Git would be easier to use?

git? easyHuh?


let's jus say, old habbits die hard.

* ronie just looooves svn


RE: [RELEASE] TV Show Next Aired (Script) Addon - jurrabi - 2012-11-08

(2012-11-08, 02:35)ronie Wrote: git? easyHuh?


let's jus say, old habbits die hard.

* ronie just looooves svn

I also was a svn guy. But since everybody was going to github I had to finally abdicate. I don't even have svn anymore installed (I guess I will have to with you Wink

In my opinion there is no one option that can be considered the best. For windows folks svn was the best choice for a long time thanks to tortoise (best windows development tool ever).
And I have to recognize github is quite friendly. I like to be able to fix things in a web browser...

So... role with the dice man.



RE: [RELEASE] TV Show Next Aired (Script) Addon - road king - 2012-11-12

Hello. I am having an issue with this script where it is serching all my canceld/ ended shows every time i launch it. so it takes a long time to finish (anound 15 - 20 minutes. I have a lot of shows) On the first post in this thred is says "it remembesr canceled/ended shows to not scrap website again in this case" can anyone saggest a fix for me?

I am using version 4.1.24 on Eden on windows 7

Thanks


RE: [RELEASE] TV Show Next Aired (Script) Addon - ronie - 2012-11-12

(2012-11-12, 05:10)road king Wrote: Hello. I am having an issue with this script where it is serching all my canceld/ ended shows every time i launch it. so it takes a long time to finish (anound 15 - 20 minutes. I have a lot of shows) On the first post in this thred is says "it remembesr canceled/ended shows to not scrap website again in this case" can anyone saggest a fix for me?

thanx for the heads up.
not sure why, but it wasn't implemented in the script at all...

please test:
script.tv.show.next.aired-5.0.0.zip
and let me know if i broke anything Smile


RE: [RELEASE] TV Show Next Aired (Script) Addon - road king - 2012-11-16

(2012-11-12, 22:32)ronie Wrote: thanx for the heads up.
not sure why, but it wasn't implemented in the script at all...

please test:
script.tv.show.next.aired-5.0.0.zip
and let me know if i broke anything Smile


Thanks for the reply, I tried to install the file you gave me via the install from .ZIP option in the addons manager, but it says "Dependences not met" In the log it says "ERROR: Texture manager unable to load file: D:\script.tv.show.next.aired-5.0.0.zip\icon.png"

I tried replacing the icon.png with the one from the already installed script but i get the same.

I also tried replaceing the contents of "C:\Users\Jethro\AppData\Roaming\XBMC\addons\script.tv.show.next.aired" with the contents ot the script.tv.show.next.aired folder in the .ZIP you gave me and then restarting XBMC, but it still scans all the shows and takes a long time doing it.