xbmc / metadata.tvshows.themoviedb.org.python

themoviedb.org TV Show scraper in Python for Kodi 18 (Leia) or later.
GNU General Public License v3.0
20 stars 26 forks source link

It takes nearly an hour to add a single episode to kodi #50

Closed HarHarLinks closed 3 years ago

HarHarLinks commented 3 years ago

Hello, I'm new to kodi, however not new to linux or python. I run kodi on arch linux on a mini-PC:

OS: Arch Linux x86_64 
Host: HP EliteDesk 800 G1 DM 
Kernel: 5.13.4-arch2-1 
Uptime: 1 hour, 30 mins 
Packages: 679 (pacman) 
Shell: zsh 5.8 
Resolution: 1920x1080 
Terminal: /dev/pts/1 
CPU: Intel i7-4785T (8) @ 3.200GHz 
GPU: Intel HD Graphics 
Memory: 609MiB / 11878MiB

Kodi is installed from the arch repo, so the version is currently 19.1-5. KDE is installed on the same machine, but I have SDDM starting kodi-standalone for me normally. My internet connection is 100Mb/s.

My storage is a samba NAS over 1Gb/s ethernet. In principle scanning works (within expectations), but my issue is that it can take an hour to import a single episode, so I ran a debug to find out why. The same holds true for the python movie crawler, the (legacy?) non-python crawler for tvshows, but the non-python movie crawler is as reasonably quick as one would expect it to be.

Adding a single episode (by going to settings -> media -> library -> videos... -> $mytvshowsrc/show/episode -> press "Info" Start: 2021-07-26 17:59:08.498 Finish: 2021-07-26 18:51:10.457 That is one hour! This can't be right, can it?

In the debug log, there are multiple instances of "Calling URL" and "the api response"

2021-07-26 18:16:27.227 T:1418    DEBUG <general>: [metadata.tvshows.themoviedb.org.python (1.4.6)]: Calling URL "https://api.themoviedb.org/3/tv/105971/season/1?api_key=af3a53eb387d57fc935e9128468b1899&language=en-US&append_to_response=credits%2Cimages&include_image_language=en%2Cen%2Cnull"
2021-07-26 18:33:45.034 T:1418    DEBUG <general>: [metadata.tvshows.themoviedb.org.python (1.4.6)]: the api response:

That is 17 minutes for a single api call, judging from the formatting, it is called here: https://github.com/xbmc/metadata.tvshows.themoviedb.org.python/blob/92959bfd2fde10b612e2568a2402889c72f18e85/libs/api_utils.py#L54-L73 Opening the same URL in a browser shows me the same api response immediately. So, either something about the network must be wrong, or something about decoding the response.

What do you think would be causing it? How do I fix it? I have the complete log in case that would be helpful to you, however following the code it seems 100% as expected... except for the 15+ minutes before the api response is ready.

I tried, both on this PC:

>>> req = Request('https://api.themoviedb.org/3/tv/105971?api_key=af3a53eb387d57fc935e9128468b1899&language=en-US&append_to_response=credits%2Ccontent_ratings%2Cexternal_ids%2Cimages%2Cvideos&include_image_language=en%2Cen%2Cnull', headers={'Accept': 'application/json'})
>>> response = urlopen(req)

and curl. The python version hangs as described, while the curl returns instantly. On my other PC, the python command is as fast. Further, using python to request another website like github.com is also as fast as it should be.

HarHarLinks commented 3 years ago

Turns out there appears to be an IPv6 issue somewhere in my network. Disabling ipv6.disable=1 in the kernel params has worked around the problem for now...