Repository: yt-dlp/yt-dlp

Issue:
[TikTok] Modify API params to get 1080p h265 (if available)
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm requesting a site-specific feature
- [X] I've verified that I'm running yt-dlp version **2023.03.04** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

_No response_

### Example URLs

https://www.tiktok.com/@tatemcrae/video/7107337212743830830

### Provide a description that is worded well enough to be understood

Updating these 2 api query params values will return a 1080p h265 version of the tiktok if available

```
device_type: Pixel 4 -> Pixel 7
resolution: 1080*1920 -> 1080*2400
```


- [Current yt-dlp API call, highest is `adapt_lower_720_1`](https://api16-normal-c-useast1a.tiktokv.com/aweme/v1/feed/?aweme_id=7107337212743830830&version_name=26.1.3&version_code=260103&build_number=26.1.3&manifest_version_code=260103&update_version_code=260103&openudid=5a53891ab9ebf6cd&uuid=1989130383684775&_rticket=1684794235828&ts=1684794235&device_brand=Google&device_type=Pixel+4&device_platform=android&resolution=1080%2A1920&dpi=420&os_version=10&os_api=29&carrier_region=US&sys_region=US&region=US&app_name=trill&app_language=en&language=en&timezone_name=America%2FNew_York&timezone_offset=-14400&channel=googleplay&ac=wifi&mcc_mnc=310260&is_my_cn=0&aid=1180&ssmix=a&as=a1qwert123&cp=cbfhckdckkde1)
- [Updated with `adapt_lowest_1080_1`](https://api16-normal-c-useast1a.tiktokv.com/aweme/v1/feed/?aweme_id=7107337212743830830&version_name=26.1.3&version_code=260103&build_number=26.1.3&manifest_version_code=260103&update_version_code=260103&openudid=5a53891ab9ebf6cd&uuid=1989130383684775&_rticket=1684794235828&ts=1684794235&device_brand=Google&device_type=Pixel+7&device_platform=android&resolution=1080%2A2400&dpi=420&os_version=10&os_api=29&carrier_region=US&sys_region=US&region=US&app_name=trill&app_language=en&language=en&timezone_name=America%2FNew_York&timezone_offset=-14400&channel=googleplay&ac=wifi&mcc_mnc=310260&is_my_cn=0&aid=1180&ssmix=a&as=a1qwert123&cp=cbfhckdckkde1)


Just a note for anyone that knows more about the API, There should also exist `adapt_1080_0` & `normal_1080_0` (maybe others) but I do not know what devices or params that would be able to get them. The only reference to the 1080p gear names on Github was [here](https://github.com/erma0/douyin/blob/88e1c6268e243bee0d4f3c263890ca73e9d91680/results/render_data_video.json#LL1536C27-L1536C27) (which is from the Douyin API, but it should exist on TikTok)

---

### June Update

The 'source' encodes seem to use the `video_id` value as the `file_id` and some sort of signature (one matchs the `file_hash` value but there are different `sign` values that also work). The gear name should be `original_1080_0` with `quality_type: 10000` 

Example: https://api16-normal-c-useast1a.tiktokv.com/aweme/v1/play/?video_id=v12044gd0000cifn8dbc77ubf8i33rdg&file_id=v12044gd0000cifn8dbc77ubf8i33rdg&sign=4ef0a55547bfe0fb142624e38826cb63

Valid signatures: `4ef0a55547bfe0fb142624e38826cb63` (`file_hash`) & `bc6ecde02cd9c3b237044c3817376ea8`  (???)

### Trimmed JSON from the feed api:

Note how `download_addr` is the exact file as the rest but has a different `sign` param

```json
  "video": {
    "play_addr": {
      "uri": "v12044gd0000cifn8dbc77ubf8i33rdg",
      "url_list": [
        "https://api16-normal-c-useast1a.tiktokv.com/aweme/v1/play/?video_id=v12044gd0000cifn8dbc77ubf8i33rdg&line=0&is_play_url=1&source=PackSourceEnum_FEED&file_id=v12044gd0000cifn8dbc77ubf8i33rdg&sign=4ef0a55547bfe0fb142624e38826cb63"
      ],
      "width": 1080,
      "height": 1920,
      "url_key": "v12044gd0000cifn8dbc77ubf8i33rdg_h264_1080p_8315273",
      "data_size": 15663896,
      "file_hash": "4ef0a55547bfe0fb142624e38826cb63"
    },
    "height": 1920,
    "width": 1080,
    "ratio": "1080p",
    "download_addr": {
      "uri": "v12044gd0000cifn8dbc77ubf8i33rdg",
      "url_list": [
        "https://api16-normal-c-useast1a.tiktokv.com/aweme/v1/play/?video_id=v12044gd0000cifn8dbc77ubf8i33rdg&line=0&watermark=0&logo_name=tiktok_m&source=FEED&file_id=v12044gd0000cifn8dbc77ubf8i33rdg&sign=bc6ecde02cd9c3b237044c3817376ea8"
      ],
      "width": 720,
      "height": 720,
      "data_size": 15663896
    },
    "has_watermark": false,
    "bit_rate": [
      {
        "gear_name": "original_1080_0",
        "quality_type": 10000,
        "bit_rate": 8315273,
        "play_addr": {
          "uri": "v12044gd0000cifn8dbc77ubf8i33rdg",
          "url_list": [
            "https://api16-normal-c-useast1a.tiktokv.com/aweme/v1/play/?video_id=v12044gd0000cifn8dbc77ubf8i33rdg&line=0&is_play_url=1&source=PackSourceEnum_FEED&file_id=v12044gd0000cifn8dbc77ubf8i33rdg&sign=4ef0a55547bfe0fb142624e38826cb63"
          ],
          "width": 1080,
          "height": 1920,
          "url_key": "v12044gd0000cifn8dbc77ubf8i33rdg_h264_1080p_8315273",
          "data_size": 15663896,
          "file_hash": "4ef0a55547bfe0fb142624e38826cb63"
        },
        "is_bytevc1": 0,
        "dub_infos": null,
        "HDR_type": "0",
        "HDR_bit": "0"
      }
    ],
  }
```

---
### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [X] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [x] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
[debug] Command-line config: ['-vU', 'https://www.tiktok.com/@tatemcrae/video/7107337212743830830']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2023.03.04 [392389b7d] (linux_exe)
[debug] Python 3.10.9 (CPython x86_64 64bit) - Linux-5.15.0-67-generic-x86_64-with-glibc2.35 (OpenSSL 3.0.8 7 Feb 2023, glibc 2.35)
[debug] exe versions: ffmpeg 4.4.2 (setts), ffprobe 4.4.2, phantomjs broken
[debug] Optional libraries: Cryptodome-3.16.0, brotli-1.0.9, certifi-2022.12.07, mutagen-1.46.0, sqlite3-2.6.0, websockets-10.4
[debug] Proxy map: {}
[debug] Loaded 1786 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Available version: stable@2023.03.04, Current version: stable@2023.03.04
Current Build Hash: 7494af600c4389d19961b44e406472bba7c54c28dc1f62bb72bdde7181708a9a
yt-dlp is up to date (stable@2023.03.04)
[TikTok] Extracting URL: https://www.tiktok.com/@tatemcrae/video/7107337212743830830
[TikTok] 7107337212743830830: Downloading video feed
[debug] Sort order given by extractor: quality, codec, size, br
[debug] Formats sorted by: hasvid, ie_pref, quality, vcodec, acodec, filesize, fs_approx, tbr, vbr, abr, lang, res, fps, hdr:12(7), channels, asr, proto, vext, aext, hasaud, source, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] 7107337212743830830: Downloading 1 format(s): bytevc1_720p_504085-2
[debug] Invoking http downloader on "https://v19.tiktokcdn.com/38fba99c2c8685db15a590de3bc89f22/646c4299/video/tos/maliva/tos-maliva-ve-0068c799-us/08df5bfc87c941358012f3586635c6c8/?a=1180&ch=0&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C3&cv=1&br=984&bt=492&cs=2&ds=3&ft=iueGqy_RZLG0PD1HhGXXg9we7dRrBEeC~&mime_type=video_mp4&qs=14&rc=M2ZoPDk0aDhlNThkNTdmZkBpanhxNTg6Zjg4ZDMzZzgzNEAuXjBfLS8vNS0xNjMzNTI2YSNrZi1ocjRvNGVgLS1kLy9zcw%3D%3D&l=20230522223304B8D4F413C0556848B7EC&btag=e00080000&cc=4"
[download] Destination: new music video 4 don’t come backkkk🧸🖤 i hope u enjoy !! @musicontiktok [7107337212743830830].mp4
[download] 100% of    9.03MiB in 00:00:00 at 10.78MiB/s
```



Discussion:

Resolving patch:
diff --git a/yt_dlp/extractor/tiktok.py b/yt_dlp/extractor/tiktok.py
--- a/yt_dlp/extractor/tiktok.py
+++ b/yt_dlp/extractor/tiktok.py
@@ -62,7 +62,7 @@ def _call_api_impl(self, ep, query, manifest_app_version, video_id, fatal=True,
         return self._download_json(
             'https://%s/aweme/v1/%s/' % (self._API_HOSTNAME, ep), video_id=video_id,
             fatal=fatal, note=note, errnote=errnote, headers={
-                'User-Agent': f'com.ss.android.ugc.{self._APP_NAME}/{manifest_app_version} (Linux; U; Android 10; en_US; Pixel 4; Build/QQ3A.200805.001; Cronet/58.0.2991.0)',
+                'User-Agent': f'com.ss.android.ugc.{self._APP_NAME}/{manifest_app_version} (Linux; U; Android 13; en_US; Pixel 7; Build/TD1A.220804.031; Cronet/58.0.2991.0)',
                 'Accept': 'application/json',
             }, query=query)
 
@@ -79,11 +79,11 @@ def _build_api_query(self, query, app_version, manifest_app_version):
             '_rticket': int(time.time() * 1000),
             'ts': int(time.time()),
             'device_brand': 'Google',
-            'device_type': 'Pixel 4',
+            'device_type': 'Pixel 7',
             'device_platform': 'android',
-            'resolution': '1080*1920',
+            'resolution': '1080*2400',
             'dpi': 420,
-            'os_version': '10',
+            'os_version': '13',
             'os_api': '29',
             'carrier_region': 'US',
             'sys_region': 'US',
@@ -624,6 +624,32 @@ class TikTokIE(TikTokBaseIE):
             'thumbnails': 'count:3',
         },
         'expected_warnings': ['Unable to find video in feed'],
+    }, {
+        # 1080p format
+        'url': 'https://www.tiktok.com/@tatemcrae/video/7107337212743830830',
+        'md5': '982512017a8a917124d5a08c8ae79621',
+        'info_dict': {
+            'id': '7107337212743830830',
+            'ext': 'mp4',
+            'title': 'new music video 4 don’t come backkkk🧸🖤 i hope u enjoy !! @musicontiktok',
+            'description': 'new music video 4 don’t come backkkk🧸🖤 i hope u enjoy !! @musicontiktok',
+            'uploader': 'tatemcrae',
+            'uploader_id': '86328792343818240',
+            'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAA-0bQT0CqebTRr6I4IkYvMDMKSRSJHLNPBo5HrSklJwyA2psXLSZG5FP-LMNpHnJd',
+            'channel_id': 'MS4wLjABAAAA-0bQT0CqebTRr6I4IkYvMDMKSRSJHLNPBo5HrSklJwyA2psXLSZG5FP-LMNpHnJd',
+            'creator': 't8',
+            'artist': 't8',
+            'track': 'original sound',
+            'upload_date': '20220609',
+            'timestamp': 1654805899,
+            'duration': 150,
+            'view_count': int,
+            'like_count': int,
+            'repost_count': int,
+            'comment_count': int,
+            'thumbnail': r're:^https://.+\.webp',
+        },
+        'params': {'format': 'bytevc1_1080p_808907-0'},
     }, {
         # Auto-captions available
         'url': 'https://www.tiktok.com/@hankgreen1/video/7047596209028074758',


Test patch: