Skip to content

Commit

Permalink
Indicate filesize approximated from tbr better
Browse files Browse the repository at this point in the history
  • Loading branch information
pukkandan committed Jun 21, 2023
1 parent 1e75d97 commit 0dff8e4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions yt_dlp/YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -2666,7 +2666,8 @@ def is_wellformed(f):
format['dynamic_range'] = 'SDR'
if format.get('aspect_ratio') is None:
format['aspect_ratio'] = try_call(lambda: round(format['width'] / format['height'], 2))
if (info_dict.get('duration') and format.get('tbr')
if (not format.get('manifest_url') # For fragmented formats, "tbr" is often max bitrate and not average
and info_dict.get('duration') and format.get('tbr')
and not format.get('filesize') and not format.get('filesize_approx')):
format['filesize_approx'] = int(info_dict['duration'] * format['tbr'] * (1024 / 8))
format['http_headers'] = self._calc_headers(collections.ChainMap(format, info_dict))
Expand Down Expand Up @@ -3707,8 +3708,11 @@ def simplified_codec(f, field):
format_field(f, 'fps', '\t%d', func=round),
format_field(f, 'dynamic_range', '%s', ignore=(None, 'SDR')).replace('HDR', ''),
format_field(f, 'audio_channels', '\t%s'),
delim,
format_field(f, 'filesize', ' \t%s', func=format_bytes) + format_field(f, 'filesize_approx', '~\t%s', func=format_bytes),
delim, (
format_field(f, 'filesize', ' \t%s', func=format_bytes)
or format_field(f, 'filesize_approx', '≈\t%s', func=format_bytes)
or format_field(try_call(lambda: format_bytes(int(info_dict['duration'] * f['tbr'] * (1024 / 8)))),
None, self._format_out('~\t%s', self.Styles.SUPPRESS))),
format_field(f, 'tbr', '\t%dk', func=round),
shorten_protocol_name(f.get('protocol', '')),
delim,
Expand Down

3 comments on commit 0dff8e4

@someziggyman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, I've noticed a bug in the output JSON after these changes. for some reason after this was implemented all formats with protocol = "m3u8_native"; lost "filesize" and "filesize_approx" values.
I'm not sure if I'm correct with all the terms here.

Test link: https://www.youtube.com/watch?v=__edp8NgPx0

BEFORE changes - part of JSON (filesize_approx is there):
abr = 0;
acodec = none;
"aspect_ratio" = "1.78";
"audio_ext" = none;
"dynamic_range" = SDR;
ext = mp4;
"filesize_approx" = 23658578;
format = "269 - 256x144";
"format_id" = 269;
"format_index" = "";
fps = 30;
"has_drm" = "";
height = 144;
"http_headers" = {
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8";
"Accept-Language" = "en-us,en;q=0.5";
"Sec-Fetch-Mode" = navigate;
"User-Agent" = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36";
};
"manifest_url" = "https://manifest.googlevideo.com/api/manifest/hls_variant/expire/1687490167/ei/F7qUZObYNseQxgKX4L3oAQ/ip/80.174.175.175/id/fff79da7c3603f1d/source/youtube/requiressl/yes/playback_host/rr1---sn-8vq54voxn25po-5ajz.googlevideo.com/mh/b6/mm/31%2C29/mn/sn-8vq54voxn25po-5ajz%2Csn-h5qzen7y/ms/au%2Crdu/mv/m/mvi/1/pcm2cms/yes/pl/24/hfr/1/demuxed/1/tts_caps/1/maudio/1/initcwndbps/1618750/vprv/1/go/1/mt/1687468141/fvip/2/nvgoi/1/short_key/1/ncsapi/1/keepalive/yes/fexp/24007246/beids/24350017/dover/13/itag/0/playlist_type/DVR/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Chfr%2Cdemuxed%2Ctts_caps%2Cmaudio%2Cvprv%2Cgo%2Citag%2Cplaylist_type/sig/AOq0QJ8wRAIgew55kZ1kNRW8KyygEQ4qKWkrJ4d7GHXzIuDWs9o94OcCIHHipgmc7CX4PQNWMrxQJzxU5w3aWoE__73zBSeHem-J/lsparams/playback_host%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpcm2cms%2Cpl%2Cinitcwndbps/lsig/AG3C_xAwRgIhAO8S-V9L9XltBMbPRPhaoGF1wMDWTIZu36AoI4MywSMtAiEA-fqU5muE8Otgk1uWtN_ytAUMMfkbUg0mCqjhv2OLkeE%3D/file/index.m3u8";
preference = "";
protocol = "m3u8_native";
quality = 0;
resolution = 256x144;
tbr = "196.213";
url = "https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1687490167/ei/F7qUZObYNseQxgKX4L3oAQ/ip/80.174.175.175/id/fff79da7c3603f1d/itag/269/source/youtube/requiressl/yes/ratebypass/yes/pfa/1/sgovp/clen%3D9970822%3Bdur%3D941.940%3Bgir%3Dyes%3Bitag%3D160%3Blmt%3D1687462720226093/hls_chunk_host/rr1---sn-8vq54voxn25po-5ajz.googlevideo.com/mh/b6/mm/31,29/mn/sn-8vq54voxn25po-5ajz,sn-h5qzen7y/ms/au,rdu/mv/m/mvi/1/pcm2cms/yes/pl/24/initcwndbps/1618750/vprv/1/playlist_type/DVR/dover/13/txp/6319224/mt/1687468141/fvip/2/short_key/1/keepalive/yes/fexp/24007246/beids/24350017/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,pfa,sgovp,vprv,playlist_type/sig/AOq0QJ8wRQIhAIYAhUhJRXbhpdZM94pdcGCBp_vn7F7fmHHmryWjJW7qAiAZ1iH1PGM6_GJBSdSK0cv2BRkN7BeuY-74b-jhPRt55Q%3D%3D/lsparams/hls_chunk_host,mh,mm,mn,ms,mv,mvi,pcm2cms,pl,initcwndbps/lsig/AG3C_xAwRgIhAOx_1dA0SlN1wrzK2UXsfyfJ1Y_mJUu4-y7SGyk4OAEuAiEA9chbvQ0_7EmBOfTf_LNFiBLFoV9x1oonIwGq3jhXCwo%3D/playlist/index.m3u8";
vbr = "196.213";
vcodec = "avc1.4D400C";
"video_ext" = mp4;
width = 256;
}

