Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

Commit

Permalink
Added the arg --nolibrary (don't scan the library of the user => quic…
Browse files Browse the repository at this point in the history
…k load)
  • Loading branch information
karlak committed Aug 11, 2013
1 parent 5c39758 commit 6deeac4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified gmusicfs/__init__.py
100644 → 100755
Empty file.
Empty file modified gmusicfs/fifo.py
100644 → 100755
Empty file.
39 changes: 22 additions & 17 deletions gmusicfs/gmusicfs.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_tracks(self, get_size=False):
return self.__tracks

def get_track(self, filename):
"""Get the track name corresponding to a filename
"""Get the track name corresponding to a filename
(eg. '001 - brilliant track name.mp3')"""
m = self.__filename_re.match(filename)
if m:
Expand All @@ -84,15 +84,15 @@ def get_cover_url(self):

def get_year(self):
"""Get the year of the album.
Aggregate all the track years and pick the most popular year
Aggregate all the track years and pick the most popular year
among them"""
years = {} # year -> count
for track in self.get_tracks():
y = track.get('year', None)
if y:
count = years.get(y, 0)
years[y] = count + 1
top_years = sorted(years.items(),
top_years = sorted(years.items(),
key=operator.itemgetter(1), reverse=True)
try:
top_year = top_years[0][0]
Expand All @@ -105,14 +105,17 @@ def __repr__(self):

class MusicLibrary(object):
'Read information about your Google Music library'

def __init__(self, username=None, password=None,
true_file_size=False, scan=True, verbose=0):
self.verbose = False
if verbose > 1:
self.verbose = True

self.__login_and_setup(username, password)

self.__artists = {} # 'artist name' -> {'album name' : Album(), ...}
self.__albums = [] # [Album(), ...]
if scan:
self.rescan()
self.true_file_size = true_file_size
Expand Down Expand Up @@ -144,12 +147,12 @@ def __login_and_setup(self, username=None, password=None):
raise NoCredentialException(
'No username/password could be read from config file'
': %s' % cred_path)

self.api = GoogleMusicAPI(debug_logging=self.verbose)
log.info('Logging in...')
self.api.login(username, password)
log.info('Login successful.')

def __aggregate_albums(self):
'Get all the tracks in the library, parse into artist and album dicts'
all_artist_albums = {} # 'Artist|||Album' -> Album()
Expand Down Expand Up @@ -196,8 +199,8 @@ def cleanup(self):

class GMusicFS(LoggingMixIn, Operations):
'Google Music Filesystem'
def __init__(self, path, username=None, password=None,
true_file_size=False, verbose=0):
def __init__(self, path, username=None, password=None,
true_file_size=False, verbose=0, scan_library=True):
Operations.__init__(self)
self.artist_dir = re.compile('^/artists/(?P<artist>[^/]+)$')
self.artist_album_dir = re.compile(
Expand All @@ -210,8 +213,8 @@ def __init__(self, path, username=None, password=None,
self.__open_files = {} # path -> urllib2_obj

# login to google music and parse the tracks:
self.library = MusicLibrary(username, password,
true_file_size=true_file_size, verbose=verbose)
self.library = MusicLibrary(username, password,
true_file_size=true_file_size, verbose=verbose, scan=scan_library)
log.info("Filesystem ready : %s" % path)

def cleanup(self):
Expand Down Expand Up @@ -277,7 +280,7 @@ def open(self, path, fh):
else:
RuntimeError('unexpected opening of path: %r' % path)

#Check for multi-part
#Check for multi-part
if len(urls) > 1:
self.__open_files[fh] = self.__open_multi_part(urls, path)
else:
Expand All @@ -302,7 +305,7 @@ def release(self, path, fh):
if u:
u.close()
del self.__open_files[fh]

def read(self, path, size, offset, fh):
u = self.__open_files.get(fh, None)
if u is None:
Expand Down Expand Up @@ -342,7 +345,7 @@ def readdir(self, path, fh):
parts['artist']][parts['album']]
files = ['.','..']
for track in album.get_tracks(get_size=True):
files.append('%03d - %s.mp3' % (track['track'],
files.append('%03d - %s.mp3' % (track['track'],
formatNames(track['titleNorm'])))
# Include cover image:
cover = album.get_cover_url()
Expand Down Expand Up @@ -381,7 +384,7 @@ def run(self):
def main():
parser = argparse.ArgumentParser(description='GMusicFS')
parser.add_argument('mountpoint', help='The location to mount to')
parser.add_argument('-f', '--foreground', dest='foreground',
parser.add_argument('-f', '--foreground', dest='foreground',
action="store_true",
help='Don\'t daemonize, run in the foreground.')
parser.add_argument('-v', '--verbose', help='Be a little verbose',
Expand All @@ -394,10 +397,12 @@ def main():
parser.add_argument('--allusers', help='Allow all system users access to files'
' (Requires user_allow_other set in /etc/fuse.conf)',
action='store_true', dest='allusers')
parser.add_argument('--nolibrary', help='Don\'t scan the library at launch',
action='store_true', dest='nolibrary')
args = parser.parse_args()

mountpoint = os.path.abspath(args.mountpoint)

# Set verbosity:
if args.veryverbose:
log.setLevel(logging.DEBUG)
Expand All @@ -417,9 +422,9 @@ def main():
logging.getLogger('fuse').setLevel(logging.WARNING)
logging.getLogger('requests.packages.urllib3').setLevel(logging.WARNING)
verbosity = 0
fs = GMusicFS(mountpoint, true_file_size=args.true_file_size, verbose=verbosity)
fs = GMusicFS(mountpoint, true_file_size=args.true_file_size, verbose=verbosity, scan_library= not args.nolibrary)
try:
fuse = FUSE(fs, mountpoint, foreground=args.foreground,
fuse = FUSE(fs, mountpoint, foreground=args.foreground,
ro=True, nothreads=True, allow_other=args.allusers)
finally:
fs.cleanup()
Expand Down
Empty file modified setup.py
100644 → 100755
Empty file.

0 comments on commit 6deeac4

Please sign in to comment.