def addMusic(self, sItem, queue):
        mode = sItem.getLive('music')
        if mode == 'off':
            return

        if mode == 'content':
            queue.music = [
                Song(s.path, s.duration)
                for s in DB.Song.select().order_by(DB.fn.Random())
            ]
        elif mode == 'dir':
            path = sItem.getLive('musicDir')
            if not path:
                return

            import mutagen
            mutagen.setFileOpener(util.vfs.File)

            queue.music = []
            for p in util.listFilePaths(path):
                try:
                    data = mutagen.File(p)
                except:
                    data = None
                    util.ERROR()

                d = 0
                if data:
                    d = data.info.length
                queue.music.append(Song(p, d))

            random.shuffle(queue.music)
        elif mode == 'file':
            path = sItem.getLive('musicFile')
            if not path:
                return

            import mutagen
            mutagen.setFileOpener(util.vfs.File)

            data = mutagen.File(path)
            d = 0
            if data:
                d = data.info.length
            queue.music = [Song(path, d)]

        duration = sum([s.duration for s in queue.music])

        if duration:  # Maybe they were all zero - we'll be here forever :)
            while duration < queue.duration:
                for i in range(len(queue.music)):
                    song = queue.music[i]
                    duration += song.duration
                    queue.music.append(song)
                    if duration >= queue.duration:
                        break

        queue.musicVolume = util.getSettingDefault('trivia.musicVolume')
        queue.musicFadeIn = util.getSettingDefault('trivia.musicFadeIn')
        queue.musicFadeOut = util.getSettingDefault('trivia.musicFadeOut')
    def addMusic(self, sItem, queue):
        mode = sItem.getLive('music')
        if mode == 'off':
            return

        if mode == 'content':
            queue.music = [Song(s.path, s.duration) for s in DB.Song.select().order_by(DB.fn.Random())]
        elif mode == 'dir':
            path = sItem.getLive('musicDir')
            if not path:
                return

            import mutagen
            mutagen.setFileOpener(util.vfs.File)

            queue.music = []
            for p in util.listFilePaths(path):
                try:
                    data = mutagen.File(p)
                except:
                    data = None
                    util.ERROR()

                d = 0
                if data:
                    d = data.info.length
                queue.music.append(Song(p, d))

            random.shuffle(queue.music)
        elif mode == 'file':
            path = sItem.getLive('musicFile')
            if not path:
                return

            import mutagen
            mutagen.setFileOpener(util.vfs.File)

            data = mutagen.File(path)
            d = 0
            if data:
                d = data.info.length
            queue.music = [Song(path, d)]

        duration = sum([s.duration for s in queue.music])

        if duration:  # Maybe they were all zero - we'll be here forever :)
            while duration < queue.duration:
                for i in range(len(queue.music)):
                    song = queue.music[i]
                    duration += song.duration
                    queue.music.append(song)
                    if duration >= queue.duration:
                        break

        queue.musicVolume = util.getSettingDefault('trivia.musicVolume')
        queue.musicFadeIn = util.getSettingDefault('trivia.musicFadeIn')
        queue.musicFadeOut = util.getSettingDefault('trivia.musicFadeOut')
Beispiel #3
0
import os
import re
from xml.etree import ElementTree as ET

import util
import mutagen
import hachoir
import database as DB

try:
    ET.ParseError
except:
    ET.ParseError = Exception

mutagen.setFileOpener(util.vfs.File)

TYPE_IDS = {
    '3D Intro': '3D.intro',
    '3D Outro': '3D.outro',
    'Countdown': 'countdown',
    'Courtesy': 'courtesy',
    'Feature Intro': 'feature.intro',
    'Feature Outro': 'feature.outro',
    'Intermission': 'intermission',
    'Short Film': 'short.film',
    'Theater Intro': 'theater.intro',
    'Theater Outro': 'theater.outro',
    'Trailers Intro': 'trailers.intro',
    'Trailers Outro': 'trailers.outro',
    'Trivia Intro': 'trivia.intro',
    'Trivia Outro': 'trivia.outro'
import os
import re
from xml.etree import ElementTree as ET

import util
import mutagen
import hachoir
import database as DB

try:
    ET.ParseError
except:
    ET.ParseError = Exception

mutagen.setFileOpener(util.vfs.File)

TYPE_IDS = {
    '3D Intro':       '3D.intro',
    '3D Outro':       '3D.outro',
    'Countdown':      'countdown',
    'Courtesy':       'courtesy',
    'Feature Intro':  'feature.intro',
    'Feature Outro':  'feature.outro',
    'Intermission':   'intermission',
    'Short Film':     'short.film',
    'Theater Intro':  'theater.intro',
    'Theater Outro':  'theater.outro',
    'Trailers Intro': 'trailers.intro',
    'Trailers Outro': 'trailers.outro',
    'Trivia Intro':   'trivia.intro',
    'Trivia Outro':   'trivia.outro'