Flickr Plugin

whoops...I started another plugin
Howdy folks,

I started to build a Plex plugin for Flickr.

I've not done much yet other than get the base plugin up and running with resource and locale support. I've been having a good dig about in the Flickr API and it doesn't look to bad. There are numerous python api's about so I just need to pick one or take the decision to parse atoms manually.

I dont really user Flickr so I figured I'd better at least use it for something to figure out people's usage patterns. What better use than for hosting screenshots of the plugin itself LOL (It would be rude to put them under picasa or photobucket).

So - a way to go but at least its a start.

The Plugin registered in photo sources



The Plugin's preferences item.



As more stuff happens I'll post more pictures into this [Flickr Set](http://www.flickr.com/photos/iandgratton/sets/72157618879464570/)

Once it does something useful I'll put up a non-release download so you can give it a try.

more power to you! please, please implement search for photos and people… i am expecting this plugin anxiously already for some time. thanks!




So what is the plugin supposed to do -- I market dating sites and might be able to use it.

Well,



making some good progress with the plugin.



I’m using Sybren Stuvel’s Python Flickr API which can be found here.



I can now

[list]

[]View the users recent photos

[
]View the users photo sets and photographs within

[]View the users contacts and browse by photo set or tag

[/list]I think the other types of functionality I’ll be able to implement are:

[list]

[
]View a lst of a users favorite photos

[]View photos by most popular tags on flickr

[
]View a list of groups that the user belongs to and view by photo set or tag

Search for groups (there is no way get a full list of groups without authentication) and by photo sets, tags, members

[/list]The services on flickr make this a little more complex than the Picasa plugin but should hopefully give a nice rich browsing experience. I’ll post up some more screenshots soon.

Few more bits done:



Photostream view




Individual image view with non-exif metadata from flickr.



Hopefully do some more soon and then maybe version 0.1 for some feedback.

looks good! patiently waiting…

Looking awesome, Ian! My favorite is the “interesting” photos section.

can’t wait to test it. one of the first things i ever searched a plugin for - and never found. Thanks a bunch.

Right folks,



I’ve just made a very early version (0.1) of this available via the Flickr page on the Plex Wiki.



If you wish to view your photostream within the plugin you need to know your Flickr Screen Name. This is not the name that appears in your flickr URL (i.e. http://www.flickr.com/photos/rebel)) but your Screen Name that you have configured (you can see if this at the top of your photostream page).



I’ll do some context-specific icons once the functionality has been checked over along with implementing searches via tag and keyword etc.



As always your feedback is appreciated.

hi, i am checking it out, but i can not get to my photostream. my screen name is the same as the “URL” name. could it be that i am not a “pro” on flickr yet? on my photostream it is written just “Your photostream”.



my flickr link



Howdy,

thanks for taking the time to try out the plugin.
You don't need to have a pro account on flickr for this to work (i don't have a pro account either) as all items viewed are public. The plugin currently has no support for viewing of private items.

if you configure the plugin with 'orr721' as the username it works. I've just tried it and I can see your recent photos. You visited an aviation display recently correct ?

