pax_global_header 0000666 0000000 0000000 00000000064 13435444765 0014531 g ustar 00root root 0000000 0000000 52 comment=139760e841ad4875b59fe11e052af1bb56dc06ea
woob-139760e841ad4875b59fe11e052af1bb56dc06ea-modules-tvsubtitles/ 0000775 0000000 0000000 00000000000 13435444765 0023530 5 ustar 00root root 0000000 0000000 woob-139760e841ad4875b59fe11e052af1bb56dc06ea-modules-tvsubtitles/modules/ 0000775 0000000 0000000 00000000000 13435444765 0025200 5 ustar 00root root 0000000 0000000 woob-139760e841ad4875b59fe11e052af1bb56dc06ea-modules-tvsubtitles/modules/tvsubtitles/ 0000775 0000000 0000000 00000000000 13435444765 0027570 5 ustar 00root root 0000000 0000000 woob-139760e841ad4875b59fe11e052af1bb56dc06ea-modules-tvsubtitles/modules/tvsubtitles/__init__.py 0000664 0000000 0000000 00000001520 13435444765 0031677 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2013 Julien Veyssier
#
# This file is part of a weboob module.
#
# This weboob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This weboob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this weboob module. If not, see .
from .module import TvsubtitlesModule
__all__ = ['TvsubtitlesModule']
woob-139760e841ad4875b59fe11e052af1bb56dc06ea-modules-tvsubtitles/modules/tvsubtitles/browser.py 0000664 0000000 0000000 00000003526 13435444765 0031633 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2013 Julien Veyssier
#
# This file is part of a weboob module.
#
# This weboob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This weboob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this weboob module. If not, see .
from __future__ import unicode_literals
from weboob.browser import PagesBrowser, URL
from weboob.browser.exceptions import BrowserHTTPNotFound
from .pages import SeriePage, SearchPage, SeasonPage, HomePage
__all__ = ['TvsubtitlesBrowser']
LANGUAGE_LIST = ['en', 'es', 'fr', 'de', 'br', 'ru', 'ua', 'it', 'gr',
'ar', 'hu', 'pl', 'tr', 'nl', 'pt', 'sv', 'da', 'fi',
'ko', 'cn', 'jp', 'bg', 'cz', 'ro']
class TvsubtitlesBrowser(PagesBrowser):
BASEURL = 'http://www.tvsubtitles.net'
search = URL(r'/search.php', SearchPage)
serie = URL(r'/tvshow-.*.html', SeriePage)
season = URL(r'/subtitle-(?P[0-9]*-[0-9]*-.*).html', SeasonPage)
home = URL(r'/', HomePage)
def iter_subtitles(self, language, pattern):
self.home.go()
assert self.home.is_here()
return self.page.iter_subtitles(language, pattern)
def get_subtitle(self, id):
try:
self.season.go(id=id)
except BrowserHTTPNotFound:
return
if self.season.is_here():
return self.page.get_subtitle()
woob-139760e841ad4875b59fe11e052af1bb56dc06ea-modules-tvsubtitles/modules/tvsubtitles/favicon.png 0000664 0000000 0000000 00000002512 13435444765 0031723 0 ustar 00root root 0000000 0000000 PNG
IHDR @ @ iq sRGB bKGD pHYs tIME
6 IDATx_U?G:dl%$e ,ycZV(A>ԃHT[,-d$ee&Z=YY*6JZڸN<ͽ3wg\w~=wΜYE^5~{49r*3 l Iy eS- .g UƸoueQ~ PugSP9ske)Tg
;P܂LEcU'8`٤ŵ$C`ͬ/[eh:o+ P- HS/}Ƞ:c< z?})ݖ}@v_NZw-P]@ưS
S hK!!^S|[NeJ-kia
ЦĪ \e@
@@C/bX6K3zC[tSuE]
FNJjIir
7Qb҇@V'-MQ;䀘6?Df; E*JO*-})k7.qǀyn|k5}hʍ_
<,. >m"[;dT
|6.
xX, F׀F8X=;8.6ʟ9Wg
bC+Vzpl mmVԺڸѶG=f[}}h{B=zߛUbgNWߕ@F#[ y_]).d{(;
1Q x;'yuߕ`FA!sDQЕ eEC;P;//(Pa, R.}<y1=fBpmF7 <# |^
,UKφQSF a @= :vp )Bc Ȋ%sEƟ0
2n umO Ox%sG(BxΞU }~lO y9 zV\D;~6M y@/7k_mnu#"A >
|<~; '\V@ &0d[£@`Tk7h+QuO8ׁ[FۑSQEIXڐ$F IENDB` woob-139760e841ad4875b59fe11e052af1bb56dc06ea-modules-tvsubtitles/modules/tvsubtitles/module.py 0000664 0000000 0000000 00000003270 13435444765 0031431 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2013 Julien Veyssier
#
# This file is part of a weboob module.
#
# This weboob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This weboob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this weboob module. If not, see .
from weboob.capabilities.subtitle import CapSubtitle, LanguageNotSupported
from weboob.tools.backend import Module
from .browser import TvsubtitlesBrowser, LANGUAGE_LIST
__all__ = ['TvsubtitlesModule']
class TvsubtitlesModule(Module, CapSubtitle):
NAME = 'tvsubtitles'
MAINTAINER = u'Julien Veyssier'
EMAIL = 'julien.veyssier@aiur.fr'
VERSION = '1.5'
DESCRIPTION = 'Tvsubtitles subtitle website'
LICENSE = 'AGPLv3+'
BROWSER = TvsubtitlesBrowser
def get_subtitle(self, id):
return self.browser.get_subtitle(id)
def get_subtitle_file(self, id):
subtitle = self.browser.get_subtitle(id)
if not subtitle:
return None
return self.browser.open(subtitle.url).content
def iter_subtitles(self, language, pattern):
if language not in LANGUAGE_LIST:
raise LanguageNotSupported()
return self.browser.iter_subtitles(language, pattern)
woob-139760e841ad4875b59fe11e052af1bb56dc06ea-modules-tvsubtitles/modules/tvsubtitles/pages.py 0000664 0000000 0000000 00000010771 13435444765 0031247 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2013 Julien Veyssier
#
# This file is part of a weboob module.
#
# This weboob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This weboob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this weboob module. If not, see .
from __future__ import unicode_literals
import re
from weboob.capabilities.subtitle import Subtitle
from weboob.browser.pages import HTMLPage
from weboob.tools.misc import to_unicode
class HomePage(HTMLPage):
def iter_subtitles(self, language, pattern):
form = self.get_form(nr=0)
form['q'] = pattern
form.submit()
assert self.browser.search.is_here()
for subtitle in self.browser.page.iter_subtitles(language):
yield subtitle
class SearchPage(HTMLPage):
""" Page which contains results as a list of series
"""
def iter_subtitles(self, language):
list_result = self.doc.xpath('//div[has-class("left_articles")]//ul')
if len(list_result) > 0:
li_result = list_result[0].xpath('.//li')
for line in li_result:
if len(line.xpath('.//img[@alt=$alt]', alt=language)) > 0:
link, = line.xpath('.//a')
href = link.attrib.get('href', '')
self.browser.location("%s%s" % (self.browser.BASEURL, href))
assert self.browser.serie.is_here()
for subtitle in self.browser.page.iter_subtitles(language):
yield subtitle
class SeriePage(HTMLPage):
""" Page of all seasons
"""
def iter_subtitles(self, language, only_one_season=False):
# handle the current season
last_table_line = self.doc.xpath('//table[@id="table5"]//tr')[-1]
amount = int(last_table_line.xpath('.//td')[2].text_content())
if amount > 0:
my_lang_img = last_table_line.xpath('.//img[@alt=$alt]', alt=language)
if len(my_lang_img) > 0:
url_current_season = self.url.split('/')[-1].replace(
'tvshow', 'subtitle').replace('.html', '-%s.html' % language)
self.browser.location(url_current_season)
assert self.browser.season.is_here()
yield self.browser.page.iter_subtitles()
if not only_one_season:
# handle the other seasons by following top links
other_seasons_links = self.doc.xpath('//p[has-class("description")]//a')
for link in other_seasons_links:
href = link.attrib.get('href', '')
self.browser.location("%s/%s" % (self.browser.BASEURL, href))
assert self.browser.serie.is_here()
for subtitle in self.browser.page.iter_subtitles(language, True):
yield subtitle
class SeasonPage(HTMLPage):
""" Page of a season with the right language
"""
def get_subtitle(self):
filename_line = self.doc.xpath('//img[@alt="filename"]')[0].getparent().getparent()
name = to_unicode(filename_line.xpath('.//td')[2].text)
id = self.url.split('/')[-1].replace('.html', '').replace('subtitle-', '')
url = '%s/download-%s.html' % (self.browser.BASEURL, id)
amount_line, = self.doc.xpath('//tr[contains(@title, "amount")]')
nb_cd = int(amount_line.xpath('.//td')[2].text)
lang = url.split('-')[-1].split('.html')[0]
filenames_line, = self.doc.xpath('//tr[contains(@title,"list")]')
file_names = filenames_line.xpath('.//td')[2].text_content().strip().replace('.srt', '.srt\n')
desc = u"files :\n"
desc += file_names
m = re.match('(.*?)\.(\w+)$', name)
if m:
name = m.group(1)
ext = m.group(2)
else:
ext = 'zip'
subtitle = Subtitle(id, name)
subtitle.url = url
subtitle.ext = ext
subtitle.language = lang
subtitle.nb_cd = nb_cd
subtitle.description = desc
return subtitle
def iter_subtitles(self):
return self.get_subtitle()
woob-139760e841ad4875b59fe11e052af1bb56dc06ea-modules-tvsubtitles/modules/tvsubtitles/test.py 0000664 0000000 0000000 00000002774 13435444765 0031133 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2013 Julien Veyssier
#
# This file is part of a weboob module.
#
# This weboob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This weboob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this weboob module. If not, see .
from weboob.tools.test import BackendTest
from random import choice
class TvsubtitlesTest(BackendTest):
MODULE = 'tvsubtitles'
def test_subtitle(self):
subtitles = list(self.backend.iter_subtitles('fr', 'sopranos'))
assert (len(subtitles) > 0)
for subtitle in subtitles:
assert subtitle.url.startswith('http')
# get the file of a random sub
if len(subtitles):
subtitle = choice(subtitles)
self.backend.get_subtitle_file(subtitle.id)
def test_get_subtitle(self):
subtitles = list(self.backend.iter_subtitles('fr', 'sopranos'))
assert (len(subtitles) > 0)
subtitle = choice(subtitles)
assert self.backend.get_subtitle(subtitle.id)