1
# -*- coding: utf-8 -*-
3
# Author: Ingelrest François (Francois.Ingelrest@gmail.com)
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU Library General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
def createFileTrack(file, bitrate, length, samplerate, isVBR, title=None, album=None, artist=None, albumArtist=None,
21
musicbrainzId=None, genre=None, trackNumber=None, date=None, discNumber=None):
22
""" Create a new FileTrack object based on the given information """
23
from media.track.fileTrack import FileTrack
25
track = FileTrack(file)
27
track.setLength(length)
28
track.setBitrate(bitrate)
29
track.setSampleRate(samplerate)
32
track.setVariableBitrate()
40
if artist is not None:
41
track.setArtist(artist)
43
if albumArtist is not None:
44
track.setAlbumArtist(albumArtist)
46
if musicbrainzId is not None:
47
track.setMBTrackId(musicbrainzId)
53
try: track.setDate(int(date))
56
# The format of the track number may be 'X' or 'X/Y'
57
# We discard Y since we don't use this information
58
if trackNumber is not None:
59
try: track.setNumber(int(trackNumber.split('/')[0]))
62
# The format of the disc number may be 'X' or 'X/Y'
63
# We discard the disc number when Y is less than 2
64
if discNumber is not None:
66
discNumber = discNumber.split('/')
68
if len(discNumber) == 1 or int(discNumber[1]) > 1:
69
track.setDiscNumber(int(discNumber[0]))