本文整理汇总了Python中gmusicapi.Musicmanager.get_all_songs方法的典型用法代码示例。如果您正苦于以下问题:Python Musicmanager.get_all_songs方法的具体用法?Python Musicmanager.get_all_songs怎么用?Python Musicmanager.get_all_songs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gmusicapi.Musicmanager
的用法示例。
在下文中一共展示了Musicmanager.get_all_songs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Musicmanager
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager import get_all_songs [as 别名]
from gmusicapi import Musicmanager
mm = Musicmanager()
mm.login()
songs = mm.get_all_songs()
print len(songs)
示例2: __init__
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager import get_all_songs [as 别名]
class User:
def __init__(self, email, app_data_dir):
self.email = email
self.app_data_dir = app_data_dir
self.db_lock = threading.Lock()
def init(self, oauth_credentials):
# Initialize the database
logger.info("%s: Initializing database" % self.email)
self._data_init()
# Create the Musicmanager
logger.info("%s: Logging in to Google music" % self.email)
self.mm = Musicmanager()
if not self.mm.login(oauth_credentials):
logger.info("%s: Error logging in to Google music" % self.email)
return False
# Check if we already have any watch paths configured
config = self._read_config()
watched_paths = config["watched_paths"] if "watched_paths" in config else []
logger.info("%s: Found previously watched paths %s" % (self.email, watched_paths))
# Create the FileWatcher
logger.info("%s: Creating the FileWatcher" % (self.email))
self.fw = FileWatcher(self.email, self._finished_writing_callback, watched_paths)
return True
def logout(self):
self.mm.logout()
self.fw.stop_watching()
def _read_config(self):
return util.read_config(os.path.join(self.app_data_dir, self.email, CFG_FILE_NAME))
def _write_config(self, config):
util.write_config(config, os.path.join(self.app_data_dir, self.email, CFG_FILE_NAME))
def get_watched_paths(self):
logger.debug("reading config from %s" % os.path.join(self.app_data_dir, self.email))
config = self._read_config()
logger.debug("read config: %s" % config)
return config["watched_paths"] if "watched_paths" in config else []
def add_watch_path(self, path):
# Add to file watcher
self.fw.watch(path)
# Add to the config
config = self._read_config()
if "watched_paths" not in config:
config["watched_paths"] = [path]
else:
if path not in config["watched_paths"]:
config["watched_paths"].append(path)
self._write_config(config)
def remove_watch_path(self, path):
# Remove from the file watcher
self.fw.remove_watch(path)
# Remove from the config
config = self._read_config()
if "watched_paths" in config:
if path in config["watched_paths"]:
config["watched_paths"].remove(path)
else:
logger.info("%s trying to remove watch path %s that we weren't watching" % (self.email, path))
self._write_config(config)
def set_default_action(self, default_action):
config = self._read_config()
config["default_action"] = default_action
self._write_config(config)
def get_default_action(self):
config = self._read_config()
return config.get("default_action", "scan_only")
def scan_existing_files(self):
watched_paths = self.get_watched_paths()
logger.debug("%s Scanning existing files in these directories: %s" % (self.email, watched_paths))
for watched_path in watched_paths:
logger.debug("Scanning existing files in %s" % watched_path)
for root, subFolders, files in os.walk(watched_path):
logger.debug("root: %s, subfolders: %s, files: %s" % (root, subFolders, files))
for file in files:
filename, fileExtension = os.path.splitext(file)
logger.debug("looking at file %s, filename = %s, file extension = %s" % (file, filename, fileExtension))
if fileExtension == ".mp3":
logger.debug("Found file %s" % file);
self._update_path(os.path.join(root, file), FileStatus.Scanned)
logger.debug("scanning finished");
def upload_scanned(self):
songs = self.get_all_songs()
for song_path in songs.keys():
if songs[song_path]["status"] == FileStatus.Scanned:
logger.debug("Uploading song %s" % song_path)
self.upload(song_path)
return
def _data_init(self):
with self.db_lock:
#.........这里部分代码省略.........