Commit 081af307 authored by d.basulto's avatar d.basulto

get audios list script

parent 32c440ee
import sys
import argparse
import os
import subprocess
from numpy import array_equal
from datetime import datetime, timedelta
def getRecordingDays(initTimestamp, endTimestamp):
initialDate = datetime.fromtimestamp(initTimestamp) #+ timedelta(hours=6)
endDate = datetime.fromtimestamp(endTimestamp) #+ timedelta(hours=6)
print(initialDate)
print(endDate)
iDate = [initialDate.day, initialDate.month, initialDate.year]
eDate = [endDate.day, endDate.month, endDate.year]
days = 1
if array_equal(iDate, eDate):
# Iterate over the same day dir
return days
else:
while not array_equal(iDate, eDate):
days += 1
initialDate += timedelta(days=1)
iDate = [initialDate.day, initialDate.month, initialDate.year]
return days
def getAudiosList2Convert(streamPublisher, initTimestamp, endTimestamp, days):
recordingsPath = '/home/geoint/virtualHDD/m3/recordings/'
initialDate = datetime.fromtimestamp(initTimestamp) #+ timedelta(hours=6)
endDate = datetime.fromtimestamp(endTimestamp) #+ timedelta(hours=6)
audiosList = []
for i in range(days):
audiosPath = '{0}/{1}/{2:02d}/{3:02d}/'.format(
streamPublisher,
initialDate.year,
initialDate.month,
initialDate.day
)
print('Now enter in: {0}'.format(audiosPath))
if os.path.exists(recordingsPath+audiosPath):
for file in os.listdir(recordingsPath+audiosPath):
audioTimestamp = int(file.split(".")[0])
if audioTimestamp >= initTimestamp and audioTimestamp <= endTimestamp:
audiosList.append(recordingsPath+audiosPath+file)
#audiosList.append((recordingsPath+audiosPath, file))
# Next day dir
initialDate += timedelta(days=1)
return audiosList
def convertAudios2Mp3(audiosList):
mp3Path = '/home/geoint/virtualHDD/m3/recordings/mp3/'
if not os.path.exists(mp3Path):
print('Mp3 created...')
os.mkdir(mp3Path)
for (audioPath, audioName) in audiosList:
timestamp = audioName.split('.')[0]
print('Timestamp: {0} - Date format: {1}'.format(timestamp, datetime.fromtimestamp(float(timestamp))))
mp3Name = timestamp + '.mp3'
convertionCommand = 'ffmpeg -i "{0}" -qscale:a 20 {1}'.format(audioPath+audioName, mp3Path+mp3Name)
subprocess.run(convertionCommand, shell=True)
def getAudiosList(streamPublisher, initTimestamp, endTimestamp):
initTimestamp = float(initTimestamp)
endTimestamp = float(endTimestamp)
days = getRecordingDays(initTimestamp, endTimestamp)
print('Recording days: {0}'.format(days))
audiosList = getAudiosList2Convert(streamPublisher, initTimestamp, endTimestamp, days)
return audiosList
# TODO
#convertAudios2Mp3(audiosList)
# Make soup!
# def getArgs():
# """ program helper """
# parser = argparse.ArgumentParser(
# description='MP3 audio soup maker',
# epilog='Use: \n'
# + '\t python mergeAudio.py -n RadioFormula1041 -i 1000000 -e 2000000\n',
# formatter_class=argparse.RawTextHelpFormatter)
# # required parameters
# requiredNamed = parser.add_argument_group('Requiered Arguments')
# parser.add_argument(
# '-n','-name',
# action='store',
# dest='streamPublisher',
# help='Stream publisher name, e.g RadioFormula1033, NoticiasMVS1245',
# required=True
# )
# parser.add_argument(
# '-i','-init',
# action='store',
# dest='initTimestamp',
# help='e.g. 15123789',
# required=True
# )
# parser.add_argument(
# '-e','-end',
# action='store',
# dest='endTimestamp',
# help='e.g. 15123789',
# required=True
# )
# # parse the args
# args = parser.parse_args()
# return args
# if __name__ == '__main__':
# args = getArgs()
# # original parameters
# streamPublisher = args.streamPublisher
# initTimestamp = float(args.initTimestamp)
# endTimestamp = float(args.endTimestamp)
# makeAudioSoup(streamPublisher, initTimestamp, endTimestamp)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment