Compare commits
7 Commits
bded5e8990
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f9c3ea08b | ||
|
|
1e6167a1ae | ||
|
|
31f8cf2047 | ||
|
|
f5393cda3b | ||
|
|
3e8f868d87 | ||
|
|
6b9999a414 | ||
|
|
de952cc314 |
26
panasonic.py
26
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']))
|
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
|
fid = fid + 1
|
||||||
|
|
||||||
def getInitialTSFromBuffer(content):
|
def getInitialTSFromBuffer(content, delta=0.1):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
logger.debug('Determining initial timestamp from content')
|
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:
|
length = len(content)
|
||||||
out, _ = ffprobe.communicate(input=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))
|
frames = json.load(BytesIO(out))
|
||||||
logger.debug('Frames: %s' % frames)
|
logger.debug('Frames: %s' % frames)
|
||||||
if 'frames' in frames:
|
if 'frames' in frames:
|
||||||
@@ -224,7 +225,7 @@ def getLastTSFromFD(fd):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def downloadMovie(url, outputFileName, duration):
|
def downloadMovie(url, outputFileName):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -234,7 +235,7 @@ def downloadMovie(url, outputFileName, duration):
|
|||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
outputFD = output.fileno()
|
outputFD = output.fileno()
|
||||||
session = sessions.Session()
|
session = requests.Session()
|
||||||
|
|
||||||
sample = 2.
|
sample = 2.
|
||||||
headers = {'TimeSeekRange.dlna.org': 'npt=0.000-%.03f' % sample}
|
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)
|
logger.error('TimeSeekRange.dlna.org is not in header: %s' % r.headers)
|
||||||
exit(-1)
|
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'])
|
m = p.match(r.headers['TimeSeekRange.dlna.org'])
|
||||||
if m == None:
|
if m == None:
|
||||||
logger.error('Impossible to parse timestamps' % r.headers['TimeSeekRange.dlna.org'])
|
logger.error('Impossible to parse timestamps' % r.headers['TimeSeekRange.dlna.org'])
|
||||||
@@ -257,8 +258,16 @@ def downloadMovie(url, outputFileName, duration):
|
|||||||
total = timedelta(seconds=total)
|
total = timedelta(seconds=total)
|
||||||
logger.debug('Header: %s' % r.headers)
|
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)
|
logger.debug('Initial timestamp: %s' % initialTS)
|
||||||
|
if initialTS == None:
|
||||||
|
logger.error('Impossible to retrieve initial timestamp')
|
||||||
|
exit(-1)
|
||||||
lastTS = getLastTSFromBuffer(r.content)
|
lastTS = getLastTSFromBuffer(r.content)
|
||||||
logger.debug('Last timestamp: %s' % lastTS)
|
logger.debug('Last timestamp: %s' % lastTS)
|
||||||
delta = lastTS-initialTS
|
delta = lastTS-initialTS
|
||||||
@@ -277,6 +286,7 @@ def downloadMovie(url, outputFileName, duration):
|
|||||||
output.write(chunk)
|
output.write(chunk)
|
||||||
if nbiters == 1000:
|
if nbiters == 1000:
|
||||||
lastTS = getLastTSFromFD(outputFD)
|
lastTS = getLastTSFromFD(outputFD)
|
||||||
|
if lastTS != None:
|
||||||
delta = lastTS-initialTS
|
delta = lastTS-initialTS
|
||||||
ratio = delta/total
|
ratio = delta/total
|
||||||
length = fstat(outputFD).st_size
|
length = fstat(outputFD).st_size
|
||||||
@@ -359,7 +369,7 @@ def main():
|
|||||||
t = timedelta(seconds=duration)
|
t = timedelta(seconds=duration)
|
||||||
|
|
||||||
logger.info('Downloading movie "%s" whose duration is %s' % (title, t))
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user