Repository: streamlink/streamlink

Issue:
Support providing a custom Crunchyroll session ID
The documentation suggests using an HTTP proxy to access region-locked content in Crunchyroll. However this isn't necessary, as all you need to do so is a session ID belonging to the region you want. Now I'm not asking for streamlink to generate one for you, as nice as that would be -- simply that it lets you specify it with an argument (it's only a 32 character string).


Discussion:
How do you set the token? In a cookie? 
Could that be done like this?

[http://www.crunblocker.com/sess_id.php](http://www.crunblocker.com/sess_id.php)
[https://github.com/jerryteps/Crunchyroll-Unblocker/tree/master/Crunchyroll%20Unblocker](https://github.com/jerryteps/Crunchyroll-Unblocker/tree/master/Crunchyroll%20Unblocker)

> [https://chrome.google.com/webstore/detail/crunchyroll-unblocker/dldddkdajilplfikaadakojgjocbnjim](https://chrome.google.com/webstore/detail/crunchyroll-unblocker/dldddkdajilplfikaadakojgjocbnjim)
> This extension works by opening a http connection to a php script which obtains a us session id. The extension then copies the id so Crunchyroll believes you are from the US.
> 
> In case the extension no longer works, you can manually access the US site instead, just find a proxy, clear your cookies (reloading your browser will do), since it saves a US session id, you can just quit out of the proxy and you'll still remain on the US site, even on your own connection, since you still have the US cookies.
<del>You can do that already using the command line arguments in streamlink adding something like `--http-cookie "sess_id=rthgyx5gg3lwlcfr2zj5gueooloxxy0u"` should do it. </del>
Or not... looks like it would need a special option.

Resolving patch:
diff --git a/src/streamlink/plugins/crunchyroll.py b/src/streamlink/plugins/crunchyroll.py
--- a/src/streamlink/plugins/crunchyroll.py
+++ b/src/streamlink/plugins/crunchyroll.py
@@ -205,7 +205,8 @@ class Crunchyroll(Plugin):
         "username": None,
         "password": None,
         "purge_credentials": None,
-        "locale": None
+        "locale": None,
+        "session_id": None,
     })
 
     @classmethod
@@ -281,13 +282,14 @@ def _create_api(self):
         if self.options.get("purge_credentials"):
             self.cache.set("session_id", None, 0)
             self.cache.set("auth", None, 0)
+            self.cache.set("session_id", None, 0)
 
         current_time = datetime.datetime.utcnow()
         device_id = self._get_device_id()
         # use the crunchyroll locale as an override, for backwards compatibility
         locale = self.get_option("locale") or self.session.localization.language_code
         api = CrunchyrollAPI(
-            self.cache.get("session_id"), self.cache.get("auth"), locale
+            self.options.get("session_id") or self.cache.get("session_id"), self.cache.get("auth"), locale
         )
 
         self.logger.debug("Creating session with locale: {0}", locale)
diff --git a/src/streamlink_cli/argparser.py b/src/streamlink_cli/argparser.py
--- a/src/streamlink_cli/argparser.py
+++ b/src/streamlink_cli/argparser.py
@@ -1023,6 +1023,14 @@ def keyvalue(value):
     and reauthenticate.
     """
 )
+plugin.add_argument(
+    "--crunchyroll-session-id",
+    metavar="SESSION_ID",
+    help="""
+    Set a specific session ID for crunchyroll, can be used to bypass
+    region restrictions
+    """
+)
 plugin.add_argument(
     "--livestation-email",
     metavar="EMAIL",
diff --git a/src/streamlink_cli/main.py b/src/streamlink_cli/main.py
--- a/src/streamlink_cli/main.py
+++ b/src/streamlink_cli/main.py
@@ -814,6 +814,9 @@ def setup_plugin_options():
     if args.crunchyroll_purge_credentials:
         streamlink.set_plugin_option("crunchyroll", "purge_credentials",
                                      args.crunchyroll_purge_credentials)
+    if args.crunchyroll_session_id:
+        streamlink.set_plugin_option("crunchyroll", "session_id",
+                                     args.crunchyroll_session_id)
 
     if args.crunchyroll_locale:
         streamlink.set_plugin_option("crunchyroll", "locale",


Test patch: