Skip to content

Commit

Permalink
Fixed 'Ondertitel.com' after site redesign and sync detection added
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-blobby committed Apr 22, 2012
1 parent b9986bf commit 61a7da7
Showing 1 changed file with 41 additions and 18 deletions.
59 changes: 41 additions & 18 deletions script.xbmc.subtitles/resources/lib/services/Ondertitel/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

_ = sys.modules[ "__main__" ].__language__

main_url = "http://www.ondertitel.com/"
main_url = "http://ondertitel.com/"
debug_pretext = ""

#====================================================================================================================
Expand All @@ -14,17 +14,22 @@

# subtitle pattern example:
"""
<td onclick="location='http://www.ondertitel.com/ondertitels/info/Brooklyns-Finest/47638.html'" align=left><a href='http://www.ondertitel.com/ondertitels/info/Brooklyns-Finest/47638.html'><span class=window2 style="text-transform: capitalize">Brooklyn's Finest</span><br /> [Brooklyns.Finest.DVDSCREENER.XviD-MENTiON]</a></td>
"""
subtitle_pattern = "<td onclick=\"location=\'(http://www\.ondertitel\.com/ondertitels/info/[^\n\r\t]*?/\d{1,10}\.html)\'\" \
align=left><a href=\'http://www\.ondertitel\.com/ondertitels/info/[^\n\r\t]*?/\d{1,10}\.html\'><span class=window2 style=\"text-transform: capitalize\">\
([^\n\r\t]*?)</span><br />[ \[]{0,2}([^\n\r\t]*?)[\]]{0,1}</a></td>"
# group(1) = link to page with downloadlink, group(2) = title as found, group(3) = filename
<strong><a href="/ondertitels/info/Avatar/48039.html" title="ondertitels Avatar" style="color: #000;">Avatar</a></strong> <img src="/images/nederlandse_vlag.jpg" height="15" width="20"> <a href="http://trailer-cinema.com/trailer/info/Avatar/Avatar.html" target="_blank"><img src="/images/icon_play-trailer.png" height="15" border="0"></a><br>
<font style="font-size: 11px; color: #444445;"><i>Avatar.RETAIL.DVDRip.XviD-DiAMOND</i></font>
</div>
</td>
<td><a href="http://www.imdb.com/title/tt0499549/" target="_blank"><img src="/images/imdb_logo.gif" border="0"></a></td>
<td style="width: 60px;">3 CD's</td><td><a href="/user_list.php?user=Goffini">Goffini</a></td></tr>
"""
subtitle_pattern = "<strong><a href=\"/(ondertitels/info/[^\n\r\t]*?.html)\"[^\n\r\t]*?trailer.png\" height=\"15\" border=\"0\"></a><br>\
[\n\r\t ]*?<font style=\"font-size: 11px; color: #444445;\"><i>([^\r\n\t]*?)</i></font>[\n\r\t ]*?</div>[\n\r\t ]*?</td>\
[\n\r\t ]*?<td>[^\r\n\t]*?</td>[\r\n\t ]*?<td style=\"width: 60px;\">(\d) CD"
# group(1) = link to page with downloadlink, group(2) = filename, group(3) = number of CD's

# downloadlink pattern example:
"""
<a href="/getdownload.php?id=47638&userfile=7 Brooklyns.Finest.DVDSCREENER.XviD-MENTiON.zip"><b>Download</b></a>
<a href="/getdownload.php?id=45071&userfile=94 Avatar (2009) PROPER TS XviD-MAXSPEED.zip"><b>Download</b></a>
"""
downloadlink_pattern = "<a href=\"/(getdownload\.php\?id=\d{1,10}&userfile=[^\n\r\t]*\.\w{3})\"><b>Download</b></a>"
# group(1) = downloadlink
Expand All @@ -33,15 +38,32 @@
# Functions
#====================================================================================================================

def getallsubs(content, title, subtitles_list):
def getallsubs(content, title, moviefile, subtitles_list, ):
for matches in re.finditer(subtitle_pattern, content, re.IGNORECASE | re.DOTALL):
if matches.group(3) == "&nbsp;":
if matches.group(3) == "1" and matches.group(2) <> "":
link = matches.group(1)
filename = matches.group(2)
log( __name__ ,"%s Subtitles found: %s (link=%s)" % (debug_pretext, filename, link))
if isexactmatch(filename, moviefile):
subtitles_list.append({'rating': '0', 'no_files': 1, 'movie': title, 'filename': filename, 'sync': True, 'link': link, 'language_flag': 'flags/nl.gif', 'language_name': 'Dutch'})
else:
subtitles_list.append({'rating': '0', 'no_files': 1, 'movie': title, 'filename': filename, 'sync': False, 'link': link, 'language_flag': 'flags/nl.gif', 'language_name': 'Dutch'})


def isexactmatch(subsfile, moviefile):
match = re.match("(.*)\.", moviefile)
if match:
moviefile = string.lower(match.group(1))
subsfile = string.lower(subsfile)
log( __name__ ," comparing subtitle file with moviefile to see if it is a match (sync):\nsubtitlesfile = '%s'\nmoviefile = '%s'" % (string.lower(subsfile), string.lower(moviefile)) )
if string.lower(subsfile) == string.lower(moviefile):
log( __name__ ," found matching subtitle file, marking it as 'sync': '%s'" % (string.lower(subsfile)) )
return True
else:
filename = matches.group(3)
link = matches.group(1)
log( __name__ ,"%s Subtitles found: %s (link=%s)" % (debug_pretext, filename, link))
subtitles_list.append({'rating': '0', 'no_files': 1, 'movie': title, 'filename': filename, 'sync': False, 'link': link, 'language_flag': 'flags/nl.gif', 'language_name': 'Dutch'})
return False
else:
return False


def getdownloadlink(content):
link = None
Expand All @@ -54,6 +76,7 @@ def getdownloadlink(content):
else:
return None


def geturl(url):
log( __name__ ,"%s Getting url:%s" % (debug_pretext, url))
try:
Expand All @@ -72,14 +95,15 @@ def search_subtitles( file_original_path, title, tvshow, year, season, episode,
msg = ""
log( __name__ ,"%s Title = %s" % (debug_pretext, title))
if len(tvshow) == 0: # only process movies
url = main_url + "?type=1+CD&p=zoek&trefwoord=" + urllib.quote_plus(title)
url = main_url + "zoeken.php?type=1&trefwoord=" + urllib.quote_plus(title)
Dutch = False
if (string.lower(lang1) == "dutch") or (string.lower(lang2) == "dutch") or (string.lower(lang3) == "dutch"):
Dutch = True
content, response_url = geturl(url)
if content is not None:
log( __name__ ,"%s Getting subs ..." % debug_pretext)
getallsubs(content, title, subtitles_list)
moviefile = os.path.basename(file_original_path)
getallsubs(content, title, moviefile, subtitles_list)
else:
log( __name__ ,"%s Dutch language is not selected" % (debug_pretext))
msg = "Won't work, Ondertitel is only for Dutch subtitles."
Expand All @@ -90,7 +114,7 @@ def search_subtitles( file_original_path, title, tvshow, year, season, episode,


def download_subtitles (subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, session_id): #standard input
url = subtitles_list[pos][ "link" ]
url = main_url + subtitles_list[pos][ "link" ]
local_tmp_file = zip_subs
content, response_url = geturl(url)
downloadlink = getdownloadlink(content)
Expand All @@ -99,7 +123,6 @@ def download_subtitles (subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder,
url = main_url + downloadlink
url = string.replace(url," ","+")
log( __name__ ,"%s Fetching subtitles using url %s" % (debug_pretext, url))
#response = urllib2.urlopen(url)
content, response_url = geturl(url)
if content is not None:
log( __name__ ,"%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file))
Expand Down

0 comments on commit 61a7da7

Please sign in to comment.