Dealing with image redirects?

Hey guys, working on another plugin.  Having some dramas with my image urls returning 302 redirects when trying to use them as thumbs for TV Show Objects.  If I open the url in a browser tab, I get the image fine.  However, when using the same url as a thumb, its reverting to my fallback image.  Any idea why?  I have used the same code for a different site recently with no dramas. Could this be some kind of hotlink protection?  Thanks in advance.

 

 

Example URL:

http://aniverse.tv/wp-content/uploads/2013/08/Asu-No-Yoichi.png

Relevant Code:

@route("/video/aniverse/showcategory")	
def ShowCategory(title, category):
oc = ObjectContainer(title1 = title)
page_data = HTML.ElementFromURL(BASE_URL + str(category))
count = 0

for each in page_data.xpath("//div[@id='anime']/a"):

	show_url = each.xpath("./@href")[0]
	show_title = each.xpath("./div[@class='tooltip']/span[@class='tip']/h1/text()")[0]
	show_thumb = each.xpath("./div[@class='tooltip']/img/@src")[0]
	show_summary = each.xpath("./div[@class='tooltip']/span[@class='tip']/p[1]/text()")[0].strip()
	show_genres = each.xpath("./div[@class='tooltip']/span[@class='tip']/h2/text()")[0].split(", ")
	
	oc.add(TVShowObject(
		key = Callback(PageEpisodes, show_title = show_title, show_url = show_url),
		rating_key = show_title,
		title = show_title,
		thumb = Resource.ContentsOfURLWithFallback(url = show_thumb, fallback='icon-cover.png'),
		summary = show_summary,
		genres = show_genres
		)
	)
	
	count = count + 1
	if count == 30:
		break
		
return oc

Relevant Plugin Log:

2013-11-05 15:50:17,559 (-4f877490) :  DEBUG (runtime:717) - Handling request GET /:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FArea-no-Kishi.png
2013-11-05 15:50:17,561 (-4f877490) :  DEBUG (runtime:814) - Found route matching /:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback
2013-11-05 15:50:17,562 (-4f877490) :  DEBUG (networking:233) - Fetching HTTP headers for 'http://aniverse.tv/wp-content/uploads/2013/08/Area-no-Kishi.png'
2013-11-05 15:50:18,357 (-4f877490) :  DEBUG (networking:172) - Requesting 'http://aniverse.tv/wp-content/uploads/2013/08/Area-no-Kishi.png'
2013-11-05 15:50:24,156 (-4f877490) :  ERROR (networking:219) - Error opening URL 'http://aniverse.tv/wp-content/uploads/2013/08/Area-no-Kishi.png'
2013-11-05 15:50:24,158 (-4f877490) :  DEBUG (runtime:914) - Response: [302] Redirect, 0 bytes
2013-11-05 15:50:24,161 (-4f877490) :  DEBUG (runtime:717) - Handling request GET /:/plugins/com.plexapp.plugins.aniverse/resources/icon-cover.png?t=1383235969
2013-11-05 15:50:24,163 (-4f877490) :  DEBUG (runtime:814) - Found route matching /:/plugins/com.plexapp.plugins.aniverse/resources/icon-cover.png
2013-11-05 15:50:24,166 (-4f877490) :  DEBUG (runtime:914) - Response: [200] DataObject, 65338 bytes

