本文整理汇总了Python中gmusicapi.Musicmanager.get_uploaded_songs方法的典型用法代码示例。如果您正苦于以下问题:Python Musicmanager.get_uploaded_songs方法的具体用法?Python Musicmanager.get_uploaded_songs怎么用?Python Musicmanager.get_uploaded_songs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gmusicapi.Musicmanager
的用法示例。
在下文中一共展示了Musicmanager.get_uploaded_songs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager import get_uploaded_songs [as 别名]
def main():
if len(sys.argv) != 2:
print_help()
sys.exit(1)
else:
username = sys.argv[1]
password = getpass.getpass()
mc = Mobileclient()
mc.login(username, password, Mobileclient.FROM_MAC_ADDRESS)
mm = Musicmanager()
mm.perform_oauth()
mm.login()
uploaded_songs = mm.get_uploaded_songs()
uploaded_ids = [track['id'] for track in uploaded_songs]
for part in chunks(uploaded_ids, 100):
complete = mc.delete_songs(part)
if len(complete) != len(part):
print("Something is wrong")
示例2: Musicmanager
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager import get_uploaded_songs [as 别名]
parser.add_argument('-r', '--refresh', required=False, help='Refresh Library.', action="store_true")
parser.add_argument('-d', '--display', required=False, help='Display playlist only.', action="store_true")
parser.add_argument('-t', '--artist', required=False, help='Artist Filter' )
args = parser.parse_args()
mm = Musicmanager()
if args.login:
mm.perform_oath()
sys.exit(0)
print "Logging In..."
mm.login()
if args.refresh:
print "Getting Songs"
library = mm.get_uploaded_songs()
with open('library.txt','w') as f:
pickle.dump( library, f)
print "Loading Library..."
with open('library.txt','r') as f:
library = pickle.load( f )
# Create playlist
playlist = []
for song in library:
if args.artist:
if args.artist.lower() not in song['artist'].lower():
continue
playlist.append( song )
示例3: Musicmanager
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager import get_uploaded_songs [as 别名]
from gmusicapi import Musicmanager
import os.path
storage_filepath = '/home/alex/.local/share/gmusicapi/oauth.cred'
mm = Musicmanager()
if os.path.isfile(storage_filepath):
mm.login()
else:
Musicmanager.perform_oauth(storage_filepath, open_browser=True)
songs = mm.get_uploaded_songs(incremental=False)
print(songs)
song_id = []
for x in songs:
song_id.append(x.get('id'))
print(song_id)
for an_id in song_id:
filename, audio = mm.download_song(an_id)
with open(filename, 'wb') as f:
f.write(audio)
input("Enter: ")
mm.logout(revoke_oauth=False)
示例4: FreeClient
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager import get_uploaded_songs [as 别名]
class FreeClient(Client):
"""
Client for free users with limited functionality.
Free users only have access to songs that they have either purchased
or uploaded, and they must be downloaded before they can be played.
Artists and albums cannot be generated, so the expand and radio methods
have no use.
"""
def __init__(self):
"""
Log into Musicmanager and get the library, either by loading an
existing library file, or by generating a new one.
"""
self.kind = 'free'
self.mm = Musicmanager()
self.mm.login()
self.songs = []
self.load_library()
if not self.songs:
self.gen_library()
def load_library(self):
path = join(common.DATA_DIR, 'library.zip')
common.w.outbar_msg('Loading library...')
if not isfile(path):
common.w.addstr(common.w.infobar, 'Could not find library file.')
return
try:
with zipfile.ZipFile(path) as z:
try:
lib = json.loads(z.read('library.json').decode('utf-8'))
except json.JSONDecodeError: # The .json file is invalid.
common.w.addstr(
common.w.infobar, 'Library file is corrupt.'
)
return
except zipfile.BadZipFile: # The .zip file is invalid.
common.w.addstr(common.w.infobar, 'Library file is corrupt.')
return
for item in lib['songs']:
try:
self.songs.append(
music_objects.LibrarySong(item, source='json'))
except KeyError: # The file has the wrong data.
common.w.addstr(common.w.infobar, 'Library file is corrupt.')
return
l = len(self.songs)
common.w.outbar_msg('Loaded %s song%s.' % (l, '' if l is 1 else 's'))
def gen_library(self):
ids = [] # Avoid duplicates between purchased and uploaded songs.
common.w.outbar_msg('Generating your library...')
for song in self.mm.get_uploaded_songs():
if song['id'] not in ids:
self.songs.append(music_objects.LibrarySong(song))
ids.append(song['id'])
for song in self.mm.get_purchased_songs():
if song['id'] not in ids:
self.songs.append(music_objects.LibrarySong(song))
ids.append(song['id'])
# Todo: Use something other than json for library storage since it
# doesn't really make logical sense (songs is a list, not a dict),
# but for now it's very easy to use.
with zipfile.ZipFile(join(common.DATA_DIR, 'library.zip'), 'w') as z:
z.writestr('library.json', json.dumps({'songs': self.songs}))
l = len(self.songs)
common.w.outbar_msg(
'Generated %d song%s.' % (l, '' if l is 1 else 's')
)
common.w.now_playing()
def expand(self, arg=None):
"""
Artists/albums cannot be generated. so free users cannot expand songs..
Keyword arguments:
arg=None: Irrelevant.
"""
common.q.error_msg('Free users cannot use expand')
def radio(self, arg=None):
"""
Artists/albums cannot be generated. so free users cannot create radio
stations.
Keyword arguments:
arg=None: Irrelevant.
"""
common.q.error_msg('Free users cannot use radio')
def search(self, query):
"""
Search the library for some query. and update the
view with the results.
Keyword arguments:
query=None: The search query.
#.........这里部分代码省略.........