Skip to content

plugins.tiktok: rewrite plugin, fix live, add VODs #6381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2025

Conversation

bastimeyer
Copy link
Member

Fixes #6380

This fixes live streams and adds support for VODs. The stream type has not been changed and it's still using HTTPStream instead of HLSStream (idc). The "origin" quality is now considered best.

Random live stream

$ streamlink tiktok.com/@kamchagaming
[cli][info] Found matching plugin tiktok for URL tiktok.com/@kamchagaming
Available streams: ao, ld (worst), sd, hd, hd_60, uhd_60, origin (best)

Random offline stream

$ streamlink https://www.tiktok.com/@netflix
[cli][info] Found matching plugin tiktok for URL https://www.tiktok.com/@netflix
[plugins.tiktok][info] The channel is currently offline
error: No playable streams found on this URL: https://www.tiktok.com/@netflix

Invalid channel

$ streamlink https://www.tiktok.com/@dytfuygiuhijyrtdcfuygviuhbijnkyugvuhb
[cli][info] Found matching plugin tiktok for URL https://www.tiktok.com/@dytfuygiuhijyrtdcfuygviuhbijnkyugvuhb
[plugins.tiktok][error] user_not_found
error: No playable streams found on this URL: https://www.tiktok.com/@dytfuygiuhijyrtdcfuygviuhbijnkyugvuhb

Live stream metadata

$ streamlink https://www.tiktok.com/@kamchagaming -j | jq .metadata
{
  "id": "7456047297768491793",
  "author": "kamchagaming",
  "category": null,
  "title": "New build meta carry 100% win 8K"
}

Random video

$ streamlink https://www.tiktok.com/@4kvideos00/video/7248374611799182593 best --player-no-close
[cli][info] Found matching plugin tiktok for URL https://www.tiktok.com/@4kvideos00/video/7248374611799182593
[cli][info] Available streams: video (worst, best)
[cli][info] Opening stream: video (http)
[cli][info] Starting player: /usr/bin/mpv
[cli][info] Stream ended
[cli][info] Closing currently open stream...

Invalid video

$ streamlink https://www.tiktok.com/@theusernameisirrelevantforvideos/video/0 best --player-no-close
[cli][info] Found matching plugin tiktok for URL https://www.tiktok.com/@theusernameisirrelevantforvideos/video/0
[plugins.tiktok][error] invalid item id
error: No playable streams found on this URL: https://www.tiktok.com/@theusernameisirrelevantforvideos/video/0

Video metadata

$ streamlink https://www.tiktok.com/@theusernameisirrelevantforvideos/video/7248374611799182593 -j | jq .metadata
{
  "id": "7248374611799182593",
  "author": "4kvideos00",
  "category": null,
  "title": null
}

@bastimeyer bastimeyer added the plugin issue A Plugin does not work correctly label Jan 5, 2025
@bastimeyer
Copy link
Member Author

