Can you please send one of the audio files you are unable to import to support(at)lingq.com? I’d like to try importing it on my end, since I am unable to reproduce the issue with various audio files I tried to import. Thanks a lot!
I’m also hitting 500 errors when attempting any upload through the v2 lessons API. Here is an example without any mp3 that ends up in a 500 error on my side:
I am trying to write an uploading script for a set of podcast mp3s that I would like to upload to lingq. While I have not personally had this working before, I’ve been following along examples such as Python - uploading audio via API - #5 by mescyn that have worked for folks before.
I did eventually get text-only uploading to work with an explicit ‘Content-Type’ of ‘application/json’. I’ve had no luck getting mp3 uploads going.
I would very much appreciate guidance on how to upload mp3s via the lingq API. I want to avoid RSI from manually uploading the 100 or so MP3s I have. I’ll open a separate thread for that.
@Chipmaster sent you some code that that should help. I probably wouldn’t send 100 mp3s to be transcribed at once. If you’re uploading with a transcript should be fine to do 100 in a row. Server seems to struggle with 3-4 concurrent transcribes. You can also download my Course Upload Extension Source Code to find the solution I wrote for audio uploading in Javascript.
Thank you for your github link. with a few adjustment(copy-paste his code into mine), it is running now.
you need to put the text file in “textfiles” folder and mp3 files in “mp3files”.
Based on their names it will zip them and upload them to lingq.
List will look like this [(1.txt, 1.mp3])
Also you should install requests_toolbelt
#!/usr/bin/env python
import requests, os
from requests_toolbelt.multipart.encoder import MultipartEncoder
from glob import glob
API_KEY = "YOURAPIKEY"
postAddress = "https://www.lingq.com/api/v3/YOURLANGUAGE/lessons/import/"
collection = "YOURCOURSE"
listoftxts = glob("textfiles/*.txt")
listofmp3s = glob("mp3files/*.mp3")
for textfile, audiofile in list(zip(listoftxts, listofmp3s)):
print("Uploading")
title = audiofile.replace('.mp3', '').replace("mp3files/","")
with open(textfile, 'r', errors='ignore') as f:
text = f.read()
with open(audiofile, 'rb') as f:
audio = f.read()
m = MultipartEncoder([
('title', title),
('text', text),
('collection', collection),
('audio', (audiofile, audio, 'audio/mpeg')),
('save', "true")
])
h = {'Authorization': 'Token ' + API_KEY,
'Content-Type': m.content_type}
r = requests.post(postAddress, data=m, headers=h)
print("Status Code: ", r.status_code)
print("https://www.lingq.com/en/learn/YOURLANGUAGE/web/reader/"+str(r.json()["id"]))