Optimierungen
Optimierungen

file:a/addon.xml -> file:b/addon.xml
--- a/addon.xml
+++ b/addon.xml
@@ -9,17 +9,13 @@
     <extension point="xbmc.addon.metadata">
         <platform>all</platform>
         <language>en es pt fr de ar it ru</language>
-        <summary lang="en">Watch videos from Crunchyroll.com!</summary>
-        <summary lang="de">Schaue Videos von Crunchyroll.com!</summary>
-        <summary lang="no">Se på videoer fra crunchyroll.com!</summary>
-        <summary lang="nl">Bekijk videos van Crunchyroll.com!</summary>
-        <description lang="en">Crunchyroll is an online video service and community that offers full-length episodes and movies of the very best in Japanese anime and Asian entertainment.</description>
-        <description lang="de">Crunchyroll ist ein online Video-Streaming-Dienst und bietet Zugang zu vollen Episoden und Filmen der besten japanischen Anime und asiatischer Unterhaltung.</description>
-        <description lang="no">Crunchyroll er en online video tjeneste og fellesskap som tilbyr full-lengde episoder og filmer av det aller beste i japansk anime og asiatiske tv serier.</description>
-        <description lang="nl">Crunchyroll is een online video stream service die volledige afleveringen en films van de beste Japanese anime en Asian entertainment aanbiedt.</description>
-        <disclaimer lang="en">WARNING: You MUST be a PREMIUM member to use this Plugin</disclaimer>
-        <disclaimer lang="de">HINWEIS: Du MUSST PREMIUM Mitglied sein um dieses Plugin zu benutzen</disclaimer>
-        <disclaimer lang="nl">WAARSCHUWING: Je MOET een Premium Member zijn om deze plugin te kunnen gebruiken</disclaimer>
+        <summary lang="en_GB">Watch videos from Crunchyroll.com!</summary>
+        <summary lang="de_DE">Schaue Videos von Crunchyroll.com!</summary>
+        <description lang="en_GB">Crunchyroll is an online video service and community that offers full-length episodes and movies of the very best in Japanese anime and Asian entertainment.</description>
+        <description lang="de_DE">Crunchyroll ist ein online Video-Streaming-Dienst und bietet Zugang zu vollen Episoden und Filmen der besten japanischen Anime und asiatischer Unterhaltung.</description>
+        <disclaimer lang="en_GB">WARNING: You MUST be a PREMIUM member to use this Plugin</disclaimer>
+        <disclaimer lang="de_DE">HINWEIS: Du MUSST PREMIUM Mitglied sein um dieses Plugin zu benutzen</disclaimer>
+        <news>v3.0.0 (2018.02.xx)[CR]- Addon rewriten from scratch</news>
         <license>GNU Affero General Public License, v3</license>
         <forum></forum>
         <website>http://www.crunchyroll.com/</website>

--- a/changelog.txt
+++ b/changelog.txt
@@ -1,144 +1,3 @@
-[B]2.2.2[/B]
-Added German, thanks MrKrabat
-Removed all sorting.  For Reals
-Can be enabled by uncommenting the sorting in crunchy_main.py
-[B]2.2.1[/B]
-Pulled Fix for Queue in Episode view (thanks rpowellgit)
-Added Trakt.tv info (from ineffablebob)
-Reverted Stupid sorting rulles that just messed stuff up.
-[B]2.2.0[/B]
-Replaced Shelf with Pickle (randomllama)
-"fix" the stupid Android bug
-Fix: v. Work around in a stupid way that just won't crash when it fails.
-[B]2.1.3[/B]
-Add display of how much videos had been watched. (Eduardo Martinez)
-Added Italian to language you and select.
-Removed code causing issues for new users on Windows.
-[B]2.1.2[/B]
-Fixed Login Bug!
-Corrected a Logging issue that would crash the plugin on non-ascii.
-Changed the resume logic to ask on playback.
-Thanks to mattrk for a new bottle of Magic Sauce 
-[B]2.1.1[/B]
-Thanks to Reinis Danne for the code cleanup
-Name change (again)
-[B]2.1.0[/B]
-You MUST be a Premium Member to use this plug-in
-[B]2.0.5[/B]
-Added Auto-Resume of watched Videos
-Increased Area to try to catch issues with loading save data on Android
-[B]2.0.3[/B]
-More Clean Up
-[B]2.0.1[/B]
-Merge Frodo and Gotham Repos
-Create Code to Push to XBMC Repo
-[B]1.0/2.0[/B]
-Clean up and final build for submission
-[B]0.9 x12[/B]
-Fixed EPs beyond 20 not showing
-Removed POP link, since nothing in there played.
-[B]0.9 x10[/B]
-More Fixes
-More Data
-Changes to help non-US users login
-Added anonymous user tracking
-[B]Version 0.9 x2[/B]
-More Fixes
-Added Bigger Art for larger screens
-[B]Version 0.9 x1[/B]
-Lot's of Bug Fixes (le__)
-[B]Version 0.9[/B]
-Crunchyroll;xbmc beta1
-Name change to reflect the major code changes
-Based on the Crunchyroll plugin for Plex by mattrk
-https://forums.plex.tv/index.php/topic/73626-rel-crunchyroll-plugin/
-[B]Version 0.7.2.2[/B]
-Added corrections for non-US / non-English sights.
-[B]Version 0.7.2[/B]
-Added ability to disable subtitles
-Resolved long standing metadata bug
-[B]Version 0.7.1[/B]
-Added Workaround broken videos
-[B]Version 0.7[/B]
-RMTP is Back!
-[B]Version 0.6.9.2[/B]
-Added Portuguese (Brazil)
-Removed Broken Seasons Link
-[B]Version 0.6.9.0[/B]
-BETA OF REBUILD
-Disabled rtms streams, because they are broken again
-[B]Version 0.6.5.2[/B]
-Marked Plugin as BROKEN
-[B]Version 0.6.5.1[/B]
-Changed Subtitles Crypto for changes in XBMC Python in 12.2
-Added Subtitle Language Selecton (Le__)
-[B]Version 0.6.5[/B]
--Re-added alternative streaming method for playback on devices lacking rtmp playback
--Must be enabled in settings, disabled by default, SD playback only
-[B]Version 0.6.0.5[/B]
--Resolve the plugin not showing on new Frodo installs.
--Force Refresh to show plugins
-[B]Version 0.6.0.3[/B]
--Correct Playback issues for users of non-US Crunchyroll site. (le__)
--Corrected a subtitle decoding bug (mattrk)
--Props to le__ and  mattrk for their patches
-[B]Version 0.6.0.2[/B]
--Roleback 0.6.0.1 due to broken Subtitle issue
-[B]Version 0.6[/B]
--The OMG I Br0ked the Fix Fix
--Videos playback as before
--Thanks to Zehd for his help.
-[B]Version 0.5[/B]
--The OMG Br0ken Vids Fix
-+Known issue, this fix makes ALL playback SD.  -Sorry
-[B]Version 0.4.2.1[/B]
--Fixed Edge a queue Case
-[B]Version 0.4.2[/B]
--The Broken Cookie Fix
--To activate, open your Queue
-[B]Version 0.4.1[/B]
--Fix for Series without Episode Names
-[B]Version 0.4[/B]
--The Drama Update
-+Known issue: Show listings max at 40 series
-[B]Version 0.3.4.4[/B]
--Fix to Series Parcing caused by Null in Description field
--Thanks to dandel for this fix
-[B]Version 0.3.4.3[/B]
--Fixes to norwegian language file
--Known Issue: non-ascii must be substituted
-[B]Version 0.3.4.2[/B]
--Added login validataion for Queue
-[B]Version 0.3.4.1[/B]
--Added language support
--now accepting language files
-[B]Verison 0.3.4[/B]
--Updated code to display all videos in the correct format.
--Known Issue: 480p videos show as "SD" in XBMC; Log file shows correct resolution
--Please report videos that don't play in the correct resolution to google code.
-[B]Verison 0.3.3.3[/B]
--Minor Change to handeling of shows without episodes
-[B]Verison 0.3.3.2[/B]
--Updated Logo
-[B]Version 0.3.3.1[/B]
--Minor Graphical Change to display of "Pre Release" shows
-[B]Version 0.3.3[/B]
--Added Episode number and marking of "Pre Release" Episodes (Where Avalible)
-[B]Version 0.3.2[/B]
--Corrected Playback of some 480p and 720p streams
--Known issue: Some streams may not play back due to the Video Encoding field not being picked up
-[B]Version 0.3.1[/B]
--Updated Queue Pull to give notice of Slow steps
-[B]Version 0.3[/B]
--Added Anime Simulcast Listing
-[B]Version 0.2[/B]
--Added 1080p Playback (Where Avalible)
-[B]Version 0.1[/B]
--First Build with Queue Functionality
--Known Issue: If CR is slow to login, Queue Plugin will crash
--Workaround: Play any video first
-[B]Version 0.0[/B]
--Init. Fork
--Applied know patches to make plugin work with current Cunchyroll site
--Added Plugin.CryptoPy to Repo to make plugin installable on XBMC 11
+v3.0.0 (2018.02.xx)
+- Addon rewriten from scratch
 

