Compare commits
7 Commits
bded5e8990
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f9c3ea08b | ||
|
|
1e6167a1ae | ||
|
|
31f8cf2047 | ||
|
|
f5393cda3b | ||
|
|
3e8f868d87 | ||
|
|
6b9999a414 | ||
|
|
de952cc314 |
36
panasonic.py
36
panasonic.py
@@ -150,12 +150,13 @@ def dumpFilms(films):
|
||||
logger.info('%d - %s enregistré le %s sur %s. Durée: %s. %s' % (fid, film['title'], film['date'], film['channel'], film['duration'], film['url']))
|
||||
fid = fid + 1
|
||||
|
||||
def getInitialTSFromBuffer(content):
|
||||
def getInitialTSFromBuffer(content, delta=0.1):
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
logger.debug('Determining initial timestamp from content')
|
||||
with Popen(['ffprobe','/dev/stdin','-loglevel', 'quiet', '-read_intervals', '0%+0.1', '-show_entries', 'frame=frame_no,best_effort_timestamp_time', '-of','json'], stdout=PIPE, stdin=PIPE) as ffprobe:
|
||||
out, _ = ffprobe.communicate(input=content)
|
||||
length = len(content)
|
||||
with Popen(['ffprobe','/dev/stdin','-loglevel', 'quiet', '-read_intervals', ('0%%+%f' % delta), '-show_entries', 'frame=frame_no,best_effort_timestamp_time', '-of','json'], stdout=PIPE, stdin=PIPE) as ffprobe:
|
||||
out, _ = ffprobe.communicate(input=content[0:min(length,200000)])
|
||||
frames = json.load(BytesIO(out))
|
||||
logger.debug('Frames: %s' % frames)
|
||||
if 'frames' in frames:
|
||||
@@ -224,7 +225,7 @@ def getLastTSFromFD(fd):
|
||||
else:
|
||||
return None
|
||||
|
||||
def downloadMovie(url, outputFileName, duration):
|
||||
def downloadMovie(url, outputFileName):
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
@@ -234,7 +235,7 @@ def downloadMovie(url, outputFileName, duration):
|
||||
exit(-1)
|
||||
|
||||
outputFD = output.fileno()
|
||||
session = sessions.Session()
|
||||
session = requests.Session()
|
||||
|
||||
sample = 2.
|
||||
headers = {'TimeSeekRange.dlna.org': 'npt=0.000-%.03f' % sample}
|
||||
@@ -247,7 +248,7 @@ def downloadMovie(url, outputFileName, duration):
|
||||
logger.error('TimeSeekRange.dlna.org is not in header: %s' % r.headers)
|
||||
exit(-1)
|
||||
|
||||
p = re.compile('^.*/(?P<totalsecs>[0-9]+)\.(?P<totalms>[0-9]+)$')
|
||||
p = re.compile(r'^.*/(?P<totalsecs>[0-9]+)\.(?P<totalms>[0-9]+)$')
|
||||
m = p.match(r.headers['TimeSeekRange.dlna.org'])
|
||||
if m == None:
|
||||
logger.error('Impossible to parse timestamps' % r.headers['TimeSeekRange.dlna.org'])
|
||||
@@ -257,8 +258,16 @@ def downloadMovie(url, outputFileName, duration):
|
||||
total = timedelta(seconds=total)
|
||||
logger.debug('Header: %s' % r.headers)
|
||||
|
||||
initialTS = getInitialTSFromBuffer(r.content)
|
||||
initialTS = None
|
||||
nbRetries = 0
|
||||
maxRetries = 10
|
||||
while initialTS == None and nbRetries < maxRetries:
|
||||
initialTS = getInitialTSFromBuffer(r.content, delta=0.1*nbRetries)
|
||||
nbRetries = nbRetries+1
|
||||
logger.debug('Initial timestamp: %s' % initialTS)
|
||||
if initialTS == None:
|
||||
logger.error('Impossible to retrieve initial timestamp')
|
||||
exit(-1)
|
||||
lastTS = getLastTSFromBuffer(r.content)
|
||||
logger.debug('Last timestamp: %s' % lastTS)
|
||||
delta = lastTS-initialTS
|
||||
@@ -277,11 +286,12 @@ def downloadMovie(url, outputFileName, duration):
|
||||
output.write(chunk)
|
||||
if nbiters == 1000:
|
||||
lastTS = getLastTSFromFD(outputFD)
|
||||
delta = lastTS-initialTS
|
||||
ratio = delta/total
|
||||
length = fstat(outputFD).st_size
|
||||
estimatedLength = ceil(length/ratio)
|
||||
pb.total = estimatedLength
|
||||
if lastTS != None:
|
||||
delta = lastTS-initialTS
|
||||
ratio = delta/total
|
||||
length = fstat(outputFD).st_size
|
||||
estimatedLength = ceil(length/ratio)
|
||||
pb.total = estimatedLength
|
||||
lseek(outputFD, 0, SEEK_END)
|
||||
nbiters = 0
|
||||
pb.update(len(chunk))
|
||||
@@ -359,7 +369,7 @@ def main():
|
||||
t = timedelta(seconds=duration)
|
||||
|
||||
logger.info('Downloading movie "%s" whose duration is %s' % (title, t))
|
||||
downloadMovie(url=films[mid]['url'], outputFileName=args.output, duration=duration)
|
||||
downloadMovie(url=films[mid]['url'], outputFileName=args.output)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user