audio: Add support for GLib.Date tag values
This commit is contained in:
parent
0fa78b8e39
commit
f877ac0807
@ -1,12 +1,13 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import collections
|
||||
import datetime
|
||||
import logging
|
||||
import numbers
|
||||
|
||||
import gi
|
||||
gi.require_version('Gst', '1.0')
|
||||
from gi.repository import Gst
|
||||
from gi.repository import GLib, Gst
|
||||
Gst.is_initialized() or Gst.init()
|
||||
|
||||
from mopidy import compat
|
||||
@ -46,6 +47,10 @@ gstreamer-GstTagList.html
|
||||
for i in range(taglist.get_tag_size(tag)):
|
||||
value = taglist.get_value_index(tag, i)
|
||||
|
||||
if isinstance(value, GLib.Date):
|
||||
date = datetime.date(
|
||||
value.get_year(), value.get_month(), value.get_day())
|
||||
result[tag].append(date.isoformat().decode('utf-8'))
|
||||
if isinstance(value, Gst.DateTime):
|
||||
result[tag].append(value.to_iso8601_string().decode('utf-8'))
|
||||
elif isinstance(value, bytes):
|
||||
|
||||
@ -2,12 +2,11 @@
|
||||
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import datetime
|
||||
import unittest
|
||||
|
||||
import gi
|
||||
gi.require_version('Gst', '1.0')
|
||||
from gi.repository import GObject, Gst
|
||||
from gi.repository import GLib, GObject, Gst
|
||||
|
||||
from mopidy import compat
|
||||
from mopidy.audio import tags
|
||||
@ -20,7 +19,7 @@ class TestConvertTaglist(object):
|
||||
taglist = Gst.TagList.new_empty()
|
||||
|
||||
for value in values:
|
||||
if isinstance(value, Gst.DateTime):
|
||||
if isinstance(value, (GLib.Date, Gst.DateTime)):
|
||||
taglist.add_value(Gst.TagMergeMode.APPEND, tag, value)
|
||||
continue
|
||||
|
||||
@ -39,6 +38,15 @@ class TestConvertTaglist(object):
|
||||
|
||||
return taglist
|
||||
|
||||
def test_date_tag(self):
|
||||
date = GLib.Date.new_dmy(7, 1, 2014)
|
||||
taglist = self.make_taglist(Gst.TAG_DATE, [date])
|
||||
|
||||
result = tags.convert_taglist(taglist)
|
||||
|
||||
assert isinstance(result[Gst.TAG_DATE][0], compat.text_type)
|
||||
assert result[Gst.TAG_DATE][0] == '2014-01-07'
|
||||
|
||||
def test_date_time_tag(self):
|
||||
taglist = self.make_taglist(Gst.TAG_DATE_TIME, [
|
||||
Gst.DateTime.new_from_iso8601_string(b'2014-01-07 14:13:12')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user