Relevant PMS Log:

Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - Request: HEAD /photo/:/transcode?height=720&url=http%3a%2f%2f127.0.0.1%3a32400%2f%3a%2fplugins%2fcom.plexapp.plugins.aniverse%2fresources%2fcontentWithFallback%3ffallback%3dicon-cover.png%26urls%3dhttp%25253A%252F%252Faniverse.tv%252Fwp-content%252Fuploads%252F2013%252F08%252FAsu-No-Yoichi.png&width=720 [192.168.1.101:53764] (9 live)
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG -  * height => 720
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG -  * url => http://127.0.0.1:32400/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG -  * width => 720
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - Photo transcoder: Request for url [127.0.0.1:32400/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png] (is local: 1 upscaled: 0)
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG -  * fallback => icon-cover.png
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG -  * urls => http%3A//aniverse.tv/wp-content/uploads/2013/08/Asu-No-Yoichi.png
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - Plug-in com.plexapp.plugins.aniverse has been used 220 times.
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - [com.plexapp.plugins.aniverse] Sending command over HTTP (GET): /:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - HTTP requesting to: http://127.0.0.1:35181/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png
Nov 05, 2013 15:49:18 [0xa3fffb70] DEBUG - [com.plexapp.plugins.aniverse] HTTP reply status 302, with 0 bytes of content.
Nov 05, 2013 15:49:18 [0xa3fffb70] DEBUG - Calling back into ourselves for photo to transcode, optimizing the process (status: 302)
Nov 05, 2013 15:49:18 [0xa3fffb70] DEBUG - HTTP requesting to: http://127.0.0.1:35181/:/plugins/com.plexapp.plugins.aniverse/resources/icon-cover.png?t=1383235969
Nov 05, 2013 15:49:18 [0xa3fffb70] DEBUG - Photo cache obtained 65338 bytes from http://127.0.0.1:35181/:/plugins/com.plexapp.plugins.aniverse/resources/icon-cover.png?t=1383235969
Nov 05, 2013 15:49:18 [0xa3fffb70] DEBUG - Saving original media file to /mnt/cache/apps/Plex/Application Support/Plex Media Server/Cache/PhotoTranscoder/80/80ba59f8fd587190bf08674fab58408515b034f1.jpg
Nov 05, 2013 15:49:18 [0xa3fffb70] DEBUG - Created thumbnail of size 512x512, has pixels: 1
Nov 05, 2013 15:49:18 [0xa4cffb70] DEBUG - Request: HEAD /photo/:/transcode?height=720&url=http%3a%2f%2f127.0.0.1%3a32400%2f%3a%2fplugins%2fcom.plexapp.plugins.aniverse%2fresources%2fcontentWithFallback%3ffallback%3dicon-cover.png%26urls%3dhttp%25253A%252F%252Faniverse.tv%252Fwp-content%252Fuploads%252F2013%252F08%252FAsu-No-Yoichi.png&width=720 [192.168.1.101:53766] (9 live)
Nov 05, 2013 15:49:18 [0xa4cffb70] DEBUG -  * height => 720
Nov 05, 2013 15:49:18 [0xa4cffb70] DEBUG -  * url => http://127.0.0.1:32400/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png
Nov 05, 2013 15:49:18 [0xa4cffb70] DEBUG -  * width => 720
Nov 05, 2013 15:49:18 [0xa4cffb70] DEBUG - Photo transcoder: Request for url [127.0.0.1:32400/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png] (is local: 1 upscaled: 0)
Nov 05, 2013 15:49:18 [0xa4cffb70] DEBUG - Content-Length of /mnt/cache/apps/Plex/Application Support/Plex Media Server/Cache/PhotoTranscoder/01/0178d259fa75c78719783308361a77476b081746.jpg is 65714.
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG - Request: GET /photo/:/transcode?height=720&url=http%3a%2f%2f127.0.0.1%3a32400%2f%3a%2fplugins%2fcom.plexapp.plugins.aniverse%2fresources%2fcontentWithFallback%3ffallback%3dicon-cover.png%26urls%3dhttp%25253A%252F%252Faniverse.tv%252Fwp-content%252Fuploads%252F2013%252F08%252FAsu-No-Yoichi.png&width=720 [192.168.1.101:53767] (8 live)
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG -  * height => 720
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG -  * url => http://127.0.0.1:32400/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG -  * width => 720
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG - Request range: 0 to 0
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG - Photo transcoder: Request for url [127.0.0.1:32400/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png] (is local: 1 upscaled: 0)
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG - Content-Length of /mnt/cache/apps/Plex/Application Support/Plex Media Server/Cache/PhotoTranscoder/01/0178d259fa75c78719783308361a77476b081746.jpg is 65714.

I had one do that one time. When I took the fallback=icon.png out of the code, it found the image and worked fine.

So you would try changing:
thumb = Resource.ContentsOfURLWithFallback(url = show_thumb, fallback='icon-cover.png')
to:
thumb = Resource.ContentsOfURLWithFallback(url = show_thumb)

