caronc / nzb-subliminal

Fetches subtitles for the videos it's provided. It can be easily integrated into NZBGet and SABnzbd too.
GNU General Public License v3.0
103 stars 14 forks source link

Provider Podnapisi failing with '415 Unsupported Media Type' #60

Closed sguillope closed 6 years ago

sguillope commented 6 years ago

The provider Podnapisi seems to always be failing by returning 415 Unsupported Media Type.

WARNING - Provider 'podnapisi' is not available, discarding it
DEBUG - ProviderNotAvailable error: 'Request failed with status code 415'

I was able to make it work just by setting an "Accept" header in the request.

caronc commented 6 years ago

@sguillope there may be something else causing your issue, i had no problem downloading the subtitle with the current version (before your pull request):

mkdir -p delme
touch "delme/Flatliners.2017.720p.BluRay.h264-EVO.mkv"
./Subliminal.py -s -z 0 -a 0 -S -p podnapisi delme/

Produces:

2018-06-03 10:28:30,052 - 5312 - INFO - Found 1 matched file(s).
2018-06-03 10:28:30,052 - 5312 - INFO - Using advanced search mode
2018-06-03 10:28:30,226 - 5312 - INFO - Scanning video 'Flatliners.2017.720p.BluRay.h264-EVO.mkv' in '/home/l2g/Development/nzb-subliminal/delme'
2018-06-03 10:28:30,227 - 5312 - WARNING - Size is lower than 10MB: hashes not computed
2018-06-03 10:28:30,240 - 5312 - ERROR - Parsing video metadata with enzyme failed
2018-06-03 10:28:33,261 - 5312 - INFO - Open Subtitles using non-authenticated service.
2018-06-03 10:28:33,738 - 5312 - INFO - Listing subtitles with provider 'opensubtitles' for video <Movie [u'Flatliners', 2017]> with languages set([<Language [en]>])
2018-06-03 10:28:34,025 - 5312 - INFO - Found 7 subtitle(s) on opensubtitles
2018-06-03 10:28:34,025 - 5312 - INFO - Listing subtitles with provider 'podnapisi' for video <Movie [u'Flatliners', 2017]> with languages set([<Language [en]>])
2018-06-03 10:28:35,552 - 5312 - WARNING - Provider 'podnapisi' is not available, discarding it
2018-06-03 10:28:35,648 - 5312 - INFO - Downloading subtitle <OpenSubtitlesSubtitle [en]> with score 24 into u'Flatliners.2017.720p.BluRay.h264-EVO.srt'
2018-06-03 10:28:36,270 - 5312 - INFO - Successfully placed Flatliners.2017.720p.BluRay.h264-EVO.srt

So Podnapisi works fine without the Accept header request.

However I'm interested in the first fix you pushed (thank you for that); i will review it next.

sguillope commented 6 years ago

Ah, that's weird! Thanks for looking into it. Something must be messing up with my request somehow (?) I even tried without going through my VPN to no avail. It consistently fails with a 415 status code unless I add the Accept header.

Using tcpdump I can see the actual list of request headers being sent out. Without Accept header:

Host: www.podnapisi.net
Accept-Encoding: identity
Referer: http://www.podnapisi.net/subtitles/search/advanced
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)

With Accept header:

Host: www.podnapisi.net
Accept-Encoding: identity
Referer: http://www.podnapisi.net/subtitles/search/advanced
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20130401 Firefox/31.0

I've also noticed that Podnapisi always redirects to using HTTPS by issuing a 301 Moved Permanently. That said changing the server url in the code to use the https:// scheme doesn't change anything to my issue.

For reference, here's my environment:

caronc commented 6 years ago

Just a thought: Is it possible you were temporary banned from Podnapisi (and that's why it didn't work for you)? If you scan against your whole (media) library and hit sites (such as Addic7ed) to many times; you can potentially receive a temporary ban. I tried to fix this in another commit #52 to throttle the hits. Maybe your problem would be fixed if we just tweaked these default arguments a bit more?

sguillope commented 6 years ago

I don't think I was banned as I only scanned a couple of specific directories and then just adding the Accept header makes it work for me all the time.

I was able to isolate the issue by replicating the request using curl as follows:

curl \
  -L \
  -H "Host: www.podnapisi.net" \
  -H "Accept:" \
  -H "Accept-Encoding: identity" \
  -H "Referer: http://www.podnapisi.net/subtitles/search/advanced" \
  -H "User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)" \
"http://www.podnapisi.net/subtitles/search/advanced?keywords=test&page=1&language=en&year=2017"

I get the response:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>415 Unsupported Media Type</title>
<h1>Unsupported Media Type</h1>
<p>The server does not support the media type transmitted in the request.</p>

Note the use of -H "Accept:" in the curl command to prevent curl from automatically adding "Accept: */*". (which is its default behaviour) If I let curl add it then the request succeeds.

caronc commented 6 years ago

Well... honestly at the end of the day the extra header doesn't hurt anyone anyway, and you were kind enough to make the change already for me (so thank you very much for that).

So I'll just go ahead and accept your pull request. BTW thanks for all your patients while i tried to debate you about it :wink: