def get_subtitle(self): desc = NotAvailable a = self.parser.select(self.document.getroot(), 'a#bt-dwl', 1) id = a.attrib.get('rel', '').split('/')[-1] m = re.match('Download \((\w+)\)', self.parser.tocleanstring(a)) if m: ext = m.group(1) else: ext = u'zip' url = unicode('http://www.opensubtitles.org/subtitleserve/sub/%s' % id) link = self.parser.select(self.document.getroot(), 'link[rel=bookmark]', 1) title = unicode(link.attrib.get('title', '')) nb_cd = int(title.lower().split('cd')[0].split()[-1]) lang = unicode(title.split('(')[1].split(')')[0]) file_names = self.parser.select(self.document.getroot(), "img[title~=filename]") if len(file_names) > 0: file_name = file_names[0].getparent().text_content() file_name = ' '.join(file_name.split()) desc = u'files :' for f in file_names: desc_line = f.getparent().text_content() desc += '\n'+' '.join(desc_line.split()) name = unicode('%s (%s)' % (title, file_name)) subtitle = Subtitle(id, name) subtitle.url = url subtitle.ext = ext for lshort, llong in LANGUAGE_CONV.items(): if lang == llong: lang = unicode(lshort) break subtitle.language = lang subtitle.nb_cd = nb_cd subtitle.description = desc return subtitle
def get_subtitle(self): desc = NotAvailable a = self.parser.select(self.document.getroot(), 'a#bt-dwl-bt', 1) id = a.attrib.get('data-product-id', '') m = re.match('Download \((\w+)\)', self.parser.tocleanstring(a)) if m: ext = m.group(1) else: ext = u'zip' url = unicode('http://www.opensubtitles.org/en/subtitleserve/sub/%s' % id) link = self.parser.select(self.document.getroot(), 'link[rel=bookmark]', 1) title = unicode(link.attrib.get('title', '')) nb_cd = int(title.lower().split('cd')[0].split()[-1]) lang = unicode(title.split('(')[1].split(')')[0]) file_names = self.parser.select(self.document.getroot(), "img[title~=filename]") if len(file_names) > 0: file_name = file_names[0].getparent().text_content() file_name = ' '.join(file_name.split()) desc = u'files :' for f in file_names: desc_line = f.getparent().text_content() desc += '\n' + ' '.join(desc_line.split()) name = unicode('%s (%s)' % (title, file_name)) subtitle = Subtitle(id, name) subtitle.url = url subtitle.ext = ext for lshort, llong in LANGUAGE_CONV.items(): if lang == llong: lang = unicode(lshort) break subtitle.language = lang subtitle.nb_cd = nb_cd subtitle.description = desc return subtitle
def get_subtitle_from_line(self, line): cells = self.parser.select(line, 'td') if len(cells) > 0: links = self.parser.select(line, 'a') a = links[0] name = u" ".join(a.text.strip().split()) first_cell = cells[0] spanlist = self.parser.select(first_cell, 'span') if len(spanlist) > 0: long_name = spanlist[0].attrib.get('title', '') else: texts = first_cell.itertext() long_name = texts.next() long_name = texts.next() if "Download at 25" in long_name: long_name = "---" name = "%s (%s)" % (name, long_name) second_cell = cells[1] link = self.parser.select(second_cell, 'a', 1) lang = link.attrib.get('href', '').split('/')[-1].split('-')[-1] for lshort, llong in LANGUAGE_CONV.items(): if lang == llong: lang = unicode(lshort) break nb_cd = int(cells[2].text.strip().lower().replace('cd', '')) cell_dl = cells[4] href = self.parser.select(cell_dl, 'a', 1).attrib.get('href', '') url = unicode('http://www.opensubtitles.org%s' % href) id = href.split('/')[-1] subtitle = Subtitle(id, name) subtitle.url = url subtitle.language = lang subtitle.nb_cd = nb_cd subtitle.description = NotLoaded return subtitle
def get_subtitle_from_line(self, line): cells = self.parser.select(line, 'td') if len(cells) > 0: links = self.parser.select(line, 'a') a = links[0] name = u" ".join(a.text.strip().split()) first_cell = cells[0] spanlist = self.parser.select(first_cell, 'span') if len(spanlist) > 0: long_name = spanlist[0].attrib.get('title', '') else: texts = first_cell.itertext() long_name = texts.next() long_name = texts.next() if "Download at 25" in long_name: long_name = "---" name = "%s (%s)" % (name, long_name) second_cell = cells[1] link = self.parser.select(second_cell, 'a', 1) lang = link.attrib.get('href', '').split('/')[-1].split('-')[-1] for lshort, llong in LANGUAGE_CONV.items(): if lang == llong: lang = unicode(lshort) break nb_cd = int(cells[2].text.strip().lower().replace('cd', '')) cell_dl = cells[4] href = self.parser.select(cell_dl, 'a', 1).attrib.get('href', '') url = unicode('http://www.opensubtitles.org%s' % href) id = href.split('/')[-1] subtitle = Subtitle(id, name) subtitle.url = url subtitle.language = lang subtitle.nb_cd = nb_cd subtitle.description = NotLoaded return subtitle