When I try and view your photosets or tags I dont get anything back. This is because of the following error appearing in the plugins log file (you can keep an eye on whats happening by looking in ~/Library/Logs/PMS Plugin Logs/com.plexapp.plugins.flickr.log)


 18:09:33.322972: com.plexapp.plugins.flickr			  :   (Framework) An exception happened:<br />
	Traceback (most recent call last):<br />
	  File "/Users/idg/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/Plugin.py", line 464, in __call<br />
		return function(*args, **kwargs)<br />
	  File "/Users/idg/Library/Application Support/Plex Media Server/Plug-ins/Flickr.bundle/Contents/Code/__init__.py", line 656, in GetTags<br />
		Log("Adding tag '%s'" % tag.text)<br />
	  File "/Users/idg/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/__init__.py", line 16, in Log<br />
		sys.stderr.write("%s
" % msg)<br />
	UnicodeEncodeError: 'ascii' codec can't encode character u'\u010d' in position 77: ordinal not in range(128)<br />
	<br />
	18:09:33.323113: com.plexapp.plugins.flickr			  :   (Framework) Request not handled by plug-in



now Flickr claim all their data is UTF-8 based so there shouldn't be any encoding problems. I came across this issue last night when I was navigating down the contacts tree and attempting to view a friend of a friends sets. It seems to happen for either tags or set names which is quite strange.

I'll have a see if I can get to the bottom of it.

The 'tag' that is causing the encoding problem is 'lamač' (but you have others with accented characters) - I've stopped my code from breaking by correctly encoding the data before it goes back into Plex. The next error I get is from within the Plex plugin framework itself:


 Traceback (most recent call last):<br />
   File "/Users/idg/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/Plugin.py", line 346, in __run<br />
	 resultStr = result.Content()<br />
   File "/Users/idg/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/Objects.py", line 109, in Content<br />
	 return XML.StringFromElement(self.ToElement())<br />
   File "/Users/idg/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/Objects.py", line 177, in ToElement<br />
	 root.append(item.ToElement())<br />
   File "/Users/idg/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/Objects.py", line 274, in ToElement<br />
	 return XMLObject.ToElement(self)<br />
   File "/Users/idg/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/Objects.py", line 105, in ToElement<br />
	 el.set(key, unicode(self.__dict__[key]))<br />
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 38: ordinal not in range(128)



I'll post up a fixed version once we've gotten to the bottom of the issue. I guess this problem could occur for any photoset, tag, contact name, photo title etc. that has accented characters within it.

thank you very much for making it work. yes, you are correct, i use tags with accented characters, as english is not my native language, and i have several friends / family members who do not speak english at all. i just hope it is not a problem in the xml file on the flickr side.



(OT xml is such a screw up on foreign languages for not supporting UTF-8 natively. i have several programs crashing for not escaping/encoding non.ASCII characters correctly in XML! it is just stupid not to use UTF-8 in 21st century).



Hi again,

we were taking a look at this issue the other night and its definately encoding thats causing the issue. There is nothing wrong with the data that comes back from the flickr api - its just some issues surrounding encoding within the plugin or possibly higher up in the plugin framework.

The elements that come back from flickr look like


 <tags><br />
	 ...<br />
	 <tag>foo</tag><br />
	 <tag>bar</tag><br />
	 ...<br />
 </tags>



A 's text() element with std characters in it has the type with the ElementTree libraries - if it has accented characters it comes back as type . Hopefully I'll get a chance to take a look at this before the end of the week. If not I'm away for a week.

i’ve been doing a bit more research regarding the issue we are seeing with errors such as:



UnicodeDecodeError: 'ascii' codec can't decode byte 0x??? in position n: ordinal not in range(128)


my hunch was it had to be something to do with the plugin process thinking its default codec for strings is ascii. Being a bit new to python I had a peep about in the sys package to see if it could help based upon some of the articles I'd read regarding the joys of and transpancey in programs. They make for some good background reading. Typical internet applications and services provide and consume data that is not locked onto a specific locale or character set.

[What I Thought I Knew About Unicode in Python Amounted To Nothing](http://farmdev.com/thoughts/23/what-i-thought-i-knew-about-unicode-in-python-amounted-to-nothing/)
[Do I hate Unicode, or Do I Hate ASCII?](http://blog.ianbicking.org/do-i-hate-unicode-or-do-i-hate-ascii.html)

so, if you make yourself a little python script like this


#!/usr/bin/python<br />
	  import sys<br />
	  import locale<br />
	  print "default encoding is '%s'" % sys.getdefaultencoding()<br />
	  print "default locale is '%s' '%s'" % locale.getdefaultlocale()



when run it outputs


default encoding is 'ascii'<br />
	  default locale is 'en_GB' 'UTF8'



or I just go at it in the python interepter I do pretty much the same thing...


idg@somewhere.local:~ $ python<br />
	  Python 2.5.1 (r251:54863, Feb  6 2009, 19:02:12)<br />
	  [GCC 4.0.1 (Apple Inc. build 5465)] on darwin<br />
	  Type "help", "copyright", "credits" or "license" for more information.<br />
	  >>> import sys<br />
	  >>> import locale<br />
	  >>> print "default encoding is '%s'" % sys.getdefaultencoding()<br />
	  default encoding is 'ascii'<br />
	  >>> print "default locale is '%s' '%s'" % locale.getdefaultlocale()<br />
	  default locale is 'en_GB' 'UTF8'



I get the same.

this choice of encoding takes place down in

/System/Library/Frameworks/Python.framework/Versions/Current/lib/python2.5/site.py

If you take a peep at setencoding() on line 368 of the above file you'll see how a python process decides what character encoding and locale it will assume for and datatypes. As I am in the UK and my mac is configured with english language and United Kingdom region that is what I would expect. It would be good if somebody outside of the uk using a non-english language could report back what they see when they do the same.

I placed similar lines into my plugins initialisation to try and figure out what codec a PMS python plugin would be using (i.e. the very first thing in the Start() method) like so

In my plugins log I see.


15:24:05.620889: com.plexapp.plugins.flickr			  :   (Framework) Attempting to start the plug-in...<br />
	  15:24:05.621274: com.plexapp.plugins.flickr			  :   default encoding is 'ascii'<br />
	  15:24:05.622555: com.plexapp.plugins.flickr			  :   default locale is 'None' 'None'



So - as suspected the plugin process thinks everything that happens to strings has to happen in an ascii way.

There are some nasty hacks you can do to get round this which you can read about on the above linked articles but changingn /usr/lib/python/site.py is bad as it effects everthing. The cleanest way seems to be to do something like


sys.setdefaultencoding('utf-8')



so we only effect ourselves and not everything that chooses to use the system python installation.

So next I modifed the first things my Start() method does to


sys.setdefaultencoding('utf-8')<br />
	  Log("default encoding is '%s'" % sys.getdefaultencoding())<br />
	  Log("default locale is '%s' '%s'" % locale.getdefaultlocale())



Now when the plugin initialises you see this in the log


15:31:59.146241: com.plexapp.plugins.flickr			  :   (Framework) Bundle verification complete<br />
  15:31:59.147052: com.plexapp.plugins.flickr			  :   (Framework) Debugging is enabled<br />
  15:31:59.164191: com.plexapp.plugins.flickr			  :   (Framework) Configured framework modules<br />
  15:31:59.178126: com.plexapp.plugins.flickr			  :   (Framework) Loaded shared resource named 'trust.json'<br />
  15:32:00.213398: com.plexapp.plugins.flickr			  :   (Framework) Imported plug-in module<br />
  15:32:00.219755: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'locale' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.226678: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'encodings' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.226836: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'utf_8' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.232664: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'codecs' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.237950: com.plexapp.plugins.flickr			  :   (Framework) WARNING: The blacklisted module 'sys' has been imported. Future framework versions will abort at this point.<br />
  15:32:00.238210: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'ascii' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.243939: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'types' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.255045: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'aliases' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.256646: com.plexapp.plugins.flickr			  :   (Framework) WARNING: The blacklisted module 'socket' has been imported. Future framework versions will abort at this point.<br />
  15:32:00.256769: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'flickrapi' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.259126: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'mimetools' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.259316: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'tempfile' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.259657: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module '_fcntl' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.260240: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module '_thread' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.261982: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module '_errno' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.262498: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module '_os' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.262965: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module '_copy_reg' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.263234: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'UserDict' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.263459: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'path' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.263780: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'stat' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.264242: com.plexapp.plugins.flickr			  :   (Framework) WARNING: The blacklisted module 'os' has been imported. Future framework versions will abort at this point.<br />
  15:32:00.264768: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'rfc822' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.271530: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'multipart' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.279436: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'base64' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.279916: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'struct' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.280281: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'binascii' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.280732: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'cache' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.281358: com.plexapp.plugins.flickr			  :   (Framework) WARNING: The blacklisted module 'threading' has been imported. Future framework versions will abort at this point.<br />
  15:32:00.283073: com.plexapp.plugins.flickr			  :   (Framework) WARNING: The blacklisted module 'urllib' has been imported. Future framework versions will abort at this point.<br />
  15:32:00.283214: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'tokencache' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.283491: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'logging' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.284518: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'cStringIO' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.284849: com.plexapp.plugins.flickr			  :   (Framework) WARNING: The blacklisted module 'thread' has been imported. Future framework versions will abort at this point.<br />
  15:32:00.284966: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'atexit' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.288504: com.plexapp.plugins.flickr			  :   (Framework) WARNING: The blacklisted module 'traceback' has been imported. Future framework versions will abort at this point.<br />
  15:32:00.294762: com.plexapp.plugins.flickr			  :   (Framework) WARNING: The blacklisted module 'urllib2' has been imported. Future framework versions will abort at this point.<br />
  15:32:00.301324: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'webbrowser' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.302898: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'subprocess' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.303132: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'select' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.304848: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'errno' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.305450: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'fcntl' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.305688: com.plexapp.plugins.flickr			  :   (Framework) WARNING: The blacklisted module 'pickle' has been imported. Future framework versions will abort at this point.<br />
  15:32:00.307668: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'ic' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.308094: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'Res' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.308959: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'Carbon' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.309099: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'Files' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.311139: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'warnings' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.311391: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'linecache' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.324079: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'File' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.324580: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'icglue' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.324722: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'macostools' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.324872: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'MacOS' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.339026: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'shlex' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.339270: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'reportinghttp' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.339377: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'httplib' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.339804: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'copy' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.340251: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'md5' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.340376: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'exceptions' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.340484: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'xmlnode' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.340583: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'xml' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.340684: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'dom' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.340913: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'xmlbuilder' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.341059: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'minidom' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.341296: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'domreg' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.341463: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'minicompat' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.344001: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'NodeFilter' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.344547: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'parsers' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.344677: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'expat' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.344811: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'errors' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.345079: com.plexapp.plugins.flickr			  :   (Framework) NOTICE: The unknown module 'model' has been imported. This may be blacklisted in future and should be used with caution.<br />
  15:32:00.345426: com.plexapp.plugins.flickr			  :   (Framework) Checked module imports<br />
  15:32:00.346487: com.plexapp.plugins.flickr			  :   (Framework) Loaded the default preferences file<br />
  15:32:00.346807: com.plexapp.plugins.flickr			  :   (Framework) Loaded the user preferences file<br />
  15:32:00.347062: com.plexapp.plugins.flickr			  :   (Framework) No cookie jar found<br />
  15:32:00.481684: com.plexapp.plugins.flickr			  :   (Framework) Loaded en strings<br />
  15:32:00.482134: com.plexapp.plugins.flickr			  :   (Framework) Couldn't find en-us strings<br />
  15:32:00.482406: com.plexapp.plugins.flickr			  :   (Framework) Initialized framework modules<br />
  15:32:00.482665: com.plexapp.plugins.flickr			  :   (Framework) Attempting to start the plug-in...<br />
  15:32:00.485858: com.plexapp.plugins.flickr			  :   (Framework) An exception happened:<br />
  Traceback (most recent call last):<br />
	File "/Users/idg/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/Plugin.py", line 550, in __call<br />
	  return function(*args, **kwargs)<br />
	File "/Users/idg/Library/Application Support/Plex Media Server/Plug-ins/Flickr.bundle/Contents/Code/__init__.py", line 75, in Start<br />
	  sys.setdefaultencoding('utf-8')<br />
  AttributeError: 'module' object has no attribute 'setdefaultencoding'



the reason why this happens is because of the main() method of pythons site.py (see line 396) file. To protect a process once its been initialised the sys.setdefaultencoding function is removed so that it cannot be overriden to anything else. Once i'd figured this out this article gave a good explanation.

[sys.setdefaultencoding is evil](http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-evil/)

The hack around this method being deleted is to do something like this in your code:


import sys, locale<br />
	reload(sys)<br />
	sys.setdefaultencoding("utf-8")



I changed my Start() method to begin with...


reload(sys)<br />
	sys.setdefaultencoding("utf-8")<br />
	Log("default encoding is '%s'" % sys.getdefaultencoding())<br />
	Log("default locale is '%s' '%s'" % locale.getdefaultlocale())



and when my plugin starts I now see all the nasty errors but importantly...


15:52:53.827983: com.plexapp.plugins.flickr			  :   (Framework) Initialized framework modules<br />
	15:52:53.828046: com.plexapp.plugins.flickr			  :   (Framework) Attempting to start the plug-in...<br />
	15:52:53.828135: com.plexapp.plugins.flickr			  :   default encoding is 'utf-8'<br />
	15:52:53.828242: com.plexapp.plugins.flickr			  :   default locale is 'None' 'None'



Now when I run up the plugin and browse a tag list that would have massively caused problems due to accented non-ascii characters it doesn't explode and I get my data back in plex. The other important side effect of this is I no longer need to pass all data through my Encode() function because python and encode/decode mayhem is now seemingly correctly managed.

The only side effect I see now is that some completely valid characters have no corresponding character in the font map that is used back in the front end in Plex itself (this could be my font configuration though). Heres an example of what I mean (a correctly encoded response with correctly printed accented chracters and some with a missing *blank* in place of a character)

You can see it on this screenshot here:



I think this is a good explanation as to why we get encoding issues with character encoding in plugins - I need to do a bit more testing but I think this is the source of the issues we have. I know the Picasa plugin suffers the same fate as Flickr. I guess the best solution to this would be to deal with this higher up in the plugin framework so it becomes more abstract and plugin devs don't even need to be aware of things.

As I am very new to python can somebody please comment on my above thoughts.

hi!



thank you very much for testing this out. I am not at home right now so I can’t run the proposed python script. My setup is MacOSX Leopard after latest update, English OS, Slovak country and Slovak locale settings. Everything works fine in the OS. Can you send me a link to your updated Flickr plugin, so I can test the “Good” and “Bad” characters on my system?



I had a similar problem with encoding accents in the RSS channel title names in the XML definition file of the MultiRSS script from XBMC. I was finally able to solve it by manually encoding the accented characters with the “ሴ” notation. Funny thing is that the actual content was later on displayed without any problems… This probably suggests a problem higher up in the framework as well.



I am not a python programmer, but after googling around I have found:



http://www.xml.com/pub/a/2005/05/18/unicode.html



Could it be of some help?



Thanks again for your work.

Ian, you’re the man!

@Ian.G:



this is the output of the python script on my mac mini:



python myenc.py <br /> default encoding is 'ascii'<br /> default locale is 'sk_SK' 'UTF8'<br /> <br />



Thanks for that. It proves to python is making the correct choices and taking into account your regional settings. python is picking 'ascii' as the default encoding for datatypes as with me and UK regional settings.

Now we know how to change the encoding I think this is something we can manage within the plugin framework itself.

I have an idea to the display of the “good” and “bad” characters.



The reason “ý” is displayed correctly but “č” is not could be that there is an assumption somewhere that the character set used is “Western” - either ISO (8859-1) or Windows (CP 1252). The character “ý” exists in these codepages but “č” does not.



Maybe you could try “áéúšž” - all of them should be “good” and “ňďťľ” - these should be “bad”.



What do you have set up in Plex “Preferences - Appearance - Look and Feel - Skin Fonts” and “Preferences - Appearance - Region - Charset” ??? I have “Skin Fonts = Unicode” and “Charset = Central Europe (Windows)”. This way the special characters display correctly on my system.



If you need some text files with examples of the encodings, or if you want me to try to set up something on my flickr page let me know. Hope this helps.

Firstly this looks like its coming along nicely and i eagerly anticipate it getting to full functionality!



Also to add to your to-do list as you are developing it(if you have time of course) a suggestion would be to add the explore section

such as: http://www.flickr.com/explore/interesting/7days/ which has a reload and shows the last 7 days of explore interestingness(their word not mine). I know my dream is for this to be on a cycle or my screensaver or something awesome like that!