From 3942d76b6e6bc354307e9e0754c2ed00511485a8 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 22 May 2007 18:01:28 +0000 Subject: [PATCH] new imdb title code --- scrapeit/imdb.py | 13 +++++++++---- scrapeit/opensubtitles.py | 10 +++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/scrapeit/imdb.py b/scrapeit/imdb.py index 395130a..7d9a376 100644 --- a/scrapeit/imdb.py +++ b/scrapeit/imdb.py @@ -157,11 +157,16 @@ class IMDb: #Title, Year title = u'' year = u'' - flat_data = data.replace('\n', '').replace('\r', '') - html_title = re.compile('(.*?) \(').findall(flat_data) + soup = BeautifulSoup(data) + html_title = soup('div', {'id': 'tn15title'}) + if html_title: html_title = html_title[0]('h1') + if html_title: html_title = html_title[0].contents if html_title: - title = html_title[0][0] - IMDbDict['year'] = html_title[0][1] + title = html_title[0] + year = re.compile('(\d\d\d\d)').findall(str(html_title[1])) + if year: year = year[0] + else: year = '' + IMDbDict['year'] = year IMDbDict['title'] = stripTags(title).strip() else: title = _getTerm(data, '(.*?)') diff --git a/scrapeit/opensubtitles.py b/scrapeit/opensubtitles.py index 9909a73..315f73f 100644 --- a/scrapeit/opensubtitles.py +++ b/scrapeit/opensubtitles.py @@ -2,12 +2,20 @@ # -*- Mode: Python; -*- # vi:si:et:sw=2:sts=2:ts=2 -from utils import read_url +import utils import feedparser import StringIO import zipfile import re +import socket +def read_url(url): + t0 = socket.getdefaulttimeout() + socket.setdefaulttimeout(100) + data = utils.read_url(url) + socket.setdefaulttimeout(t0) + return data + def searchSubtitlesByIMDb(imdb, parts = 1, language = "eng"): url = "http://www.opensubtitles.org/en/search/sublanguageid-%s/subsumcd-%s/subformat-srt/imdbid-%s/rss_2_00" % (language, parts, imdb) data = read_url(url)