Skip to content

Commit

Permalink
Fix m3u file creation, with correct metadata generation (#2258)
Browse files Browse the repository at this point in the history
# Title
Fix m3u file creation, with correct metadata generation
## Description

## Related Issue
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->
#2251
#2246 

## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

Update m3u_test file.
Ran pylint, black and mypy and edited as required.

## Types of Changes
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)


## Checklist
Go over all the following points, and put an `x` in all the boxes that
apply.
- [xx] My code follows the code style of this project
- [x] My change requires a change to the documentation
- [ x] I have updated the documentation accordingly
- [ duhh] I have read the [CONTRIBUTING](/docs/CONTRIBUTING.md) document
- [ also duhh] I have read the [CORE VALUES](/docs/CORE_VALUES.md)
document
- [ yes] I have added tests to cover my changes
- [ n/a] All new and existing tests passed
  • Loading branch information
Silverarmor authored Jan 16, 2025
2 parents 46c26ba + 3df175a commit 8f437a9
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/standard-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Run Pylint check
run: |
poetry run pylint --fail-under 10 --limit-inference-results 0 --disable=R0917,W0511 ./spotdl
poetry run pylint --fail-under 10 --limit-inference-results 0 --disable=R0917 ./spotdl
- name: Run MyPy check
run: |
Expand Down
12 changes: 6 additions & 6 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ everyone involved. The community looks forward to your contributions. 🎉
- [I Want To Contribute](#i-want-to-contribute)
- [Reporting Bugs](#reporting-bugs)
- [Suggesting Enhancements](#suggesting-enhancements)
- [Linting, Formatting and Type-checking](#Linting,-Formatting-and-Type-checking)
- [Python Documentation](#Python-Documentation)
- [Overview of the Project Structure](#Overview-of-the-Project-Structure)
- [Join The Project Team](#Join-The-Project-Team)
- [Linting, Formatting and Type-checking](#linting-formatting-and-type-checking)
- [Python Documentation](#python-documentation)
- [Overview of the Project Structure](#overview-of-the-project-structure)
- [Join The Project Team](#join-the-project-team)

## I Have a Question

Expand Down Expand Up @@ -132,7 +132,7 @@ Once it's filed:
addressed until they are reproduced.
- If the team is able to reproduce the issue, it will be marked `needs-fix`, as well as
possibly other tags (such as `critical`), and the issue will be left to be
[implemented by someone](#your-first-code-contribution).
implemented by someone.

<!-- You might want to create an issue template for bugs and errors that can be used as a guide and that defines the structure of the information to be included. If you do so, reference it here in the description. -->

Expand Down Expand Up @@ -216,7 +216,7 @@ All changes will now affect the poetry installation of the spotDL cli.
- We use [`pylint`](https://pypi.org/project/pylint/) for linting and expect a score above `9`

```bash
pylint --limit-inference-results 0 --fail-under 9 ./spotdl
pylint --fail-under 10 --limit-inference-results 0 --disable=R0917 ./spotdl
```

- We use [`black`](https://pypi.org/project/black/) for code formatting
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ spotDL uses YouTube as a source for music downloads. This method is used to avoi
spotDL downloads music from YouTube and is designed to always download the highest possible bitrate; which is 128 kbps for regular users and 256 kbps for YouTube Music premium users.
Check the [Audio Formats](usage#audio-formats-and-quality) page for more info.
Check the [Audio Formats](usage.md#audio-formats-and-quality) page for more info.
## Contributing
Interested in contributing? Check out our [CONTRIBUTING.md](CONTRIBUTING) to find
Interested in contributing? Check out our [CONTRIBUTING.md](CONTRIBUTING.md) to find
resources around contributing along with a guide on how to set up a development environment.
## Donate
Expand Down
1 change: 0 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ If you don't want config to load automatically change `load_config` option in co
"scan_for_songs": false,
"m3u": null,
"output": "{artists} - {title}.{output-ext}",
"m3u_output": "#EXTINF:{duration}, {artists} - {title}.{output-ext}",
"overwrite": "skip",
"search_query": null,
"ffmpeg": "ffmpeg",
Expand Down
2 changes: 1 addition & 1 deletion spotdl/console/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def pool_worker(song: Song):
gen_m3u_files(
songs,
m3u_file,
downloader.settings["m3u_output"],
downloader.settings["output"],
downloader.settings["format"],
downloader.settings["restrict"],
False,
Expand Down
4 changes: 2 additions & 2 deletions spotdl/console/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def sync(
gen_m3u_files(
songs_list,
m3u_file,
downloader.settings["m3u_output"],
downloader.settings["output"],
downloader.settings["format"],
downloader.settings["restrict"],
False,
Expand Down Expand Up @@ -232,7 +232,7 @@ def sync(
gen_m3u_files(
songs_playlist,
m3u_file,
downloader.settings["m3u_output"],
downloader.settings["output"],
downloader.settings["format"],
downloader.settings["restrict"],
False,
Expand Down
2 changes: 1 addition & 1 deletion spotdl/download/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def download_multiple_songs(
gen_m3u_files(
song_list,
self.settings["m3u"],
self.settings["m3u_output"],
self.settings["output"],
self.settings["format"],
self.settings["restrict"],
False,
Expand Down
1 change: 0 additions & 1 deletion spotdl/types/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class DownloaderOptions(TypedDict):
scan_for_songs: bool
m3u: Optional[str]
output: str
m3u_output: str
overwrite: str
search_query: Optional[str]
ffmpeg: str
Expand Down
1 change: 0 additions & 1 deletion spotdl/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def get_parameter(cls, key):
"scan_for_songs": False,
"m3u": None,
"output": "{artists} - {title}.{output-ext}",
"m3u_output": "#EXTINF:{duration}, {artists} - {title}.{output-ext}",
"overwrite": "skip",
"search_query": None,
"ffmpeg": "ffmpeg",
Expand Down
16 changes: 11 additions & 5 deletions spotdl/utils/m3u.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,20 @@ def create_m3u_content(
- file_extension: the file extension to use
- restrict: sanitization to apply to the filename
- short: whether to use the short version of the template
- detect_formats: the formats to detect for existing files
### Returns
- the m3u content as a string
"""

text = ""
text = "#EXTM3U\n"

for song in song_list:
metadata = create_file_name(
song, "#EXTINF:{duration},{album-artist} - {title}", ""
)
text += str(metadata) + "\n"

if not detect_formats:
file_name = create_file_name(
song, template, file_extension, restrict, short
Expand All @@ -48,14 +55,14 @@ def create_m3u_content(
else:
for file_ext in detect_formats:
file_name = create_file_name(song, template, file_ext, restrict, short)

if file_name.exists():
text += str(file_name) + "\n"
break
else:

file_name = create_file_name(
song, template, file_extension, restrict, short
)

text += str(file_name) + "\n"

return text
Expand All @@ -74,9 +81,8 @@ def gen_m3u_files(
Create an m3u8 filename from the query.
### Arguments
- query: the query
- songs: the list of songs
- file_name: the file name to use
- song_list: the list of songs
- template: the output file template to use
- file_extension: the file extension to use
- restrict: sanitization to apply to the filename
Expand Down
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ pytest --disable-vcr
```

Whenever the server response will change and affect the tests behavior, the stored responses
can be updated by wiping the [tests/*/cassetes](tests/*/cassetes) directory and running `pytest`
can be updated by wiping the [tests/*/cassettes](tests/*/cassettes) directory and running `pytest`
again (without `--disable-vcr`).
5 changes: 3 additions & 2 deletions tests/utils/test_m3u.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def test_create_m3u_content():

assert content != ""
assert len(content.split("\n")) > 5
assert content.split("\n")[0].endswith("mp3.mp3")

assert content.split("\n")[0] == "#EXTM3U"
assert content.split("\n")[1].startswith("#EXTINF:")
assert content.split("\n")[2].endswith(".mp3")

def test_create_m3u_file(tmpdir, monkeypatch):
monkeypatch.chdir(tmpdir)
Expand Down

0 comments on commit 8f437a9

Please sign in to comment.