Skip to content

Commit a106bc0

Browse files
authored
Delete playlists (#7)
* delete_playlists function deletes all playlists * Updated README & docs for delete-playlists
1 parent 59672bc commit a106bc0

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Type `ytmusic-deleter` to see the usage information. There are currently four co
1919

2020
`unlike-all`:    Reset all Thumbs Up ratings back to neutral.
2121

22-
`delete-all`:    Combo command that will run `delete-uploads`, `remove-library`, and `unlike-all`.
22+
`delete-playlists`:    Delete all manually created YT Music playlists.
23+
24+
`delete-all`:    Combo command that will run `delete-uploads`, `remove-library`, `unlike-all`, and `delete-playlists`.
2325
## Examples
2426

2527
Getting help:
@@ -48,7 +50,11 @@ Reset all Thumbs Up ratings back to neutral:
4850
```
4951
ytmusic-deleter unlike-all
5052
```
51-
Remove everything (uploads, library tracks, and unlike all songs):
53+
Delete all your personally created playlists:
54+
```
55+
ytmusic-deleter delete-playlists
56+
```
57+
Remove everything (uploads, library tracks, playlists, and unlike all songs):
5258
```
5359
ytmusic-deleter delete-all
5460
```

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
install_reqs = [
1616
"click",
17-
"ytmusicapi",
17+
"ytmusicapi >= 0.11.0",
1818
"enlighten"
1919
]
2020

tests/test_cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ def test_unlike_all_songs(self):
1818
runner = CliRunner()
1919
result = runner.invoke(cli.unlike_all)
2020
assert result.exit_code == 0
21+
22+
def test_delete_playlists(self):
23+
runner = CliRunner()
24+
result = runner.invoke(cli.delete_playlists)
25+
assert result.exit_code == 0

ytmusic_deleter/cli.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,32 @@ def unlike_all():
245245
logging.info("Finished unliking all songs.")
246246

247247

248+
@cli.command()
249+
def delete_playlists():
250+
"""Delete all playlists
251+
"""
252+
logging.info("Retrieving all your playlists...")
253+
library_playlists = youtube_auth.get_library_playlists(sys.maxsize)
254+
# Can't delete "Your Likes" playlist
255+
library_playlists = list(filter(lambda playlist: playlist["playlistId"] != "LM", library_playlists))
256+
logging.info(f"\tRetrieved {len(library_playlists)} playlists.")
257+
logging.info(f"Begin deleting playlists...")
258+
progress_bar = manager.counter(total=len(library_playlists), desc="Playlists Deleted", unit="playlists")
259+
for playlist in library_playlists:
260+
logging.info(f"Processing playlist: {playlist['title']}")
261+
response = youtube_auth.delete_playlist(playlist["playlistId"])
262+
if response:
263+
logging.info(f"\tRemoved playlist \"{playlist['title']}\" from your library.")
264+
else:
265+
logging.error(f"\tFailed to remove playlist \"{playlist['title']}\" from your library.")
266+
progress_bar.update()
267+
logging.info("Finished deleting all playlists")
268+
248269
@cli.command()
249270
@click.pass_context
250271
def delete_all(ctx):
251-
"""Executes delete-uploads, remove-library, and unlike-all"""
272+
"""Executes delete-uploads, remove-library, unlike-all, and delete_playlists"""
252273
ctx.invoke(delete_uploads)
253274
ctx.invoke(remove_library)
254275
ctx.invoke(unlike_all)
276+
ctx.invoke(delete_playlists)

0 commit comments

Comments
 (0)