See #170: fixed several feed parsing issues
This commit is contained in:
parent
b43d0f7009
commit
a119a5d90a
|
@ -589,13 +589,21 @@ def get_cached_upload(uploads, expected_track_uuid):
|
|||
return upload
|
||||
|
||||
|
||||
class PermissiveIntegerField(serializers.IntegerField):
|
||||
def to_internal_value(self, v):
|
||||
try:
|
||||
return super().to_internal_value(v)
|
||||
except serializers.ValidationError:
|
||||
return self.default
|
||||
|
||||
|
||||
class RssFeedItemSerializer(serializers.Serializer):
|
||||
id = serializers.CharField()
|
||||
title = serializers.CharField()
|
||||
rights = serializers.CharField(required=False, allow_blank=True)
|
||||
itunes_season = serializers.IntegerField(required=False)
|
||||
itunes_episode = serializers.IntegerField(required=False)
|
||||
itunes_duration = ItunesDurationField()
|
||||
itunes_episode = PermissiveIntegerField(required=False, default=None)
|
||||
itunes_duration = ItunesDurationField(required=False)
|
||||
links = serializers.ListField()
|
||||
tags = serializers.ListField(required=False)
|
||||
summary_detail = serializers.DictField(required=False)
|
||||
|
@ -627,12 +635,12 @@ class RssFeedItemSerializer(serializers.Serializer):
|
|||
if row.get("rel") != "enclosure":
|
||||
continue
|
||||
try:
|
||||
size = int(row.get("length"))
|
||||
size = int(row.get("length", 0)) or None
|
||||
except (TypeError, ValueError):
|
||||
raise serializers.ValidationError("Invalid size")
|
||||
|
||||
data["audio"] = {
|
||||
"mimetype": row["type"],
|
||||
"mimetype": common_utils.get_audio_mimetype(row["type"]),
|
||||
"size": size,
|
||||
"source": row["href"],
|
||||
}
|
||||
|
@ -703,7 +711,7 @@ class RssFeedItemSerializer(serializers.Serializer):
|
|||
"source": validated_data["links"]["audio"]["source"],
|
||||
"size": validated_data["links"]["audio"]["size"],
|
||||
"mimetype": validated_data["links"]["audio"]["mimetype"],
|
||||
"duration": validated_data["itunes_duration"],
|
||||
"duration": validated_data.get("itunes_duration"),
|
||||
"import_status": "finished",
|
||||
"library": channel.library,
|
||||
}
|
||||
|
|
|
@ -396,3 +396,8 @@ def get_mimetype_from_ext(path):
|
|||
"gif": "image/gif",
|
||||
}
|
||||
return match.get(ext)
|
||||
|
||||
|
||||
def get_audio_mimetype(mt):
|
||||
aliases = {"audio/x-mp3": "audio/mpeg", "audio/mpeg3": "audio/mpeg"}
|
||||
return aliases.get(mt, mt)
|
||||
|
|
|
@ -37,10 +37,13 @@ def compute_status(jobs):
|
|||
|
||||
|
||||
AUDIO_EXTENSIONS_AND_MIMETYPE = [
|
||||
# keep the most correct mimetype for each extension at the bottom
|
||||
("mp3", "audio/mpeg3"),
|
||||
("mp3", "audio/x-mp3"),
|
||||
("mp3", "audio/mpeg"),
|
||||
("ogg", "video/ogg"),
|
||||
("ogg", "audio/ogg"),
|
||||
("opus", "audio/opus"),
|
||||
("mp3", "audio/mpeg"),
|
||||
("aac", "audio/x-m4a"),
|
||||
("m4a", "audio/x-m4a"),
|
||||
("flac", "audio/x-flac"),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<time :datetime="`${duration}s`">
|
||||
<template v-if="durationObj.hours">{{ durationObj.hours|padDuration }}</template>{{ durationObj.minutes|padDuration }}:{{ durationObj.seconds|padDuration }}
|
||||
<template v-if="durationObj.hours">{{ durationObj.hours|padDuration }}:</template>{{ durationObj.minutes|padDuration }}:{{ durationObj.seconds|padDuration }}
|
||||
</time>
|
||||
|
||||
</template>
|
||||
|
|
Loading…
Reference in New Issue