本文整理汇总了Python中gmusicapi.Webclient.delete_songs方法的典型用法代码示例。如果您正苦于以下问题:Python Webclient.delete_songs方法的具体用法?Python Webclient.delete_songs怎么用?Python Webclient.delete_songs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gmusicapi.Webclient
的用法示例。
在下文中一共展示了Webclient.delete_songs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MusicSync
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import delete_songs [as 别名]
#.........这里部分代码省略.........
def file_already_in_list(self, filename, goog_songs):
tag = self.get_id3_tag(filename)
i = 0
while i < len(goog_songs):
if self.tag_compare(goog_songs[i], tag):
goog_songs.pop(i)
return True
i += 1
return False
def get_id3_tag(self, filename):
data = mutagen.File(filename, easy=True)
r = {}
if "title" not in data:
title = os.path.splitext(os.path.basename(filename))[0]
print "Found song with no ID3 title, setting using filename:"
print " %s" % title
print " (please note - the id3 format used (v2.4) is invisible to windows)"
data["title"] = [title]
data.save()
r["title"] = data["title"][0]
r["track"] = int(data["tracknumber"][0].split("/")[0]) if "tracknumber" in data else 0
# If there is no track, try and get a track number off the front of the file... since thats
# what google seems to do...
# Not sure how google expects it to be formatted, for now this is a best guess
if r["track"] == 0:
m = re.match("(\d+) ", os.path.basename(filename))
if m:
r["track"] = int(m.group(0))
r["artist"] = data["artist"][0] if "artist" in data else ""
r["album"] = data["album"][0] if "album" in data else ""
return r
def find_song(self, filename, plid):
tag = self.get_id3_tag(filename)
print "Song Tag: %s " % tag
print "Filename: %s" % filename
ws_plids = []
ws_plids.append(plid)
print (ws_plids)
playlists = self.wc.get_all_playlist_ids()
print (playlists)
results = self.wc.get_playlist_songs(ws_plids)
# NOTE - dianostic print here to check results if you're creating duplicates
print results
print "%s ][ %s ][ %s ][ %s" % (tag["title"], tag["artist"], tag["album"], tag["track"])
for r in results:
if self.tag_compare(r, tag):
# TODO: add rough time check to make sure its "close"
return r
return None
def filter_search_results(self, results, song):
# Try Exact Matching
for g_song in results["song_hits"]:
if self.tag_compare(g_song["track"], song):
return g_song["track"]["nid"]
elif self.song_compare(g_song["track"], song, "artist"):
# try just the artist
return g_song["track"]["nid"]
elif self.song_compare(g_song["track"], song, "part-song"):
# try part of song and artist
return g_song["track"]["nid"]
return None
def song_compare(self, g_song, tag, type):
if "track" not in g_song:
g_song["track"] = 0
title_parts = tag["title"].split("(") # removing shit like (featuring wiz)
tp = title_parts[0].split(" ") # First word maybe
if "artist" in type:
return g_song["artist"].lower() == tag["artist"].lower()
if "part-song" in type:
return g_song["title"].find(tp[0]) and g_song["artist"].lower() == tag["artist"].lower()
return None
def tag_compare(self, g_song, tag):
if "track" not in g_song:
g_song["track"] = 0
return (
g_song["title"].split(" ")[0].lower() == tag["title"].split(" ")[0].lower()
and g_song["artist"].lower() == tag["artist"].lower()
)
def delete_song(self, sid):
self.wc.delete_songs(sid)
print "Deleted song by id [%s]" % sid
def get_platform_path(self, full_path):
# Try to avoid messing with the path if possible
if os.sep == "/" and "\\" not in full_path:
return full_path
if os.sep == "\\" and "\\" in full_path:
return full_path
if "\\" not in full_path:
return full_path
return os.path.normpath(full_path.replace("\\", "/"))
示例2: MusicSync
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import delete_songs [as 别名]
#.........这里部分代码省略.........
if remove_missing:
for s in goog_songs:
print " removing: %s" % s['title']
self.wc.remove_songs_from_playlist(plid, s.id)
time.sleep(.3) # Don't spam the server too fast...
removed_files += 1
print "%d songs unmodified" % existing_files
print "%d songs added" % added_files
print "%d songs failed" % failed_files
print "%d songs removed" % removed_files
print "Ended: %s" % filename
else:
print " playlist %s didn't exist - skipping" % filename
def get_files_from_playlist(self, filename):
files = []
f = codecs.open(filename, encoding='utf-8')
for line in f:
line = line.rstrip().replace(u'\ufeff',u'')
if line == "" or line[0] == "#":
continue
path = os.path.abspath(self.get_platform_path(line))
if not os.path.exists(path):
print " file not found: %s" % line
continue
files.append(path)
f.close()
return files
def file_already_in_list(self, filename, goog_songs):
tag = self.get_id3_tag(filename)
i = 0
while i < len(goog_songs):
# print "checking: %s" % tag
# print "against: %s" % goog_songs[i]
if self.tag_compare(goog_songs[i], tag):
goog_songs.pop(i)
return True
i += 1
return False
def get_id3_tag(self, filename):
data = mutagen.File(filename, easy=True)
r = {}
if 'title' not in data:
title = os.path.splitext(os.path.basename(filename))[0]
print ' found song with no ID3 title, setting using filename:'
print ' %s' % title
print ' (please note - the id3 format used (v2.4) is invisible to windows)'
data['title'] = [title]
data.save()
r['title'] = data['title'][0]
r['track'] = int(data['tracknumber'][0].split('/')[0]) if 'tracknumber' in data else 0
# If there is no track, try and get a track number off the front of the file... since thats
# what google seems to do...
# Not sure how google expects it to be formatted, for now this is a best guess
if r['track'] == 0:
m = re.match("(\d+) ", os.path.basename(filename))
if m:
r['track'] = int(m.group(0))
r['artist'] = data['artist'][0] if 'artist' in data else ''
r['album'] = data['album'][0] if 'album' in data else ''
return r
def find_song(self, filename):
tag = self.get_id3_tag(filename)
# NOTE - diagnostic print here to check results if you're creating duplicates
print " [%s][%s][%s][%s]" % (tag['title'], tag['artist'], tag['album'], tag['track'])
for s in self.songs:
if self.tag_compare(s, tag):
print " %s matches %s" % (s['title'], tag['title'])
return s
print " No matches for %s" % tag['title']
return None
def tag_compare(self, g_song, tag):
# If a google result has no track, google doesn't return a field for it
if 'track' not in g_song:
g_song['track'] = 0
return g_song['title'].lower() == tag['title'].lower() and\
g_song['artist'].lower() == tag['artist'].lower() and\
g_song['album'].lower() == tag['album'].lower() and\
g_song['track'] == tag['track']
def delete_song(self, sid):
self.wc.delete_songs(sid)
print " deleted song by id [%s]" % sid
def get_platform_path(self, full_path):
# Try to avoid messing with the path if possible
if os.sep == '/' and '\\' not in full_path:
return full_path
if os.sep == '\\' and '\\' in full_path:
return full_path
if '\\' not in full_path:
return full_path
return os.path.normpath(full_path.replace('\\', '/'))