Skip to content

Conversation

tylerlv3
Copy link
Contributor

@tylerlv3 tylerlv3 commented Aug 7, 2025

Title

Fixes Invalid directory creation when downloading from YouTube Music.

Description

Resolves an issue where downloading songs from a YT music playlist would result in them being saved to a None/None directory. The root cause was that the directory was being generated before the songs' metadata was fully fetched from YT music. album_artist and album_name were None when the directory was created, leading to an invalid directory structure, and any M3U created after to not point to the correct directories. The fix was entirely in downloader.py.

Related Issue

Fixes #2286

Motivation and Context

This change is required to ensure that playlists downloaded from YouTube Music are saved in the correct directory structure, specified by the user's output format. It fixes a significant bug that affected the core use of the tool and prevented further problems, such as breaking M3U links.

How Has This Been Tested?

  1. Manual verification: used the same command from Download YTM Playlist yields to {album-artist} directory to None, even when the M3U pointing to correct {album-artist} #2286 that was failing (with a different playlist as the playlist in the issue doesn't exist anymore). The command succeeded after my changes and created the correct directory structure ({album-artist}/{album}).
  2. Automated testing: Ran the full Pytest suite on both my modified repository and a clean clone of the repository on the master branch. The test results were identical, with the same tests failing and passing between both repositories. So, my changes have not caused any new errors.

Screenshots (if appropriate)

N/A

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the CONTRIBUTING document
  • I have added tests to cover my changes
  • All new and existing tests passed

@Silverarmor Silverarmor requested a review from Copilot August 7, 2025 05:05
Copilot

This comment was marked as outdated.

@Silverarmor
Copy link
Member

Copilot's review matches what I saw. Some logic has been removed which will break some features.

@tylerlv3
Copy link
Contributor Author

tylerlv3 commented Aug 7, 2025

Ah yea I missed that, I will add the duplicate check back in 👍

…uld result in them being saved to a None/None directory. The root cause was that the directory was being generated before the songs metadata was fully fetched from YT music. album_artist and album_name were None when the directory was created, leading to an invlaid directory structure, and any M3U created after to not point to the correctt directories. The fix was entirely in downloader.py.
@tylerlv3
Copy link
Contributor Author

tylerlv3 commented Aug 8, 2025

Ok, I have amended the if statement, and slightly changed it to make it a little more readable, and added back the accidental deletion for the duplicate force logic.

@Silverarmor Silverarmor requested a review from Copilot August 8, 2025 03:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a critical bug where downloading from YouTube Music playlists created invalid directory structures due to premature directory creation before metadata was fully fetched.

  • Moved song reinitialization to occur before file path creation
  • Removed redundant code for metadata checking and reinitialization
  • Fixed duplicate variable assignment in file existence check

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tylerlv3
Copy link
Contributor Author

tylerlv3 commented Aug 8, 2025

Ha, one thing after another, keep working on this after long shifts at work lol. Anyway, I think it's good now, but let me know.

@Silverarmor Silverarmor changed the base branch from master to dev August 10, 2025 22:02
@Silverarmor Silverarmor merged commit 194b4e6 into spotDL:dev Aug 10, 2025
@Silverarmor Silverarmor mentioned this pull request Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Download YTM Playlist yields to {album-artist} directory to None, even when the M3U pointing to correct {album-artist}
2 participants