forked from upstream/IPod-Shuffle-4g
Made mutagen import optional
This commit is contained in:
parent
a21b0a2fe1
commit
3ff22a4950
1 changed files with 44 additions and 26 deletions
|
|
@ -1,11 +1,11 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Builtin libraries
|
||||
import sys
|
||||
import struct
|
||||
import urllib.request, urllib.parse, urllib.error
|
||||
import os
|
||||
import hashlib
|
||||
import mutagen
|
||||
import binascii
|
||||
import subprocess
|
||||
import collections
|
||||
import errno
|
||||
|
|
@ -15,6 +15,12 @@ import re
|
|||
import tempfile
|
||||
import signal
|
||||
|
||||
# External libraries
|
||||
try:
|
||||
import mutagen
|
||||
except ImportError:
|
||||
mutagen = None
|
||||
|
||||
audio_ext = (".mp3", ".m4a", ".m4b", ".m4p", ".aa", ".wav")
|
||||
list_ext = (".pls", ".m3u")
|
||||
def make_dir_if_absent(path):
|
||||
|
|
@ -359,6 +365,9 @@ class Track(Record):
|
|||
self["filetype"] = 2
|
||||
|
||||
text = os.path.splitext(os.path.basename(filename))[0]
|
||||
|
||||
# Try to get album and artist information with mutagen
|
||||
if mutagen:
|
||||
audio = None
|
||||
try:
|
||||
audio = mutagen.File(filename, easy = True)
|
||||
|
|
@ -622,10 +631,15 @@ class Shuffler(object):
|
|||
self.lists.append(os.path.abspath(dirpath))
|
||||
|
||||
if self.auto_id3_playlists != None:
|
||||
if mutagen:
|
||||
for grouped_list in group_tracks_by_id3_template(self.tracks, self.auto_id3_playlists):
|
||||
self.lists.append(grouped_list)
|
||||
else:
|
||||
print("Error: No mutagen found. Cannot generate auto-id3-playlists.")
|
||||
sys.exit(1)
|
||||
|
||||
def write_database(self):
|
||||
print("Writing database. This may take a while...")
|
||||
with open(os.path.join(self.path, "iPod_Control", "iTunes", "iTunesSD"), "wb") as f:
|
||||
try:
|
||||
f.write(self.tunessd.construct())
|
||||
|
|
@ -633,6 +647,7 @@ class Shuffler(object):
|
|||
print("I/O error({0}): {1}".format(e.errno, e.strerror))
|
||||
print("Error: Writing iPod database failed.")
|
||||
sys.exit(1)
|
||||
|
||||
print("Database written successfully:")
|
||||
print("Tracks", len(self.tracks))
|
||||
print("Albums", len(self.albums))
|
||||
|
|
@ -740,6 +755,9 @@ if __name__ == '__main__':
|
|||
if result.rename_unicode:
|
||||
check_unicode(result.path)
|
||||
|
||||
if not mutagen:
|
||||
print("Warning: No mutagen found. Database will not contain any album nor artist information.")
|
||||
|
||||
verboseprint("Playlist voiceover requested:", result.playlist_voiceover)
|
||||
verboseprint("Track voiceover requested:", result.track_voiceover)
|
||||
if (result.track_voiceover or result.playlist_voiceover):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue