1
1
from __future__ import annotations
2
2
3
3
import mimetypes
4
- from asyncio import get_event_loop , shield , wait_for
4
+ from asyncio import get_event_loop , shield
5
5
from binascii import hexlify , unhexlify
6
6
from pathlib import Path , PurePosixPath
7
7
from typing import TYPE_CHECKING , Any , Optional , TypedDict , cast
19
19
from tribler .core .libtorrent .download_manager .download_config import DownloadConfig
20
20
from tribler .core .libtorrent .download_manager .download_manager import DownloadManager
21
21
from tribler .core .libtorrent .download_manager .download_state import DOWNLOAD , UPLOAD , DownloadStatus
22
- from tribler .core .libtorrent .download_manager .stream import Stream , StreamChunk
22
+ from tribler .core .libtorrent .download_manager .stream import Stream , StreamReader
23
23
from tribler .core .libtorrent .torrentdef import TorrentDef
24
24
from tribler .core .restapi .rest_endpoint import (
25
25
HTTP_BAD_REQUEST ,
@@ -249,8 +249,6 @@ def get_files_info_json_paged(download: Download, view_start: Path, view_size: i
249
249
"availability" : Float ,
250
250
"peers" : String ,
251
251
"total_pieces" : Integer ,
252
- "vod_prebuffering_progress" : Float ,
253
- "vod_prebuffering_progress_consec" : Float ,
254
252
"error" : String ,
255
253
"time_added" : Integer
256
254
}),
@@ -336,16 +334,9 @@ async def get_downloads(self, request: Request) -> RESTResponse: # noqa: C901
336
334
"completed_dir" : download .config .get_completed_dir (),
337
335
"total_pieces" : tdef .get_nr_pieces (),
338
336
"error" : repr (state .get_error ()) if state .get_error () else "" ,
339
- "time_added" : download .config .get_time_added ()
337
+ "time_added" : download .config .get_time_added (),
338
+ "streamable" : bool (tdef and tdef .get_files_with_length ({'mp4' , 'm4v' , 'mov' , 'mkv' }))
340
339
}
341
- if download .stream :
342
- info .update ({
343
- "vod_prebuffering_progress" : download .stream .prebuffprogress ,
344
- "vod_prebuffering_progress_consec" : download .stream .prebuffprogress_consec ,
345
- "vod_header_progress" : download .stream .headerprogress ,
346
- "vod_footer_progress" : download .stream .footerprogress ,
347
-
348
- })
349
340
350
341
if unfiltered or params .get ("infohash" ) == info ["infohash" ]:
351
342
# Add peers information if requested
@@ -1137,11 +1128,8 @@ async def prepare(self, request: BaseRequest) -> AbstractStreamWriter | None:
1137
1128
stream = self ._download .stream
1138
1129
1139
1130
start = start or 0
1140
- if not stream .enabled or stream .fileindex != self ._file_index :
1141
- await wait_for (stream .enable (self ._file_index , start ), 10 )
1142
- await stream .updateprios ()
1143
-
1144
- reader = StreamChunk (self ._download .stream , start )
1131
+ await stream .enable (self ._file_index )
1132
+ reader = StreamReader (stream , start )
1145
1133
await reader .open ()
1146
1134
try :
1147
1135
writer = await super ().prepare (request )
@@ -1153,7 +1141,7 @@ async def prepare(self, request: BaseRequest) -> AbstractStreamWriter | None:
1153
1141
while data :
1154
1142
await writer .write (data [:todo ])
1155
1143
todo -= len (data )
1156
- if todo <= 0 :
1144
+ if todo <= 0 or len ( data ) == 0 :
1157
1145
break
1158
1146
data = await reader .read ()
1159
1147
0 commit comments