@drehtisch
Please check this PR and see if you find any channels that may not be working correctly (I can't check everything)
https://github.com/streamlink/streamlink/blob/master/CONTRIBUTING.md#pull-request-feedback

@drehtisch
Copy link

@bastimeyer Seems to be working fine. Worked for 2 out of 3 lives i tried. Wasn't different before the change, not understanding what is different between the lives that work and the ones that don't but that isn't the point.

Some other feedback, about the pull-request-feedback documentation. I had to run pip install versioningit to get your pr version running.

Thank you very much for your fix.

@bastimeyer
Copy link
Member Author

Seems to be working fine. Worked for 2 out of 3 lives i tried. Wasn't different before the change, not understanding what is different between the lives that work and the ones that don't but that isn't the point.

What is that supposed to mean? I am looking for feedback with actual data (which you btw also avoided in #6380), so the plugin can be fully fixed. The current implementation on master is broken, so I don't know what you mean with "before the change" either.

@drehtisch
Copy link

drehtisch commented Jan 5, 2025

Seems to be working fine. Worked for 2 out of 3 lives i tried. Wasn't different before the change, not understanding what is different between the lives that work and the ones that don't but that isn't the point.

What is that supposed to mean? I am looking for feedback with actual data (which you btw also avoided in #6380), so the plugin can be fully fixed. The current implementation on master is broken, so I don't know what you mean with "before the change" either.

When the version in master still worked before it broke, some lives worked and others didn't. As none of the lives i used this with were online, where this usually worked fine until yesterday. I now tested it with random lives from the live feed. Where 2 worked and 1 didn't.

If you want i can repeat the test, possible also with more lives and then send you the names with which it worked and with which it didn't. I don't know if they will still be online when you try to reproduce my test though.

@drehtisch
Copy link

streamlink https://www.tiktok.com/@hofzeitprojekt/live best --player-external-http --player-external-http-port 12345 --loglevel=debug
[cli][debug] OS: Linux-6.8.0-76060800daily20240311-generic-x86_64-with-glibc2.35
[cli][debug] Python: 3.10.12
[cli][debug] OpenSSL: OpenSSL 3.0.2 15 Mar 2022
[cli][debug] Streamlink: 7.1.1+6.g9026a544
[cli][debug] Dependencies:
[cli][debug] certifi: 2024.12.14
[cli][debug] exceptiongroup: 1.2.2
[cli][debug] isodate: 0.7.2
[cli][debug] lxml: 5.3.0
[cli][debug] pycountry: 24.6.1
[cli][debug] pycryptodome: 3.21.0
[cli][debug] PySocks: 1.7.1
[cli][debug] requests: 2.32.3
[cli][debug] trio: 0.28.0
[cli][debug] trio-websocket: 0.11.1
[cli][debug] urllib3: 2.3.0
[cli][debug] websocket-client: 1.8.0
[cli][debug] Arguments:
[cli][debug] url=https://www.tiktok.com/@hofzeitprojekt/live
[cli][debug] stream=['best']
[cli][debug] --loglevel=debug
[cli][debug] --player-external-http=True
[cli][debug] --player-external-http-port=12345
[cli][info] Found matching plugin tiktok for URL https://www.tiktok.com/@hofzeitprojekt/live
[plugins.tiktok][error] Error while querying API
error: No playable streams found on this URL: https://www.tiktok.com/@hofzeitprojekt/live

This does currently not work.

@drehtisch
Copy link

While this does work, and it is not apparent to me why this works and the other one doesn't.
streamlink https://www.tiktok.com/@svensupertramp/live best --player-external-http --player-external-http-port 12345 --loglevel=debug
[cli][debug] OS: Linux-6.8.0-76060800daily20240311-generic-x86_64-with-glibc2.35
[cli][debug] Python: 3.10.12
[cli][debug] OpenSSL: OpenSSL 3.0.2 15 Mar 2022
[cli][debug] Streamlink: 7.1.1+6.g9026a544
[cli][debug] Dependencies:
[cli][debug] certifi: 2024.12.14
[cli][debug] exceptiongroup: 1.2.2
[cli][debug] isodate: 0.7.2
[cli][debug] lxml: 5.3.0
[cli][debug] pycountry: 24.6.1
[cli][debug] pycryptodome: 3.21.0
[cli][debug] PySocks: 1.7.1
[cli][debug] requests: 2.32.3
[cli][debug] trio: 0.28.0
[cli][debug] trio-websocket: 0.11.1
[cli][debug] urllib3: 2.3.0
[cli][debug] websocket-client: 1.8.0
[cli][debug] Arguments:
[cli][debug] url=https://www.tiktok.com/@svensupertramp/live
[cli][debug] stream=['best']
[cli][debug] --loglevel=debug
[cli][debug] --player-external-http=True
[cli][debug] --player-external-http-port=12345
[cli][info] Found matching plugin tiktok for URL https://www.tiktok.com/@svensupertramp/live
[cli][info] Available streams: ao, ld (worst), sd, hd, uhd, origin (best)
[cli][info] Starting server, access with one of:
[cli][info] http://127.0.0.1:12345/
(Additional ip addresses redacted - can be provided if needed for some reason)

@drehtisch
Copy link

streamlink https://www.tiktok.com/@hofzeitprojekt/live best --player-external-http --player-external-http-port 12345 --loglevel=debug [cli][debug] OS: Linux-6.8.0-76060800daily20240311-generic-x86_64-with-glibc2.35 [cli][debug] Python: 3.10.12 [cli][debug] OpenSSL: OpenSSL 3.0.2 15 Mar 2022 [cli][debug] Streamlink: 7.1.1+6.g9026a544 [cli][debug] Dependencies: [cli][debug] certifi: 2024.12.14 [cli][debug] exceptiongroup: 1.2.2 [cli][debug] isodate: 0.7.2 [cli][debug] lxml: 5.3.0 [cli][debug] pycountry: 24.6.1 [cli][debug] pycryptodome: 3.21.0 [cli][debug] PySocks: 1.7.1 [cli][debug] requests: 2.32.3 [cli][debug] trio: 0.28.0 [cli][debug] trio-websocket: 0.11.1 [cli][debug] urllib3: 2.3.0 [cli][debug] websocket-client: 1.8.0 [cli][debug] Arguments: [cli][debug] url=https://www.tiktok.com/@hofzeitprojekt/live [cli][debug] stream=['best'] [cli][debug] --loglevel=debug [cli][debug] --player-external-http=True [cli][debug] --player-external-http-port=12345 [cli][info] Found matching plugin tiktok for URL https://www.tiktok.com/@hofzeitprojekt/live [plugins.tiktok][error] Error while querying API error: No playable streams found on this URL: https://www.tiktok.com/@hofzeitprojekt/live

This does currently not work.

image

Something i just found out, there are lives that are not accessible without being logged in, and this might be the reason why it doesn't work.

@bastimeyer bastimeyer force-pushed the plugins/tiktok/rewrite branch from 9026a54 to 6b9aca2 Compare January 5, 2025 16:15
@bastimeyer
Copy link
Member Author

Thanks for the follow-up data.

Streams that require a login for some reason still have a success response type, but don't include the streamId and streamData attributes:

curl 'https://www.tiktok.com/api-live/user/room?aid=1988&sourceType=54&uniqueId=hofzeitprojekt' \
  -s \
  -H 'accept: */*' \
  -H 'accept-language: en-US,en;q=0.9' \
  -H 'referer: https://www.tiktok.com/@hofzeitproject/live' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36' \
  | jq
{
  "data": {
    "user": {
      "avatarLarger": "https://p16-sign-useast2a.tiktokcdn.com/tos-useast2a-avt-0068-euttp/4076a1904d416c0589b481a2759cce1e~c5_1080x1080.webp?lk3s=a5d48078&nonce=5132&refresh_token=8ca1a5762aad8fc0d0ca22d027a0ef5b&x-expires=1736262000&x-signature=sYGceSXal7zLfYUh1xnHyGJqX9g%3D&shp=a5d48078&shcp=fdd36af4",
      "avatarMedium": "https://p16-sign-useast2a.tiktokcdn.com/tos-useast2a-avt-0068-euttp/4076a1904d416c0589b481a2759cce1e~c5_720x720.webp?lk3s=a5d48078&nonce=39010&refresh_token=6de48f196168b53e57d1413d269018f7&x-expires=1736262000&x-signature=i5QrL4QKTxNAiw5uCBR4vu8lSd8%3D&shp=a5d48078&shcp=fdd36af4",
      "avatarThumb": "https://p16-sign-useast2a.tiktokcdn.com/tos-useast2a-avt-0068-euttp/4076a1904d416c0589b481a2759cce1e~c5_100x100.webp?lk3s=a5d48078&nonce=75820&refresh_token=3397dd97d99a5dca42dd376a39e1a68b&x-expires=1736262000&x-signature=1GQE2zOUZxoRJUBHDQ9Iz4TBtiQ%3D&shp=a5d48078&shcp=fdd36af4",
      "id": "7049376587855037445",
      "nickname": "Hofzeit Projekt",
      "secUid": "MS4wLjABAAAASkhNIwWSfT0VqvSzBELgKKTQMFAiU6dMH-D-iGUukquhPKk4L1l8VIpruUYmG61w",
      "secret": false,
      "uniqueId": "hofzeitprojekt",
      "verified": false,
      "roomId": "7456412520824310550",
      "signature": "https://linktr.ee/hofzeitprojekt",
      "status": 2,
      "followStatus": 0
    },
    "stats": {
      "followingCount": 2255,
      "followerCount": 20648
    },
    "liveRoom": {
      "coverUrl": "https://p16-sign-useast2a.tiktokcdn.com/tos-useast2a-avt-0068-euttp/4076a1904d416c0589b481a2759cce1e~c5_720x720.webp?lk3s=a5d48078&nonce=36871&refresh_token=6d065495b8669eb65412978b7b9ad24f&x-expires=1736262000&x-signature=i5QrL4QKTxNAiw5uCBR4vu8lSd8%3D&shp=a5d48078&shcp=fdd36af4",
      "squareCoverImg": "",
      "title": "",
      "startTime": 1736081407,
      "status": 2,
      "paidEvent": {
        "event_id": 0,
        "paid_type": 0
      },
      "liveSubOnly": 0,
      "liveRoomMode": 0,
      "gameTagId": 0,
      "liveRoomStats": {
        "userCount": 1187
      }
    }
  },
  "message": "",
  "extra": {
    "id": "202501051559012BF397F177959BD16759"
  },
  "statusCode": 0
}

The plugin now handles this correctly and shows the inaccessible error message:

$ streamlink tiktok.com/@hofzeitprojekt
[cli][info] Found matching plugin tiktok for URL tiktok.com/@hofzeitprojekt
[plugins.tiktok][error] The stream is inaccessible
error: No playable streams found on this URL: tiktok.com/@hofzeitprojekt

@bastimeyer
Copy link
Member Author

Btw, if someone wants support for authentication, then they'll have to submit a pull request with the necessary changes. I am not interested in this myself at all, or really anything with tiktok/douyin/bytedance etc...

Merging now...

@bastimeyer bastimeyer merged commit f88dfae into streamlink:master Jan 5, 2025
23 checks passed
@bastimeyer bastimeyer deleted the plugins/tiktok/rewrite branch January 5, 2025 16:22
@drehtisch
Copy link

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin issue A Plugin does not work correctly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plugins.tiktok: Could not find room ID
2 participants