imdbpy – 无法获取剧集ID

huangapple go评论70阅读模式
英文:

imdbpy - cannot get the episode ids

问题

我是Python的初学者。

我正在尝试使用Imdbpy获取有关电影的一些信息。代码如下:

ia = IMDb()
results = ia.search_movie(movie_name)
movie_id = results[0].getID()
movie = ia.get_movie(movie_id)

如果movie_name是一个系列名称,我将获取剧集的ID:

episode_ids = ia.get_movie_episodes(movie)

但我遇到了一个错误,我不知道如何修复它。错误如下:

Traceback (most recent call last):
  File "e:\python\file_name\film_names.py", line 333, in 
    writing_imdb_S(film_name, path, file_oldname_need, prefix_and_suffix)
  File "e:\python\file_name\film_names.py", line 146, in writing_imdb_S
    episode_ids = ia.get_movie_episodes(movie)
  ...
  http.client.InvalidURL: URL can't contain control characters. '/title/ttThe Last of Us/episodes' (found at least ' ')

我对此没有做任何处理,因为我不太了解URL和请求以及imdbpy本身。如果你能帮我解决这个问题,我将不胜感激。

英文:

I'm a beginner at Python.

I am trying to get some information about a movie using Imdbpy. The code looks like this:

ia = IMDb()
results = ia.search_movie(movie_name)
movie_id = results[0].getID()
movie = ia.get_movie(movie_id)

and if the movie_name is a series name I am going to get the episodes ids:

episode_ids = ia.get_movie_episodes(movie)

but I get an error that I do not know how to fix it:
the error:

Traceback (most recent call last):
  File "e:\python\file_name\film_names.py", line 333, in 
<module>
    writing_imdb_S(film_name, path,file_oldname_need, prefix_and_sufix)
  File "e:\python\file_name\film_names.py", line 146, in 
writing_imdb_S
    episode_ids = ia.get_movie_episodes(movie)
  File "C:\Users\mahdi\AppData\Roaming\Python\Python310-32\site-packages\imdb\parser\http\__init__.py", line 631, 
in get_movie_episodes
    cont = self._retrieve(self.urls['movie_main'] % movieID + 'episodes')
  File "C:\Users\mahdi\AppData\Roaming\Python\Python310-32\site-packages\imdb\parser\http\__init__.py", line 392, 
in _retrieve
    ret = self.urlOpener.retrieve_unicode(url, size=size)  File "C:\Users\mahdi\AppData\Roaming\Python\Python310-32\site-packages\imdb\parser\http\__init__.py", line 233, in retrieve_unicode
    response = uopener.open(url)
  File "C:\Program Files (x86)\Python310-32\lib\urllib\request.py", line 519, in open
    response = self._open(req, data)
  File "C:\Program Files (x86)\Python310-32\lib\urllib\request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +    
  File "C:\Program Files (x86)\Python310-32\lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
  File "C:\Program Files (x86)\Python310-32\lib\urllib\request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,  File "C:\Program Files (x86)\Python310-32\lib\urllib\request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,        
  File "C:\Program Files (x86)\Python310-32\lib\http\client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)      
  File "C:\Program Files (x86)\Python310-32\lib\http\client.py", line 1293, in _send_request
    self.putrequest(method, url, **skips)
  File "C:\Program Files (x86)\Python310-32\lib\http\client.py", line 1127, in putrequest
    self._validate_path(url)
  File "C:\Program Files (x86)\Python310-32\lib\http\client.py", line 1227, in _validate_path
    raise InvalidURL(f"URL can't contain control characters. {url!r} "  
http.client.InvalidURL: URL can't contain control characters. '/title/ttThe Last of Us/episodes' (found at least ' ')

(I just pasted it idk which part is important.)

I did not do anything about it because I don't really know about urls and request and imdbpy it self.
I would appreciate it if you help me about it.

I don't know if you need these but I'm trying to get these information:
['title', 'year', 'rating', 'season', 'episode_number', 'episode_title', 'episode_rating', 'genres']

答案1

得分: 0

我认为按照文档获取剧集的正确方法是:

> 可以使用“episodes”信息集来获取系列的剧集。这个信息集添加了一个名为“episodes”的键,它是一个从季节号到剧集的字典。而每个季节都是一个从季节内剧集号到剧集的字典。请注意,季节和剧集号不是从0开始的;它们是由IMDb提供的数字:
>
>
> >>> ia.update(series, 'episodes')
> >>> sorted(series['episodes'].keys()) # 这里的键实际上是季节号!
> [1, 2, 3, 4]
> >>> season4 = series['episodes'][4]
> >>> len(season4)
> 13
> >>> episode = series['episodes'][4][2]
> >>> episode
> <Movie id:1038701[http] title:"The 4400" Fear Itself (2007)>
> >>> episode['season']
> 4
> >>> episode['episode']

但要小心,这里的series对象与您的movie对象相同。您可以在文档中找到更多信息:https://cinemagoer.readthedocs.io/en/latest/usage/series.html#series

英文:

I think the correct way to get the episodes, by the doc, is:

> The episodes of a series can be fetched using the “episodes” infoset. This infoset adds an episodes key which is a dictionary from season numbers to episodes. And each season is a dictionary from episode numbers within the season to the episodes. Note that the season and episode numbers don’t start from 0; they are the numbers given by the IMDb:
>
>
> >>> ia.update(series, 'episodes')
> >>> sorted(series['episodes'].keys()) # the keys here are actually season number!
> [1, 2, 3, 4]
> >>> season4 = series['episodes'][4]
> >>> len(season4)
> 13
> >>> episode = series['episodes'][4][2]
> >>> episode
> <Movie id:1038701[http] title:"The 4400" Fear Itself (2007)>
> >>> episode['season']
> 4
> >>> episode['episode']

But be careful that the series object here is the same as your movie object. You can find more information on the doc: https://cinemagoer.readthedocs.io/en/latest/usage/series.html#series

huangapple
  • 本文由 发表于 2023年5月6日 19:27:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76188606.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定