Not sure why this worked for me or what reason it caused an issue, but try it and see what happens. 

And report back here if it makes a difference. I would be curious to know if others have encountered this and see if anyone knows the reason it happened.

Thanks for the reply.  Unfortunately, it didn't work for me.  It did however change my errors to 404's which I find strange.  I guess it could be the ContentsOfURLWithFallback function reacting to not having a specified fallback though.  Either way, I'm logging the url's its using and opening those url's in a browser work fine.  I have to admit, it's got me puzzled.   :wacko:

That sounds to me like the Resource.ContentsOfURLWithFallback() is failing to follow the redirect. I can’t think of a reason why it shouldn’t follow redirects. Could be a bug. We’ll have to try to get @jam’s attention and see if there’s a reason that couldn’t/shouldn’t work of if it can be “fixed” in a future framework update.

OK cool.  I'm still pretty new at this and I didn't want to be the first one to cry "bug" lol.  In the meantime, is there anyway that I can work around it?  I've seen mention somewhere of an undocumented arg for HTTP.Request to follow redirects? I know I can load my thumb in a separate function, can I use a HTTP request to follow the redirect, extract the image and return it that way?  I'm sure I've seen something like this used in the official plugins but can't for the life of me remember where.

Can we have a look at the code and try the channel? I have a feeling this is more of a weird cache issue than it is a redirect issue. When I download the image without a Referer, User-Agent, etc header it's still working and there aren't any redirects.

I'd LOVE for someone to take a look at it.  On top of this image issue,  my code seems to be crashing PMC on Windows (I have a feeling both issues are related).  However the same code works fine on PHT and Android.  I've uploaded the plugin HERE.  It's on google drive so you'll need to hit File > Download.  Also, the plugin isn't actually functional yet, I have no URL service etc.  I've hit this issue just trying to setup the navigation.

Thanks in advance.

Hi TehCrucible!

Thanks for the link, I checked out the channel and the images are working fine on my machine (tested with PMC, P/HT and Plex/Web). I think that you're looking at a caching problem and that something has gone wrong while you were developing your channel. Can you try the following to see if this fixes the problem on your machine?

- Close PMS

- Remove the contents of these folders (these are Mac paths, I don't have access to a Windows/Linux machine at the moment):

  1. Depending on the version of Plex you have:
    /Users//Library/Application Support/Plex/userdata/Thumbnails
    or
    /Users//Library/Application Support/Plex Home Theater/userdata/Thumbnails
  2. /Users//Library/Caches/PlexMediaServer/PhotoTranscoder
  3. /Users//Library/Application Support/Plex Media Server/Plug-in Support/Caches/com.plexapp.plugins.animeplus
  4. /Users//Library/Application Support/Plex Media Server/Plug-in Support/Data/com.plexapp.plugins.animeplus

- Start PMS and try your channel again.

I'm so sorry, sander1.  I linked you the wrong plugin!!!   :wacko:

The plugin in question is actually this one.  I did try removing the caches you suggested (including the correct plugin caches) but it hasn't helped unfortunately.  Any chance I can get you to try out this one?!  So sorry to waste your time. 

Hey TehCrucible,

I checked your other channel, and I think the problem is the HTTP return status for the images, which is HTTP 200 No Error. A "normal" 200 status message is HTTP 200 OK. Other than that I cannot find anything wrong or different from other channels. I'm trying to contact the framework dev to see if this is a framework issue or a PMS issue.

A (temporary) solution could be to proxy the images with a service like, for example, images.weserv.nl:

# Remove http:// from the original URL when using images.weserv.nl.
http://images.weserv.nl/?url=www.animeplus.tv/images/series/small/1978.jpg

Hi!

I just noticed that in your code the wrong value is used for the thumbnail url. show_url is being used instead of show_thumb:

thumb = Resource.ContentsOfURLWithFallback(url = show_url, fallback='icon-cover.png'),

Edit: Changing the value of url to show_thumb doesn't make work however :(

Haha thnks mate, I had also noticed and changed this one since. I’ll try out your proxy idea tonight. Thanks again for all your help. Originally I started this plugin as an experiment but it turns out the source site actually has a fair amount of metadata available with only the one http request so it would be good to get it working properly.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.