Comments (7)
My apologies, I should have closely examined the code of ytmdl
. Fortunately, there is a workaround for the above-mentioned issue: directly call the ytmdl.core.search
method.
import ytmdl
args = ytmdl.main.arguments()
args.SONG_NAME = ["SONG_NAME"]
args.choice = 1
args.quiet = True
url, title = ytmdl.core.search(args.SONG_NAME[0], args)
The URL can then be utilized directly with yt-dlp
. I will experiment with this and provide an update soon. Thank you.
Edit:
Code for the yt-dlp
part:
import yt_dlp
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
},
{'key': 'FFmpegMetadata'},],
'outtmpl': '%(title)s.%(ext)s',
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
error_code = ydl.download([url])
from ytmdl.
The above is correct. You can use the core functions directly and establish various functionalities. Moreover, I think the feature you requested is still a good one since the metadata that yt-dlp provides can be a fallback meta. It doesn't look good but it will be something.
The above yt-dlp
code looks good. You can refer to how ytmdl
is using yt-dlp
by checking the ytmdl/yt.py
file.
BTW, Phoenix10.1 looks like a good idea, will try it out!
from ytmdl.
@deepjyoti30 I just experimented with this code and it seems to work surprisingly well for our use cases, especially when compared to ytmdl
’s metadata search.
import ytmdl
import yt_dlp
import eyed3
import glob
import os
import nltk
args = ytmdl.main.arguments()
args.SONG_NAME = ["YOUR_SONG_NAME"]
args.choice = 1
args.quiet = True
url, title = ytmdl.core.search(args.SONG_NAME[0], args)
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
},
{'key': 'FFmpegMetadata'},],
'outtmpl': '%(title)s.%(ext)s',
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
error_code = ydl.download([url])
song_file = glob.glob("*.mp3")[0]
metadata = eyed3.load(song_file)
fetched_artist = metadata.tag.artist
os.remove(song_file)
infos = ytmdl.metadata.get_from_itunes(args.SONG_NAME[0])
most_accurate = sorted([info.json for info in infos[:10]], key=lambda x: nltk.edit_distance(x["artistName"], fetched_artist))[0]
print(most_accurate)
I will try to conduct more thorough testing on thousands of songs to verify this claim.
from ytmdl.
@deepjyoti30, we have successfully made the changes mentioned above to Phoenix 10.1.
If you plan on implementing these changes to ytmdl, check out pncnmnp/phoenix10.1#18 for inspiration.
Thank you for your help, and please feel free to ask any questions about our implementation.
from ytmdl.
@hariprasanths Support for youtube
as a fallback for metadata is added in the above commit. I will include it in the next release.
from ytmdl.
@deepjyoti30, I feel confident in providing my comment on the above-mentioned code now.
TLDR; The code mentioned above appears to fetch metadata with about 29% more accuracy than the default logic of ytmdl
.
I began by searching for datasets containing song titles and artist names. I found an excellent one on Kaggle: Top Spotify songs from 2010-2019 - BY YEAR.
Thus, I made minor enhancements to the aforementioned script and compared it to the metadata created by ytmdl.main.main
.
Using the suggested script resulted in 82.8% accuracy, whereas ytmdl
had about 54%. This finding aligns with our observations on Phoenix10.1, where 1/4 to 1/3 of all songs display incorrect metadata.
The dataset comprises roughly 600 songs, although I couldn't test the entire set as it was quite slow. Nonetheless, after analyzing 250 songs, I obtained the above results that should provide a suitable estimate.
Based on this experiment, I am confident that the best action for Phoenix10.1 is to utilize --add-metadata
with yt-dlp
to collect the song's actual metadata. Following this, we will extract further information from itunespy
using an edit_distance
based method.
We will continue to use ytmdl.core.search
as it has proven quite practical.
Here is the code and data for the entire experiment.
from ytmdl.
Failling back to yt-dlp's metadata when metadata fetch errors out would help a lot. I would prefer to have an option to not skip a track altogether when metadata fetch fails.
from ytmdl.
Related Issues (20)
- Filename control from CLI HOT 5
- Ytmdl skipping meta without flags and deleting the downloaded file. HOT 1
- Why does it output 320 kbps MP3? HOT 2
- Super annoying to tag playlist HOT 1
- Automatic skipping of songs already HOT 1
- Didn't work: complaining about iTunes... HOT 7
- ytmdl --list YOUTUBE_PLAYLIST_URL ====> YOUTUBE_PLAYLIST_URL is empty HOT 1
- Question
- Allow overriding ytmdl config file every run HOT 9
- Windows "|" in song name issue again HOT 1
- Zombie files buildup HOT 1
- Saavn songs doesn't have 100x100 album art HOT 1
- Add sponsorblock support HOT 1
- [Bug] Errors from missing videos in playlists don't seem to be handled gracefully.
- [Premium Youtube Music] can't download premium only songs! HOT 1
- Crash on ampersand in artist HOT 2
- "UnicodeEncodeError: 'charmap' codec can't encode character" when trying to download a song. HOT 3
- [FEATURE REQUEST] Consider dropping/replacing ffmpeg-python dependency because of future transitive dependency HOT 2
- Add support for showing `album name` in the metadata results
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ytmdl.