2013-05-01, 01:26
I was playing around and actually added a subtitle selection to the settings page.
I did it some time ago, when I was also trying to fix the playback on my region, but the codes was a mess... so I leaved it alone.
Now I did a basic clean up and re-added to the current version.
It adds a selection to Default, English, Portuguese, Spanish and French (since that those are the languages I could find) to the plugin settings.
The Default one uses the language from the Crunchyroll account settings (or your region, if you're not logged in), the others will overlap it to the selected language.
But, if that language isn't available in the current video, it will automatically fallback to the Default one.
(Note: It only works on softsubbed content, the hardsubbed ones are (probably) fully controlled by Crunchyroll account)
I did some testing and seems to be working as it should.
If you think it could be useful, feel free to use it.
I did it some time ago, when I was also trying to fix the playback on my region, but the codes was a mess... so I leaved it alone.
Now I did a basic clean up and re-added to the current version.
It adds a selection to Default, English, Portuguese, Spanish and French (since that those are the languages I could find) to the plugin settings.
The Default one uses the language from the Crunchyroll account settings (or your region, if you're not logged in), the others will overlap it to the selected language.
But, if that language isn't available in the current video, it will automatically fallback to the Default one.
(Note: It only works on softsubbed content, the hardsubbed ones are (probably) fully controlled by Crunchyroll account)
I did some testing and seems to be working as it should.
Code:
.../resources/language/English/strings.xml | 7 +++
.../resources/lib/crunchyDec.py | 64 +++++++++++++++++++---
.../resources/settings.xml | 1 +
3 files changed, 64 insertions(+), 8 deletions(-)
diff --git a/plugin.video.crunchyroll-takeout/resources/language/English/strings.xml b/plugin.video.crunchyroll-takeout/resources/language/English/strings.xml
index e6bbc55..9e351c0 100644
--- a/plugin.video.crunchyroll-takeout/resources/language/English/strings.xml
+++ b/plugin.video.crunchyroll-takeout/resources/language/English/strings.xml
@@ -80,4 +80,11 @@
<string id="80002">Video not available to your user account</string>
<string id="80003">Mature Content</string>
<string id="80004">Please login to view this video</string>
+ <!-- Alternative Language Selector -->
+ <string id="100001">Subtitles Language:</string>
+ <string id="100002">Default</string>
+ <string id="100003">English (US)</string>
+ <string id="100004">Espanol</string>
+ <string id="100005">Francais (France)</string>
+ <string id="100006">Portugues (Brasil)</string>
</strings>
diff --git a/plugin.video.crunchyroll-takeout/resources/lib/crunchyDec.py b/plugin.video.crunchyroll-takeout/resources/lib/crunchyDec.py
index b83a5bb..42e9a88 100644
--- a/plugin.video.crunchyroll-takeout/resources/lib/crunchyDec.py
+++ b/plugin.video.crunchyroll-takeout/resources/lib/crunchyDec.py
@@ -2,6 +2,9 @@ import sys
# -*- coding: utf-8 -*-
import sha
import zlib
+import re
+import urllib
+import urllib2
import math as Math
from utils.Common import Common
from binascii import hexlify, unhexlify
@@ -32,14 +35,59 @@ class crunchyDec:
def strainSoup(self, xml):
soup = BeautifulSoup(xml)
- subtitle = soup.find('subtitle', attrs={'link': None})
- if subtitle:
- _id = int(subtitle['id'])
- _iv = subtitle.find('iv').contents[0]
- _data = subtitle.data.string
- return _id, _iv, _data
- else:
- print "CRUNCHYROLL: --> Couldn't parse XML file."
+ # subtitle = soup.find('subtitle', attrs={'link': None})
+ # if subtitle:
+ # _id = int(subtitle['id'])
+ # _iv = subtitle.find('iv').contents[0]
+ # _data = subtitle.data.string
+ # return _id, _iv, _data
+ # else:
+ # print "CRUNCHYROLL: --> Couldn't parse XML file."
+
+ subsLang = __settings__.getSetting("subsLang")
+ #subsLang 0 will use the language that is set up as default on Crunchyroll account
+ if subsLang == "1":
+ subsLang = "English"
+ if subsLang == "2":
+ subsLang = "Espa"
+ if subsLang == "3":
+ subsLang = "Fran"
+ if subsLang == "4":
+ subsLang = "Portug"
+
+ if subsLang != "0":
+ subtitleALT = soup.find('subtitles').find('subtitle', { "title" : re.compile(subsLang) })
+ if subtitleALT:
+ print 'CRUNCHYROLL: --> Alternative language subs found: '+subsLang
+ playlist = subtitleALT.get('link')
+
+ opener = urllib2.build_opener()
+ opener.addheaders = [('Referer', 'http://www.crunchyroll.com'),('User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')]
+ response = opener.open(playlist)
+ xml = response.read()
+ soup = BeautifulSoup(xml)
+ subtitleALTsoup = soup.find('subtitle')
+
+ if subtitleALTsoup:
+ _id = int(subtitleALTsoup['id'])
+ _iv = subtitleALTsoup.find('iv').contents[0]
+ _data = subtitleALTsoup.data.string
+ return _id, _iv, _data
+ else:
+ print "CRUNCHYROLL: --> Couldn't parse subtitle XML file."
+ else:
+ print 'CRUNCHYROLL: --> Alternative language subs NOT found, falling back to the default one instead.'
+ subsLang = "0"
+
+ if subsLang == "0":
+ subtitle = soup.find('subtitle', attrs={'link': None})
+ if subtitle:
+ _id = int(subtitle['id'])
+ _iv = subtitle.find('iv').contents[0]
+ _data = subtitle.data.string
+ return _id, _iv, _data
+ else:
+ print "CRUNCHYROLL: --> Couldn't parse XML file."
def convertToASS(self, script):
soup = BeautifulSoup(script, convertEntities=BeautifulSoup.HTML_ENTITIES)
diff --git a/plugin.video.crunchyroll-takeout/resources/settings.xml b/plugin.video.crunchyroll-takeout/resources/settings.xml
index a618114..cb4b2d6 100644
--- a/plugin.video.crunchyroll-takeout/resources/settings.xml
+++ b/plugin.video.crunchyroll-takeout/resources/settings.xml
@@ -9,4 +9,5 @@
<setting id="thumb_quality" type="enum" lvalues="40002|40003|40004" label="40001" default="1" />
<setting type="sep" />
<setting id="useSRTSubs" label="Use unstyled subtitles" type="bool" default="false"/>
+ <setting id="subsLang" type="enum" lvalues="100002|100003|100004|100005|100006" label="100001" default="0" />
</settings>
If you think it could be useful, feel free to use it.