feat(convert): ajoute la fouille des fichiers audio

master
François Poulain 2 years ago
parent 926b1bd91f
commit d020005721
  1. 23
      drupal2spip_lal/base/convert.py
  2. 4
      requirements/base.txt

@ -9,6 +9,7 @@ from django.conf import settings
from django.db.models import F
from django.utils.timezone import make_aware, now
import mediafile
import request
from bs4 import BeautifulSoup as bs
@ -68,6 +69,7 @@ def download(src, filename, force_download):
with open(path, 'wb') as fd:
for chunk in r.iter_content(chunk_size=128):
fd.write(chunk)
return path
def fetch_document(src, filename, force_download):
@ -80,11 +82,12 @@ def fetch_document(src, filename, force_download):
logger.warn('Echec à creer le dossier: {}'.format(e))
cible = os.path.join(extension, filename)
path = None
try:
download(src, cible, force_download)
path = download(src, cible, force_download)
except Exception as e:
logger.warn('Echec au download: {}'.format(e))
return extension, cible
return extension, cible, path
def fetch_and_remove_logo(article, force_download):
@ -376,7 +379,7 @@ def convert_node(node, options):
is_image = upload.file.filemime in images_mimes
is_video = upload.file.filemime in video_mimes
extension, fichier = fetch_document(
extension, fichier, path = fetch_document(
upload.file.filepath, upload.file.filename, force_download
)
@ -396,7 +399,19 @@ def convert_node(node, options):
document_attributes['largeur'] = 1
elif is_audio:
document_attributes['media'] = 'audio'
document_attributes['duree'] = 1
try:
m = mediafile.MediaFile(path)
document_attributes['duree'] = m.length
if m.artist and m.album:
document_attributes['credits'] = '{} / {}'.format(
m.artist, m.album
)
elif m.artist:
document_attributes['credits'] = m.artist
elif m.album:
document_attributes['credits'] = m.album
except Exception as e:
logger.warn('Echec de lecture: {}'.format(e))
elif is_video:
document_attributes['media'] = 'video'
document_attributes['duree'] = 1

@ -15,3 +15,7 @@ beautifulsoup4
# Logs
# ------------------------------------------------------------------------------
colorlog
# Media
# ------------------------------------------------------------------------------
mediafile

Loading…
Cancel
Save