Repository: streamlink/streamlink

Issue:
plugins.trovo: API error(s): {"ret":10505,"msg":"Data not exist"} when using plugin
### Checklist

- [X] This is a plugin issue and not a different kind of issue
- [X] [I have read the contribution guidelines](https://github.com/streamlink/streamlink/blob/master/CONTRIBUTING.md#contributing-to-streamlink)
- [X] [I have checked the list of open and recently closed plugin issues](https://github.com/streamlink/streamlink/issues?q=is%3Aissue+label%3A%22plugin+issue%22)
- [X] [I have checked the commit log of the master branch](https://github.com/streamlink/streamlink/commits/master)

### Streamlink version

Latest stable release

### Description

When trying to use streamlink with any Trovo stream, I get a {"ret":10505,"msg":"Data not exist"}
It seems they change something when adding their Discord-Like interface

Step 
1. Get any stream URL from Trovo
2. Try streamlink https://trovo.live/s/TheALounge/221604214 

(If it can help, on another Github project, I found a similare case : https://github.com/yt-dlp/yt-dlp/issues/4135)

### Debug log

```text
streamlink https://trovo.live/s/TheALounge/221604214 best --loglevel debug -o "F:\Live\Theta di Gon %DATE:~-4%-%DATE:~-7,2%-%DATE:~-10,2% %TIME::=-% Bis.mp4" --retry-streams 4 --hls-segment-threads 4

[cli][debug] OS:         Windows 10
[cli][debug] Python:     3.10.5
[cli][debug] Streamlink: 4.1.0
[cli][debug] Requests(2.27.1), Socks(1.7.1), Websocket(1.3.2)
[cli][debug] Arguments:
[cli][debug]  url=https://trovo.live/s/TheALounge/221604214
[cli][debug]  stream=['best']
[cli][debug]  --loglevel=debug
[cli][debug]  --output=F:\Live\2022-07-03 14-18-25,94 Bis.mp4
[cli][debug]  --retry-streams=4.0
[cli][debug]  --hls-segment-threads=4
[cli][debug]  --ffmpeg-ffmpeg=F:\Program Files (x86)\Streamlink\ffmpeg\ffmpeg.exe
[cli][info] Found matching plugin trovo for URL https://trovo.live/s/TheALounge/221604214
[plugins.trovo][error] API error(s): {"ret":10505,"msg":"Data not exist"}
[cli][info] Waiting for streams, retrying every 4.0 second(s)
```



Discussion:
It looks like they changed the URL path a little bit for live streams.  It is now prepended with `s/` - it wasn't originally.  It's an easy fix.

Can you test or provide links to some past streams and clips, please?  It seems that Trovo no longer allows people to obtain the share URLs for these without logging in - and I do not have an account.  Thanks.


Resolving patch:
diff --git a/src/streamlink/plugins/trovo.py b/src/streamlink/plugins/trovo.py
--- a/src/streamlink/plugins/trovo.py
+++ b/src/streamlink/plugins/trovo.py
@@ -7,6 +7,7 @@
 import logging
 import random
 import re
+import sys
 
 from streamlink.plugin import Plugin, pluginmatcher
 from streamlink.plugin.api import validate
@@ -17,16 +18,15 @@
 
 
 @pluginmatcher(re.compile(r"""
-        https?://(?:www\.)?trovo\.live/
-        (?:
-            (?:
-                (?:clip|video)/(?P<video_id>[^/?&]+)
-            )
-            |
-            (?P<user>[^/?&]+)
-        )
+    https?://(?:www\.)?trovo\.live/s/(?P<user>[^/?&]+)(?:/\d+\?vid=(?P<video_id>[^/?&]+))?
 """, re.VERBOSE))
 class Trovo(Plugin):
+    @classmethod
+    def stream_weight(cls, stream):
+        if stream == "source":
+            return sys.maxsize, stream
+        return super().stream_weight(stream)
+
     @staticmethod
     def generate_qid():
         return f"{random.getrandbits(40):010x}".upper()
@@ -96,7 +96,7 @@ def get_vod(self, video_id):
         for s in json["vodInfo"]["playInfos"]:
             q = s["desc"]
             if "(source)" in q:
-                q = f"source_{q.replace('(source)', '')}"
+                q = "source"
             yield q, HLSStream(self.session, update_scheme("https:", s["playUrl"]))
 
     def get_live(self, user):


Test patch:
diff --git a/tests/plugins/test_trovo.py b/tests/plugins/test_trovo.py
--- a/tests/plugins/test_trovo.py
+++ b/tests/plugins/test_trovo.py
@@ -6,15 +6,21 @@ class TestPluginCanHandleUrlTrovo(PluginCanHandleUrl):
     __plugin__ = Trovo
 
     should_match_groups = [
-        ("https://trovo.live/UserName", {"user": "UserName"}),
-        ("https://trovo.live/clip/clip_123", {"video_id": "clip_123"}),
-        ("https://trovo.live/video/video_456", {"video_id": "video_456"}),
-        ("https://www.trovo.live/UserName", {"user": "UserName"}),
-        ("https://www.trovo.live/clip/clip_123", {"video_id": "clip_123"}),
-        ("https://www.trovo.live/video/video_456", {"video_id": "video_456"}),
+        ("https://trovo.live/s/UserName", {"user": "UserName"}),
+        ("https://trovo.live/s/UserName/abc", {"user": "UserName"}),
+        ("https://trovo.live/s/UserName/123", {"user": "UserName"}),
+        ("https://trovo.live/s/UserName/123?vid=vc-456&adtag=", {"user": "UserName", "video_id": "vc-456"}),
+        ("https://trovo.live/s/UserName/123?vid=ltv-1_2_3&adtag=", {"user": "UserName", "video_id": "ltv-1_2_3"}),
+        ("https://www.trovo.live/s/UserName", {"user": "UserName"}),
+        ("https://www.trovo.live/s/UserName/abc", {"user": "UserName"}),
+        ("https://www.trovo.live/s/UserName/123", {"user": "UserName"}),
+        ("https://www.trovo.live/s/UserName/123?vid=vc-456&adtag=", {"user": "UserName", "video_id": "vc-456"}),
+        ("https://www.trovo.live/s/UserName/123?vid=ltv-1_2_3&adtag=", {"user": "UserName", "video_id": "ltv-1_2_3"}),
     ]
 
     should_not_match = [
         "https://trovo.live/",
         "https://www.trovo.live/",
+        "https://www.trovo.live/s/",
+        "https://www.trovo.live/other/",
     ]