Last active
January 30, 2024 16:52
-
-
Save NataliaItani/4473ba7de4029c85af8973f15a1c37d8 to your computer and use it in GitHub Desktop.
Free Youtube Music downloader scripts for add to your websites by ymusicapk.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import necessary libraries | |
import ytmusicapi | |
import pytube | |
import re, os, sys | |
import requests | |
from urllib.parse import parse_qs, urljoin | |
import json | |
try: | |
import blessings | |
clear_eol = blessings.Terminal().clear_eol | |
except ImportError as err: | |
clear_eol = "\x1b[K" | |
class DownloaderMixin: | |
# ... (existing code remains unchanged) | |
def download_entire_playlist(self, playlist_id, dest_dir="~/Music", limit_duration=25*60, no_uploaded=True): | |
playlist = self.get_playlist(playlist_id) | |
self.download_playlist(playlist, dest_dir, limit_duration, no_uploaded) | |
def download_top_songs_by_artist(self, artist_name, dest_dir="~/Music", limit=10): | |
search_results = self.search(artist_name, filter="songs", limit=limit) | |
songs = search_results['tracks'] | |
self.download_playlist(songs, dest_dir) | |
def download_multiple_playlists(self, playlist_ids, dest_dir="~/Music", limit_duration=25*60, no_uploaded=True): | |
for playlist_id in playlist_ids: | |
self.download_entire_playlist(playlist_id, dest_dir, limit_duration, no_uploaded) | |
def download_popular_songs(self, dest_dir="~/Music", limit=10): | |
chart = self.get_top_charts(limit=limit) | |
songs = chart['tracks'] | |
self.download_playlist(songs, dest_dir) | |
def download_videos_from_urls(self, video_urls, dest_dir="~/Music"): | |
for video_url in video_urls: | |
video_id = self.extract_video_id(video_url) | |
self.download_song(video_id, dest_dir) | |
class YTMusic(ytmusicapi.YTMusic, DownloaderMixin): | |
pass | |
if __name__ == "__main__": | |
# Ensure headers_auth.json exists | |
if not os.path.exists("headers_auth.json"): | |
print("Missing file 'headers_auth.json'. See ytmusicapi.readthedocs.org for an explanation of how to use an authenticated watch page request in a signed-in browser and the browser devtools to set up headers_auth.json for ytmusicapi.") | |
sys.exit() | |
# Create an instance of YTMusic | |
ytm = YTMusic("headers_auth.json") | |
# EXAMPLE - download the last 10 songs in your playback history | |
history = ytm.download_playlist(ytm.get_history()) | |
# EXAMPLE - download the most recent 1000 songs you liked | |
ytm.download_playlist(ytm.get_liked_songs(limit=1000)) | |
# EXAMPLE - download an entire playlist by providing the playlist ID | |
ytm.download_entire_playlist("YOUR_PLAYLIST_ID") | |
# EXAMPLE - download the top songs by a specific artist | |
ytm.download_top_songs_by_artist("ARTIST_NAME") | |
# EXAMPLE - download multiple playlists by providing a list of playlist IDs | |
ytm.download_multiple_playlists(["PLAYLIST_ID_1", "PLAYLIST_ID_2"]) | |
# EXAMPLE - download popular songs from the top charts | |
ytm.download_popular_songs() | |
# EXAMPLE - download songs by providing a list of YouTube video URLs | |
ytm.download_videos_from_urls(["https://www.youtube.com/watch?v=VIDEO_ID_1", "https://www.youtube.com/watch?v=VIDEO_ID_2"]) | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>YouTube Music Downloader with ytmusicapi and pytube</title> | |
</head> | |
<body> | |
<h1>Description:</h1> | |
<p>The provided script is a Python program that leverages the <code>ytmusicapi</code> library and <code>pytube</code> to download high-quality audio from YouTube Music. The script is designed to facilitate the downloading of playlists, history, liked songs, and more from YouTube Music, overcoming the signatureCipher obfuscation used by YouTube for higher-quality adaptive format streams.</p> | |
<h1>Description of Classes and Functions:</h1> | |
<h2>YTMusic Class:</h2> | |
<p>The <code>YTMusic</code> class is a combination of the <code>ytmusicapi.YTMusic</code> class and the <code>DownloaderMixin</code> class, which provides additional downloading functionalities.</p> | |
<h2>DownloaderMixin Class:</h2> | |
<p>The <code>DownloaderMixin</code> class extends the <code>YTMusic</code> class with additional functions for downloading entire playlists, top songs by an artist, multiple playlists, popular songs, and videos from URLs.</p> | |
<h2>Functions:</h2> | |
<ul> | |
<li><code>download_entire_playlist(playlist_id, dest_dir="~/Music", limit_duration=25*60, no_uploaded=True)</code>: Downloads an entire playlist by providing the playlist ID.</li> | |
<li><code>download_top_songs_by_artist(artist_name, dest_dir="~/Music", limit=10)</code>: Searches for the top songs by a specific artist and downloads them.</li> | |
<li><code>download_multiple_playlists(playlist_ids, dest_dir="~/Music", limit_duration=25*60, no_uploaded=True)</code>: Downloads multiple playlists by providing a list of playlist IDs.</li> | |
<li><code>download_popular_songs(dest_dir="~/Music", limit=10)</code>: Downloads popular songs from the top charts.</li> | |
<li><code>download_videos_from_urls(video_urls, dest_dir="~/Music")</code>: Downloads songs by providing a list of YouTube video URLs.</li> | |
</ul> | |
<h1>How to Use:</h1> | |
<ol> | |
<li><strong>Install Required Libraries:</strong> Make sure to install the necessary libraries by running: <code>pip install ytmusicapi pytube</code></li> | |
<li><strong>Obtain headers_auth.json:</strong> Follow the instructions on <a href="https://ytmusicapi.readthedocs.io/en/latest/setup.html#authenticated-requests">ytmusicapi.readthedocs.org</a> to set up the <code>headers_auth.json</code> file for authenticated requests.</li> | |
<li><strong>Replace Placeholder Values:</strong> Replace placeholder values in the script, such as "YOUR_PLAYLIST_ID" and "ARTIST_NAME," with your actual playlist ID and artist name.</li> | |
<li><strong>Run the Script:</strong> Execute the script, and it will demonstrate various examples of how to use the provided functions to download playlists, liked songs, top songs by an artist, etc.</li> | |
</ol> | |
<p><strong>Note:</strong> Be aware of YouTube's terms of service and copyright laws when using such scripts. Always ensure that your usage complies with the platform's policies.</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just copy and paste it into your website to add the free youtube music mp3 downloader script and also download ymusic apk who is the developer of this script. Open the HTML section in your theme and post setting and copy and paste this code.