After changes - filesize_approx is GONE: (however if using ./yt-dlp -F "https://www.youtube.com/watch?v=__edp8NgPx0" file size will be shown inform on the 269 format id with ~ before it):

abr = 0;
acodec = none;
"aspect_ratio" = "1.78";
"audio_ext" = none;
"dynamic_range" = SDR;
ext = mp4;
format = "269 - 256x144";
"format_id" = 269;
"format_index" = "<null>";
fps = 30;
"has_drm" = "<null>";
height = 144;
"http_headers" =     {
    Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
    "Accept-Language" = "en-us,en;q=0.5";
    "Sec-Fetch-Mode" = navigate;
    "User-Agent" = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.70 Safari/537.36";
};
"manifest_url" = "https://manifest.googlevideo.com/api/manifest/hls_variant/expire/1687490836/ei/tLyUZLz1B4eUW97Nj4gG/ip/80.174.175.175/id/fff79da7c3603f1d/source/youtube/requiressl/yes/playback_host/rr1---sn-8vq54voxn25po-5ajz.googlevideo.com/mh/b6/mm/31%2C29/mn/sn-8vq54voxn25po-5ajz%2Csn-h5qzen7y/ms/au%2Crdu/mv/m/mvi/1/pl/24/hfr/1/demuxed/1/tts_caps/1/maudio/1/initcwndbps/1647500/vprv/1/go/1/mt/1687468864/fvip/2/nvgoi/1/short_key/1/ncsapi/1/keepalive/yes/fexp/24007246/dover/13/itag/0/playlist_type/DVR/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Chfr%2Cdemuxed%2Ctts_caps%2Cmaudio%2Cvprv%2Cgo%2Citag%2Cplaylist_type/sig/AOq0QJ8wRQIhALThkoN89yHn-AgvF5LDincvuE1JuAwB8kfv6FpypNfqAiBRSsmB48ntxwuYyuPYWmi-_qKJ34l2Bw5T365wruzn1Q%3D%3D/lsparams/playback_host%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps/lsig/AG3C_xAwRQIgU95NyBkUaskCA9cJTfDyHZf9Z8LxyeujgBWSIrbnMNECIQCDLKaS8raEa7Q5pv5QK5LKE0cx8BF7dbYy8S9lVmyIXA%3D%3D/file/index.m3u8";
preference = "<null>";
protocol = "m3u8_native";
quality = 0;
resolution = 256x144;
tbr = "196.213";
url = "https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1687490836/ei/tLyUZLz1B4eUW97Nj4gG/ip/80.174.175.175/id/fff79da7c3603f1d/itag/269/source/youtube/requiressl/yes/ratebypass/yes/pfa/1/sgovp/clen%3D9970822%3Bdur%3D941.940%3Bgir%3Dyes%3Bitag%3D160%3Blmt%3D1687462720226093/hls_chunk_host/rr1---sn-8vq54voxn25po-5ajz.googlevideo.com/mh/b6/mm/31,29/mn/sn-8vq54voxn25po-5ajz,sn-h5qzen7y/ms/au,rdu/mv/m/mvi/1/pl/24/initcwndbps/1647500/vprv/1/playlist_type/DVR/dover/13/txp/6319224/mt/1687468864/fvip/2/short_key/1/keepalive/yes/fexp/24007246/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,pfa,sgovp,vprv,playlist_type/sig/AOq0QJ8wRAIgdbRmbtBzWzHzv3J2Jt893lEvXhFZLCFLyuZ4UTZGlFYCIFCL_M-4-QVGdxVfWziBMr7li4tvKEAlRxKA2a9mkV6S/lsparams/hls_chunk_host,mh,mm,mn,ms,mv,mvi,pl,initcwndbps/lsig/AG3C_xAwRAIgaFIedoacVYMdmwUbXEKV24-CYznlW6Im4WZoGsJuvC4CIFOxUwmfyWREW67tpdH95n2jkxVRbMMdvMCTmsqiLoD2/playlist/index.m3u8";
vbr = "196.213";
vcodec = "avc1.4D400C";
"video_ext" = mp4;
width = 256;

@pukkandan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@someziggyman The file size estimation was added in f2fe69c and was aimed at http formats. It has been noticed for a long time that this gives wrong results for m3u8/dash. Hence why I've decided to remove it for such formats now. The estimate is still shown in -F just for convenience. If you want the old "bad" estimate, just do tbr * duration manually

@someziggyman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your explanation and apologies for the trouble! Thought I've caught something, but turned out just a newbie comment.

Please sign in to comment.