Skip to content

Commit 8f437a9

Browse files
authored
Fix m3u file creation, with correct metadata generation (#2258)
# 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
2 parents 46c26ba + 3df175a commit 8f437a9

File tree

12 files changed

+28
-24
lines changed

12 files changed

+28
-24
lines changed

.github/workflows/standard-checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
2727
- name: Run Pylint check
2828
run: |
29-
poetry run pylint --fail-under 10 --limit-inference-results 0 --disable=R0917,W0511 ./spotdl
29+
poetry run pylint --fail-under 10 --limit-inference-results 0 --disable=R0917 ./spotdl
3030
3131
- name: Run MyPy check
3232
run: |

docs/CONTRIBUTING.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ everyone involved. The community looks forward to your contributions. 🎉
2727
- [I Want To Contribute](#i-want-to-contribute)
2828
- [Reporting Bugs](#reporting-bugs)
2929
- [Suggesting Enhancements](#suggesting-enhancements)
30-
- [Linting, Formatting and Type-checking](#Linting,-Formatting-and-Type-checking)
31-
- [Python Documentation](#Python-Documentation)
32-
- [Overview of the Project Structure](#Overview-of-the-Project-Structure)
33-
- [Join The Project Team](#Join-The-Project-Team)
30+
- [Linting, Formatting and Type-checking](#linting-formatting-and-type-checking)
31+
- [Python Documentation](#python-documentation)
32+
- [Overview of the Project Structure](#overview-of-the-project-structure)
33+
- [Join The Project Team](#join-the-project-team)
3434

3535
## I Have a Question
3636

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

137137
<!-- 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. -->
138138

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

218218
```bash
219-
pylint --limit-inference-results 0 --fail-under 9 ./spotdl
219+
pylint --fail-under 10 --limit-inference-results 0 --disable=R0917 ./spotdl
220220
```
221221

222222
- We use [`black`](https://pypi.org/project/black/) for code formatting

docs/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ spotDL uses YouTube as a source for music downloads. This method is used to avoi
139139
140140
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.
141141
142-
Check the [Audio Formats](usage#audio-formats-and-quality) page for more info.
142+
Check the [Audio Formats](usage.md#audio-formats-and-quality) page for more info.
143143
144144
## Contributing
145145
146-
Interested in contributing? Check out our [CONTRIBUTING.md](CONTRIBUTING) to find
146+
Interested in contributing? Check out our [CONTRIBUTING.md](CONTRIBUTING.md) to find
147147
resources around contributing along with a guide on how to set up a development environment.
148148
149149
## Donate

docs/usage.md

-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ If you don't want config to load automatically change `load_config` option in co
281281
"scan_for_songs": false,
282282
"m3u": null,
283283
"output": "{artists} - {title}.{output-ext}",
284-
"m3u_output": "#EXTINF:{duration}, {artists} - {title}.{output-ext}",
285284
"overwrite": "skip",
286285
"search_query": null,
287286
"ffmpeg": "ffmpeg",

spotdl/console/save.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async def pool_worker(song: Song):
108108
gen_m3u_files(
109109
songs,
110110
m3u_file,
111-
downloader.settings["m3u_output"],
111+
downloader.settings["output"],
112112
downloader.settings["format"],
113113
downloader.settings["restrict"],
114114
False,

spotdl/console/sync.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def sync(
8282
gen_m3u_files(
8383
songs_list,
8484
m3u_file,
85-
downloader.settings["m3u_output"],
85+
downloader.settings["output"],
8686
downloader.settings["format"],
8787
downloader.settings["restrict"],
8888
False,
@@ -232,7 +232,7 @@ def sync(
232232
gen_m3u_files(
233233
songs_playlist,
234234
m3u_file,
235-
downloader.settings["m3u_output"],
235+
downloader.settings["output"],
236236
downloader.settings["format"],
237237
downloader.settings["restrict"],
238238
False,

spotdl/download/downloader.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def download_multiple_songs(
339339
gen_m3u_files(
340340
song_list,
341341
self.settings["m3u"],
342-
self.settings["m3u_output"],
342+
self.settings["output"],
343343
self.settings["format"],
344344
self.settings["restrict"],
345345
False,

spotdl/types/options.py

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class DownloaderOptions(TypedDict):
4949
scan_for_songs: bool
5050
m3u: Optional[str]
5151
output: str
52-
m3u_output: str
5352
overwrite: str
5453
search_query: Optional[str]
5554
ffmpeg: str

spotdl/utils/config.py

-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ def get_parameter(cls, key):
313313
"scan_for_songs": False,
314314
"m3u": None,
315315
"output": "{artists} - {title}.{output-ext}",
316-
"m3u_output": "#EXTINF:{duration}, {artists} - {title}.{output-ext}",
317316
"overwrite": "skip",
318317
"search_query": None,
319318
"ffmpeg": "ffmpeg",

spotdl/utils/m3u.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,20 @@ def create_m3u_content(
3232
- file_extension: the file extension to use
3333
- restrict: sanitization to apply to the filename
3434
- short: whether to use the short version of the template
35+
- detect_formats: the formats to detect for existing files
3536
3637
### Returns
3738
- the m3u content as a string
3839
"""
3940

40-
text = ""
41+
text = "#EXTM3U\n"
42+
4143
for song in song_list:
44+
metadata = create_file_name(
45+
song, "#EXTINF:{duration},{album-artist} - {title}", ""
46+
)
47+
text += str(metadata) + "\n"
48+
4249
if not detect_formats:
4350
file_name = create_file_name(
4451
song, template, file_extension, restrict, short
@@ -48,14 +55,14 @@ def create_m3u_content(
4855
else:
4956
for file_ext in detect_formats:
5057
file_name = create_file_name(song, template, file_ext, restrict, short)
58+
5159
if file_name.exists():
5260
text += str(file_name) + "\n"
5361
break
54-
else:
62+
5563
file_name = create_file_name(
5664
song, template, file_extension, restrict, short
5765
)
58-
5966
text += str(file_name) + "\n"
6067

6168
return text
@@ -74,9 +81,8 @@ def gen_m3u_files(
7481
Create an m3u8 filename from the query.
7582
7683
### Arguments
77-
- query: the query
84+
- songs: the list of songs
7885
- file_name: the file name to use
79-
- song_list: the list of songs
8086
- template: the output file template to use
8187
- file_extension: the file extension to use
8288
- restrict: sanitization to apply to the filename

tests/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ pytest --disable-vcr
4444
```
4545

4646
Whenever the server response will change and affect the tests behavior, the stored responses
47-
can be updated by wiping the [tests/*/cassetes](tests/*/cassetes) directory and running `pytest`
47+
can be updated by wiping the [tests/*/cassettes](tests/*/cassettes) directory and running `pytest`
4848
again (without `--disable-vcr`).

tests/utils/test_m3u.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ def test_create_m3u_content():
1414

1515
assert content != ""
1616
assert len(content.split("\n")) > 5
17-
assert content.split("\n")[0].endswith("mp3.mp3")
18-
17+
assert content.split("\n")[0] == "#EXTM3U"
18+
assert content.split("\n")[1].startswith("#EXTINF:")
19+
assert content.split("\n")[2].endswith(".mp3")
1920

2021
def test_create_m3u_file(tmpdir, monkeypatch):
2122
monkeypatch.chdir(tmpdir)

0 commit comments

Comments
 (0)