~jwiltshire/pogo/debian

« back to all changes in this revision

Viewing changes to src/media/format/__init__.py

  • Committer: Jonathan Wiltshire
  • Date: 2010-12-20 23:52:57 UTC
  • Revision ID: git-v1:e24ab7d692aa9fecd89514fbd769b83b9db2dd55
Tags: upstream/0.3
Imported Upstream version 0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Author: Ingelrest François (Francois.Ingelrest@gmail.com)
 
4
#
 
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.
 
9
#
 
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.
 
14
#
 
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
 
18
 
 
19
 
 
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
 
24
 
 
25
    track = FileTrack(file)
 
26
 
 
27
    track.setLength(length)
 
28
    track.setBitrate(bitrate)
 
29
    track.setSampleRate(samplerate)
 
30
 
 
31
    if isVBR:
 
32
        track.setVariableBitrate()
 
33
 
 
34
    if title is not None:
 
35
        track.setTitle(title)
 
36
 
 
37
    if album is not None:
 
38
        track.setAlbum(album)
 
39
 
 
40
    if artist is not None:
 
41
        track.setArtist(artist)
 
42
 
 
43
    if albumArtist is not None:
 
44
        track.setAlbumArtist(albumArtist)
 
45
 
 
46
    if musicbrainzId is not None:
 
47
        track.setMBTrackId(musicbrainzId)
 
48
 
 
49
    if genre is not None:
 
50
        track.setGenre(genre)
 
51
 
 
52
    if date is not None:
 
53
        try:    track.setDate(int(date))
 
54
        except: pass
 
55
 
 
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]))
 
60
        except: pass
 
61
 
 
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:
 
65
        try:
 
66
            discNumber = discNumber.split('/')
 
67
 
 
68
            if len(discNumber) == 1 or int(discNumber[1]) > 1:
 
69
                track.setDiscNumber(int(discNumber[0]))
 
70
        except:
 
71
            pass
 
72
 
 
73
    return track