# Path: playa/common/storage.py
# def load(path):
#     start = time.time()
# 
#     print "Loading %s" % path
# 
#     with open(path, 'rb') as fp:
#         try:
#             result = pickle.load(fp)
#         except EOFError:
#             return
# 
#     print "Done! (took %.2fs)" % (time.time() - start)
# 
#     return result
# 
# def save(path, data):
#     start = time.time()
# 
#     print "Saving %s" % path
# 
#     with open(path, 'wb') as fp:
#         pickle.dump(data, fp)
#     
#     print "Done! (took %.2fs)" % (time.time() - start)


import os.path
from playa.common.storage import load, save
"""
playa.ext.audio.playlists
~~~~~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2011 DISQUS.
:license: Apache License 2.0, see LICENSE for more details.
"""

from __future__ import absolute_import



class Playlists(object):
    def __init__(self, app):
        self.app = app
        self.playlists = {}
        self.add_path(os.path.join(self.app.config['DATA_PATH'], 'playlists'))

    def add_path(self, path, base=None):
        if not base:
            base = path
        for fn in os.listdir(path): 
            if fn.startswith('.'):
                continue

            full_path = os.path.join(path, fn)
            if os.path.isdir(full_path):
                self.add_path(path, base)
                continue
            

# Path: playa/common/storage.py
# def load(path):
#     start = time.time()
# 
#     print "Loading %s" % path
# 
#     with open(path, 'rb') as fp:
#         try:
#             result = pickle.load(fp)
#         except EOFError:
#             return
# 
#     print "Done! (took %.2fs)" % (time.time() - start)
# 
#     return result
# 
# def save(path, data):
#     start = time.time()
# 
#     print "Saving %s" % path
# 
#     with open(path, 'wb') as fp:
#         pickle.dump(data, fp)
#     
#     print "Done! (took %.2fs)" % (time.time() - start)


# Path: playa/ext/audio/playlists.py
import os.path
from playa.common.storage import load, save

"""
playa.ext.audio.playlists
~~~~~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2011 DISQUS.
:license: Apache License 2.0, see LICENSE for more details.
"""

from __future__ import absolute_import



class Playlists(object):
    def __init__(self, app):
        self.app = app
        self.playlists = {}
        self.add_path(os.path.join(self.app.config['DATA_PATH'], 'playlists'))

    def add_path(self, path, base=None):
        if not base:
            base = path
        for fn in os.listdir(path): 
            if fn.startswith('.'):
                continue

            full_path = os.path.join(path, fn)
            if os.path.isdir(full_path):
                self.add_path(path, base)
                continue
            

            self.playlists[full_path] = load(full_path)