file:a/default.py -> file:b/default.py
--- a/default.py
+++ b/default.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Crunchyroll
-# Copyright (C) 2017 MrKrabat
+# Copyright (C) 2018 MrKrabat
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as

--- a/resources/language/resource.language.de_de/strings.po
+++ b/resources/language/resource.language.de_de/strings.po
@@ -23,6 +23,10 @@
 msgctxt "#30002"
 msgid "Password"
 msgstr "Passwort"
+
+msgctxt "#30003"
+msgid "Synchronize play time progress"
+msgstr "Synchronisiere den Fortschritt der Spielzeit"
 
 msgctxt "#30010"
 msgid "Video quality"
@@ -154,6 +158,10 @@
 msgid "An error occurred"
 msgstr "Ein Fehler ist aufgetreten"
 
+msgctxt "#30062"
+msgid "You need to be logged in"
+msgstr "Du musst eingeloggt sein"
+
 msgctxt "#30063"
 msgid "You need to be a premium member"
 msgstr "Du musst premium Nutzer sein"

--- a/resources/language/resource.language.en_gb/strings.po
+++ b/resources/language/resource.language.en_gb/strings.po
@@ -22,6 +22,10 @@
 
 msgctxt "#30002"
 msgid "Password"
+msgstr ""
+
+msgctxt "#30003"
+msgid "Synchronize play time progress"
 msgstr ""
 
 msgctxt "#30010"
@@ -154,6 +158,10 @@
 msgid "An error occurred"
 msgstr ""
 
+msgctxt "#30062"
+msgid "You need to be logged in"
+msgstr ""
+
 msgctxt "#30063"
 msgid "You need to be a premium member"
 msgstr ""

--- a/resources/lib/api.py
+++ b/resources/lib/api.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Crunchyroll
-# Copyright (C) 2017 MrKrabat
+# Copyright (C) 2018 MrKrabat
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as
@@ -43,14 +43,9 @@
     DEVICE = "com.crunchyroll.iphone"
 
 
-def start(username, password, args):
+def start(args):
     """Login and session handler
     """
-    # create cookie path
-    cookiepath = os.path.join(
-        xbmc.translatePath(args._addon.getAddonInfo("profile")),
-        "cookies.lwp")
-
     # create cookiejar
     cj = LWPCookieJar()
     args._cj = cj
@@ -65,10 +60,14 @@
 
     # check if cookies exist
     try:
-        cj.load(cookiepath, ignore_discard=True)
+        cj.load(get_cookie_path(args), ignore_discard=True)
     except IOError:
         # cookie file does not exist
         pass
+
+    # get login informations
+    username = args._addon.getSetting("crunchyroll_username")
+    password = args._addon.getSetting("crunchyroll_password")
 
     # session management
     if not (args._session_id and args._auth_token):
@@ -119,18 +118,13 @@
 def close(args):
     """Saves cookies and session
     """
-    # create cookie path
-    cookiepath = os.path.join(
-        xbmc.translatePath(args._addon.getAddonInfo("profile")),
-        "cookies.lwp")
-
     # save cookies
-    args._cj.save(cookiepath, ignore_discard=True)
+    args._cj.save(get_cookie_path(args), ignore_discard=True)
     args._addon.setSetting("session_id", args._session_id)
     args._addon.setSetting("auth_token", args._auth_token)
 
 
-def request(args, method, options):
+def request(args, method, options, failed=False):
     """Make Crunchyroll JSON API call
     """
     # required in every request
@@ -155,8 +149,24 @@
 
     # check for error
     if json_data["error"]:
-        xbmc.log("[PLUGIN] %s: API returned error '%s'" % (args._addonname, str(req)), xbmc.LOGERROR)
+        xbmc.log("[PLUGIN] %s: API returned error '%s'" % (args._addonname, str(json_data)), xbmc.LOGNOTICE)
         args._session_restart = True
+        # retry request, session expired
+        if not failed:
+            start(args)
+            return request(args, method, options, True)
 
     return json_data
 
+
+def get_cookie_path(args):
+    """Get cookie file path
+    """
+    profile_path = xbmc.translatePath(args._addon.getAddonInfo("profile"))
+    try:
+        # python2
+        return os.path.join(profile_path.decode("utf-8"), u"cookies.lwp")
+    except AttributeError:
+        # python3
+        return os.path.join(profile_path, "cookies.lwp")
+

--- a/resources/lib/cmdargs.py
+++ b/resources/lib/cmdargs.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Crunchyroll
-# Copyright (C) 2017 MrKrabat
+# Copyright (C) 2018 MrKrabat
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as

--- a/resources/lib/controller.py
+++ b/resources/lib/controller.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Crunchyroll
-# Copyright (C) 2017 MrKrabat
+# Copyright (C) 2018 MrKrabat
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as
@@ -38,6 +38,7 @@
 
     # check for error
     if req["error"]:
+        view.add_item(args, {"title": args._addon.getLocalizedString(30061)})
         view.endofdirectory()
         return False
 
@@ -84,6 +85,7 @@
 
     # check for error
     if req["error"]:
+        view.add_item(args, {"title": args._addon.getLocalizedString(30061)})
         view.endofdirectory()
         return False
 

--- a/resources/lib/crunchyroll.py
+++ b/resources/lib/crunchyroll.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Crunchyroll
-# Copyright (C) 2017 MrKrabat
+# Copyright (C) 2018 MrKrabat
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as
@@ -86,11 +86,13 @@
 
     if not (username and password):
         # open addon settings
+        view.add_item(args, {"title": args._addon.getLocalizedString(30062)})
+        view.endofdirectory()
         args._addon.openSettings()
         return False
     else:
         # login
-        success = api.start(username, password, args)
+        success = api.start(args)
         if success:
             # list menue
             xbmcplugin.setContent(int(sys.argv[1]), "tvshows")
@@ -99,6 +101,8 @@
         else:
             # login failed
             xbmc.log("[PLUGIN] %s: Login failed" % args._addonname, xbmc.LOGERROR)
+            view.add_item(args, {"title": args._addon.getLocalizedString(30060)})
+            view.endofdirectory()
             xbmcgui.Dialog().ok(args._addonname, args._addon.getLocalizedString(30060))
             return False
 

--- a/resources/lib/view.py
+++ b/resources/lib/view.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Crunchyroll
-# Copyright (C) 2017 MrKrabat
+# Copyright (C) 2018 MrKrabat
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as
@@ -46,6 +46,10 @@
     """Add item to directory listing.
     """
 
+    if args._addon.getSetting("sync_playtime") == "false":
+        info.pop("playcount", None)
+        info.pop("progress", None)
+
     # create list item
     li = xbmcgui.ListItem(label = info["title"])
 
@@ -80,9 +84,15 @@
 
 
 def quote_value(value):
+    """Proper quote on both python2 and python3 (feature detection)
+       Remove after python3 migration
+    """
     if not isinstance(value, basestring):
         value = str(value)
-    return quote_plus(value.encode("utf8") if not isinstance(value, str) else value)
+    try:
+        return quote_plus(value.encode("utf-8") if isinstance(value, unicode) else value)
+    except NameError:
+        return quote_plus(value)
 
 
 def build_url(args, info):

--- a/resources/settings.xml
+++ b/resources/settings.xml
@@ -8,5 +8,6 @@
     <setting type="sep" />
     <setting id="subtitle_language" type="select" lvalues="30021|30022|30023|30024|30025|30026|30027|30028|30029|30030|30031" label="30020" default="0" />
     <setting id="video_quality" type="select" lvalues="30014|30013|30012|30011" label="30010" default="0" />
+    <setting id="sync_playtime" type="bool" label="30003" default="true"/>
 </settings>