Skip to content

Commit

Permalink
CHORE : add 3.10 python support and use yt_dlp instead of youtube-dl
Browse files Browse the repository at this point in the history
  • Loading branch information
thib1984 committed Oct 16, 2021
1 parent e95a62c commit b4fb7d3
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 116 deletions.
6 changes: 3 additions & 3 deletions .github/actions/full_test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ runs:
shell: bash
run: |
echo "---->remove dependency"
pip uninstall --yes youtube-dl
pip uninstall --yes yt-dlp
echo "---->verify is version not installed"
ytdlmusic --version | grep "youtube-dl version : NOT INSTALLED"
ytdlmusic --version | grep "yt-dlp version : NOT INSTALLED"
echo "---->verify the error"
(ytdlmusic --auto "Rexlambo Stay With Me" || echo "good exit code") | grep "good exit code"
echo "---->verify the error is corretly displayed"
(ytdlmusic --auto "Rexlambo Stay With Me" || echo "good exit code") | grep "Try to upgrade with 'ytdlmusic --update'"
echo "---->test upgrade contains waited text"
printf 'y\n' | ytdlmusic --fullupdate | grep "Successfully installed youtube-dl"
printf 'y\n' | ytdlmusic --fullupdate | grep "Successfully installed yt-dlp"
echo '---->ytdlmusic -dkQ --auto "Rexlambo Stay With Me"'
ytdlmusic -q --auto "Rexlambo Stay With Me"
echo "---->test if mp3 file exists"
Expand Down
6 changes: 3 additions & 3 deletions .github/actions/full_test_published/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ runs:
shell: bash
run: |
echo "---->remove dependency"
pip uninstall --yes youtube-dl
pip uninstall --yes yt-dlp
echo "---->verify is version not installed"
ytdlmusic --version | grep "youtube-dl version : NOT INSTALLED"
ytdlmusic --version | grep "yt-dlp version : NOT INSTALLED"
echo "---->verify the error"
(ytdlmusic --auto "Rexlambo Stay With Me" || echo "good exit code") | grep "good exit code"
echo "---->verify the error is corretly displayed"
(ytdlmusic --auto "Rexlambo Stay With Me" || echo "good exit code") | grep "Try to upgrade with 'ytdlmusic --update'"
echo "---->test upgrade contains waited text"
printf 'y\n' | ytdlmusic --fullupdate | grep "Successfully installed youtube-dl"
printf 'y\n' | ytdlmusic --fullupdate | grep "Successfully installed yt-dlp"
echo '---->ytdlmusic -dkQ --auto "Rexlambo Stay With Me"'
ytdlmusic -q --auto "Rexlambo Stay With Me"
echo "---->test if mp3 file exists"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
python-version: '3.7'
- os-version: 'ubuntu-20.04'
python-version: '3.8'
- os-version: 'ubuntu-20.04'
python-version: '3.10'
runs-on: ${{ matrix.os-version }}
name: test package on ${{ matrix.os-version }} with ${{ matrix.python-version }}
steps:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
python-version: '3.7'
- os-version: 'ubuntu-20.04'
python-version: '3.8'
- os-version: 'ubuntu-20.04'
python-version: '3.10'
runs-on: ${{ matrix.os-version }}
name: test package on ${{ matrix.os-version }} with ${{ matrix.python-version }}
steps:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test_published_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
python-version: '3.7'
- os-version: 'ubuntu-20.04'
python-version: '3.8'
- os-version: 'ubuntu-20.04'
python-version: '3.10'
runs-on: ${{ matrix.os-version }}
name: test package on ${{ matrix.os-version }} with ${{ matrix.python-version }}
steps:
Expand Down
110 changes: 15 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This package is directly available from [pypi](https://pypi.org/project/ytdlmusi
It may be illegal to download restricted content with this software, depending on the law in your country.

This package use two very important dependencies :
- [youtube_dl](https://pypi.org/project/youtube_dl/)
- [yt_dlp](https://pypi.org/project/yt_dlp/) a fork from [youtube-search-python](https://pypi.org/project/youtube-search-python/)
- [youtube-search-python](https://pypi.org/project/youtube-search-python/)

## Installation prerequisites
Expand All @@ -29,92 +29,15 @@ This package use two very important dependencies :

``ytdlmusic [KEY WORDS]``

ytdlmusic searches YouTube for "\[KEY WORDS\]" and displays the top five result and their description. The selected result is downloaded in your current directory. The default used format is MP3. The default filename is \[KEY WORDS\].mp3.
![demo_1](https://user-images.githubusercontent.com/45128847/137580908-ce3f1b17-a2b3-4530-bc90-df00fbaf1cfc.gif)

Example:
```
~$ ytdlmusic "Rexlambo Stay With Me"
search "Rexlambo Stay With Me" with youtube-search-python
1
Rexlambo - stay with me
https://www.youtube.com/watch?v=LrED6SSFf-I
3:52 - 9,636 views
2
stay with me – Rexlambo (No Copyright Music)
https://www.youtube.com/watch?v=a0hkrjqpIOo
3:52 - 166,640 views
3
Rexlambo - stay with me
https://www.youtube.com/watch?v=0vnOMFmBUGk
3:52 - 837 views
4
Rexlambo - stay with me
https://www.youtube.com/watch?v=TjATW8iAwa0
3:52 - 668 views
5
Rexlambo - Stay With Me
https://www.youtube.com/watch?v=jIc8c2hh4ew
3:53 - No views
Which (1-5, 0 to exit, 1 by default) ? 2
download https://www.youtube.com/watch?v=a0hkrjqpIOo with youtubedl
start youtube-dl operation
[youtube] a0hkrjqpIOo: Downloading webpage
[download] Destination: Rexlambo Stay With Me.webm
[download] 100% of 3.69MiB in 00:02
[ffmpeg] Destination: Rexlambo Stay With Me.mp3
Deleting original file Rexlambo Stay With Me.webm (pass -k to keep)
[ffmpeg] Adding metadata to 'Rexlambo Stay With Me.mp3'
end youtube-dl operation
Rexlambo Stay With Me.mp3 is ready
````
## Batch

You can use a command to loop in a csv file, and download all MP3 files from it.

`` ytdlmusic --batch path_file had_header sep columns_to_concatenate ``*

You can indicate one or more columns that you want to concatenate, separated by "+".

Example :

```
ytdlmusic -y --batch "./test.csv" True ";" 2+1
search "above limujii" with youtube-search-python
download https://www.youtube.com/watch?v=cUWU_T9KBk8 with youtubedl
start youtube-dl operation
[youtube] cUWU_T9KBk8: Downloading webpage
[download] Destination: above limujii.webm
[download] 100% of 2.58MiB in 00:01
[ffmpeg] Destination: above limujii.mp3
Deleting original file above limujii.webm (pass -k to keep)
[ffmpeg] Adding metadata to 'above limujii.mp3'
end youtube-dl operation
above limujii.mp3 is ready
search "awake nomyn" with youtube-search-python
download https://www.youtube.com/watch?v=hZQDfGX8Cu4 with youtubedl
start youtube-dl operation
[youtube] hZQDfGX8Cu4: Downloading webpage
[download] Destination: awake nomyn.webm
[download] 100% of 3.67MiB in 00:02
[ffmpeg] Destination: awake nomyn.mp3
Deleting original file awake nomyn.webm (pass -k to keep)
[ffmpeg] Adding metadata to 'awake nomyn.mp3'
end youtube-dl operation
awake nomyn.mp3 is ready
search "zhhezhahkzaj eyazttyzaeyz" with youtube-search-python
No result found, retry with other words.
search "avalon scandinavianz" with youtube-search-python
download https://www.youtube.com/watch?v=B5CYUMs6-eo with youtubedl
start youtube-dl operation
[youtube] B5CYUMs6-eo: Downloading webpage
[download] Destination: avalon scandinavianz.webm
[download] 100% of 2.79MiB in 00:01
[ffmpeg] Destination: avalon scandinavianz.mp3
Deleting original file avalon scandinavianz.webm (pass -k to keep)
[ffmpeg] Adding metadata to 'avalon scandinavianz.mp3'
end youtube-dl operation
avalon scandinavianz.mp3 is ready
```
![demo_2](https://user-images.githubusercontent.com/45128847/137581058-e0cca29b-9ad1-472e-bbb0-4fce94b984a0.gif)

with csv file
```
Expand All @@ -130,7 +53,7 @@ scandinavianz;avalon;information

`` ytdlmusic --update `` or `` ytdlmusic -u `` upgrade ytdlmusic.

`` ytdlmusic --fullupdate `` or `` ytdlmusic -U `` upgrade ytdlmusic and the dependencies youtube-dl and youtube-search-python.
`` ytdlmusic --fullupdate `` or `` ytdlmusic -U `` upgrade ytdlmusic and the dependencies yt-dlp and youtube-search-python.

`` ytdlmusic --version `` or `` ytdlmusic -v `` display version of ytdlmusic and the dependencies.

Expand Down Expand Up @@ -181,42 +104,39 @@ The ``ffmpeg`` package is required for the MP3 conversion. Install it and retry
### With the ``--tag`` option, my filenames keep the YouTube title format. Why?

The ``ffmpeg`` package is required for the tag conversion. Install it and retry to launch ytdlmusic.
### What are the compatibilities with Python, pip, youtube-dl and youtube-search-python?

When an new version is released, it is compatible with the last Python version in the branches 3.6 to 33.9, on the release date. It's also compatible with the last versions of dependencies, on the release date.
### What are the compatibilities with Python, pip, yt-dlp and youtube-search-python?

### What are the compatibilities with Python 3.10?
When an new version is released, it is compatible with the last Python version in the branches 3.6 to 3.10, on the release date. It's also compatible with the last versions of dependencies, on the release date.

When the 3.10 version will be released in final version, the package of ytdlmusic will be rework to be compatible with 3.10 version.


### When I try to update youtube-dl with ``youtube-dl -U``, I obtain an error message in my debian/ubuntu!
### When I try to update yt-dlp with ``yt-dlp -U``, I obtain an error message in my debian/ubuntu!

If you obtain the following message:

```
It looks like you installed youtube-dl with a package manager, pip, setup.py or a tarball. Please use that to update.
It looks like you installed yt-dlp with a package manager, pip, setup.py or a tarball. Please use that to update.
```

instead of

```
youtube-dl: error: youtube-dl's self-update mechanism is disabled on Debian.
Please update youtube-dl using apt(8).
See https://packages.debian.org/sid/youtube-dl for the latest packaged version.
yt-dlp: error: yt-dlp's self-update mechanism is disabled on Debian.
Please update yt-dlp using apt(8).
See https://packages.debian.org/sid/yt-dlp for the latest packaged version.
```

No panic! You have just downloaded a newer version of youtube-dl which is not in apt. When a new version of youtube-dl will be released in apt, you will download it automatically with ``sudo apt upgrade``. If you want to retrieve the previous version, ``sudo apt remove youtube-dl && sudo apt install youtube-dl``
No panic! You have just downloaded a newer version of yt-dlp which is not in apt. When a new version of yt-dlp will be released in apt, you will download it automatically with ``sudo apt upgrade``. If you want to retrieve the previous version, ``sudo apt remove yt-dlp && sudo apt install yt-dlp``

### I get an error about ``_requesthandler.py line 22`` when I try to use ytdlmusic

Sorry... You should update Python to 3.6 version or more. youtube-search-python doesn't seem to be compatible with Python 3.5 or less. Now, ytdlmusic package checks the Python version during the installation process.

### Have you tested your package?

Before a new version of ytdlmusic is published, it is checked in an [automatic job](https://github.com/thib1984/ytdlmusic/actions/workflows/publish.yml), with the last versions of pip, youtube-dl and youtube-search-python, and also in the last versions of Python in the three branches 3.6 to 3.9.*
Before a new version of ytdlmusic is published, it is checked in an [automatic job](https://github.com/thib1984/ytdlmusic/actions/workflows/publish.yml), with the last versions of pip, yt-dlp and youtube-search-python, and also in the last versions of Python in the four branches 3.6 to 3.10.

Each night, [another automatic job](https://github.com/thib1984/ytdlmusic/actions/workflows/test_published_release.yml) checks the actual package with last versions of dependencies and Pythons 3.6 to 3.9. So if a regression appears, the author of ytdlmusic received an automatic mail to warn it.*
Each night, [another automatic job](https://github.com/thib1984/ytdlmusic/actions/workflows/test_published_release.yml) checks the actual package with last versions of dependencies and Pythons 3.6 to 3.10. So if a regression appears, the author of ytdlmusic received an automatic mail to warn it.*

*_These tests are executed with GitHub Actions on an Ubuntu 20.04 image. Tests are also run on macOS and Windows images (only very last Python version)._
## Thanks
Expand All @@ -225,7 +145,7 @@ Thanks to contributors and dependencies authors :

- [albenquer](https://github.com/albenquer) and [dlicois](https://github.com/dlicois) for contributions!
- [Hitesh Kumar Saini](https://github.com/alexmercerind) for [youtube-search-python](https://github.com/alexmercerind/youtube-search-python)
- [ytdl-org](https://github.com/ytdl-org) for [youtube-dl](https://github.com/ytdl-org/youtube-dl)
- [yt-dlp](https://github.com/yt-dlp) for [yt-dlp](https://github.com/yt-dlp/yt-dlp)
- [devsnd](https://github.com/devsnd) for [tinytag](https://github.com/devsnd/tinytag)
- [avian2](https://github.com/avian2) for [unidecode](https://github.com/avian2/unidecode)
- [tartley](https://github.com/tartley) for [colorama](https://github.com/tartley/colorama)
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="ytdlmusic",
version="1.10.3",
version="2.0.0",
description="ytdlmusic is a command-line program to search and download music files from YouTube without use browser.",
long_description="The complete description/installation/use/FAQ is available at : https://github.com/thib1984/ytdlmusic#readme",
long_description_content_type="text/markdown",
Expand All @@ -14,7 +14,7 @@
packages=["ytdlmusic"],
install_requires=[
"youtube-search-python",
"youtube_dl",
"yt_dlp",
"tinytag",
"unidecode",
"termcolor",
Expand All @@ -29,6 +29,7 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
Expand Down
2 changes: 1 addition & 1 deletion ytdlmusic/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

VERSION_DEPENDENCIES = """\
youtube-search-python version : $1
youtube-dl version : $2
yt-dlp version : $2
pip(3) version : $3
Python version : $4
ffmpeg : $5"""
Expand Down
16 changes: 8 additions & 8 deletions ytdlmusic/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
from ytdlmusic.log import print_debug

try:
import youtube_dl
import yt_dlp
except ImportError:
print_debug("youtubde_dl import problem")
print_debug("yt_dlp import problem")


def download_song(song_url, filename):
"""
download song with youtube-dl
download song with yt-dlp
in filename
from url song_url
"""

print(
colored("download " + song_url + " with youtubedl", "green")
colored("download " + song_url + " with yt_dlp", "green")
)

# m4a
Expand Down Expand Up @@ -61,16 +61,16 @@ def download_song(song_url, filename):

if is_verbose():
opts["verbose"] = "True"
print_debug("debug youtube-dl is activated")
print_debug("debug yt-dlp is activated")
if not is_quiet():
print("start youtube-dl operation")
print("start yt-dlp operation")
elif is_quiet():
opts["quiet"] = True
opts["no_warnings"] = True
with youtube_dl.YoutubeDL(opts) as ydl:
with yt_dlp.YoutubeDL(opts) as ydl:
ydl.extract_info(song_url, download=True)
if not is_quiet():
print("end youtube-dl operation")
print("end yt-dlp operation")
if not is_ffmpeg_installed() and not is_m4a() and not is_ogg():
print(
colored(
Expand Down
2 changes: 1 addition & 1 deletion ytdlmusic/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def compute_args():
"-U",
"--fullupdate",
action="store_true",
help="upgrade ytdlmusic, and the dependencies youtube-dl and youtube-search-python",
help="upgrade ytdlmusic, and the dependencies yt-dlp and youtube-search-python",
)
my_group.add_argument(
"-b",
Expand Down
2 changes: 1 addition & 1 deletion ytdlmusic/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def print_version_dependencies():
VERSION_DEPENDENCIES,
{
"$1": pip_package_version("youtube-search-python"),
"$2": pip_package_version("youtube-dl"),
"$2": pip_package_version("yt-dlp"),
"$3": pip_package_version_of_double("pip3", "pip"),
"$4": python_version(),
"$5": binary_path("ffmpeg"),
Expand Down
4 changes: 2 additions & 2 deletions ytdlmusic/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def update():

def fullupdate():
"""
update ytdlmusic, youtube-search-python, youtube-dl
update ytdlmusic, youtube-search-python, yt-dlp
"""

if not is_auto():
Expand All @@ -49,7 +49,7 @@ def fullupdate():
boolean_ysp = update_pip_package(
pip3_or_pip(), "youtube-search-python"
)
boolean_ytdl = update_pip_package(pip3_or_pip(), "youtube-dl")
boolean_ytdl = update_pip_package(pip3_or_pip(), "yt-dlp")
boolean_ytdlm = update_pip_package(pip3_or_pip(), "ytdlmusic")

if not (boolean_ysp and boolean_ytdl and boolean_ytdlm):
Expand Down

0 comments on commit b4fb7d3

Please sign in to comment.