我正在尝试投票以查看youtube-dl作业的状态。我无法弄清楚如何让它发挥作用。
以下是我的python-rq worker.py文件
class MyLogger(object):
def debug(self, msg):
pass
def warning(self, msg):
pass
def error(self, msg):
print(msg)
def my_hook(d):
if d['status'] == 'finished':
print('Done downloading, now converting ...')
ydl_opts = {
'format': 'bestaudio/best', # choice of quality
'extractaudio' : True, # only keep the audio
'outtmpl': temp_filepath, # name the location
'noplaylist' : True, # only download single song, not playlist
'prefer-ffmpeg' : True,
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
}],
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
result = ydl.download([url])
在我的主应用程序中,我尝试过各种变化,但仍然无法获得logger / my_hook输出。
job = q.fetch_job(job_id)
一旦我有了job_id,我似乎唯一能得到的就是job.result,如果它没有完成只返回None
,我会尝试打印以查看状态但似乎无法找到它。
我可能正在考虑将my_hood或logger写入一个单独的临时文件,我可以读取该行,但我认为这可能过多了? 任何帮助将不胜感激或可能的解决方法。
答案 0 :(得分:1)
在github isues的一些帮助之后,我能够使用get_current_job来更新它并将其传递给meta。
import java.io.File;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyID;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.PrefixManager;
import org.semanticweb.owlapi.reasoner.InferenceType;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory;
import org.semanticweb.owlapi.util.DefaultPrefixManager;
public class Fauna {
private final static OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
private final static OWLDataFactory df = manager.getOWLDataFactory();
private final static OWLReasonerFactory rf = new StructuralReasonerFactory();
private final OWLOntology ontology;
private final OWLOntologyID id;
private final IRI iri;
private final PrefixManager pm;
private final OWLReasoner reasoner;
private final OWLObjectPropertyExpression arePartsOf;
private final TreeSet<OWLClass> clsParts = new TreeSet<>();
/**
*
* @param file
* @throws OWLOntologyCreationException
*/
public Fauna(File file) throws OWLOntologyCreationException {
ontology = manager.loadOntologyFromOntologyDocument(file);
id = ontology.getOntologyID();
iri = id.getOntologyIRI();
pm = new DefaultPrefixManager(iri.toString().concat("#"));
reasoner = rf.createReasoner(ontology);
reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_ASSERTIONS);
arePartsOf = df.getOWLObjectProperty(IRI.create(iri + "#arePartsOf"));
for (String s : new String[] { "Eyes", "Ears", "Legs" }) {
OWLClass cls = df.getOWLClass(":" + s, pm);
clsParts.add(cls);
}
}
/**
*
* @param individual
* @return
*/
private Set<OWLNamedIndividual> getPartsOfSameSpecies(OWLNamedIndividual individual) {
if (!ontology.containsIndividualInSignature(individual.getIRI())) {
return null;
}
Set<OWLClass> types = reasoner.getTypes(individual, true).getFlattened();
if (Collections.disjoint(clsParts, types)) {
return null;
}
Set<OWLNamedIndividual> values = reasoner.getObjectPropertyValues(individual, arePartsOf).getFlattened();
if (values == null || values.size() != 1) {
return null;
}
OWLNamedIndividual species = values.iterator().next();
return this.getParts(species);
}
/**
*
* @param species
* @return
*/
public Set<OWLNamedIndividual> getParts(OWLNamedIndividual species) {
HashSet<OWLNamedIndividual> individuals = new HashSet<>();
for (OWLClass cls : clsParts) {
for (OWLIndividual i : cls.getIndividuals(ontology)) {
OWLNamedIndividual part = i.asOWLNamedIndividual();
if (!reasoner.getObjectPropertyValues(part, arePartsOf).containsEntity(species)) {
continue;
}
individuals.add(part);
}
}
return individuals;
}
}