Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download music with length closest to one on Spotify #111

Merged
merged 6 commits into from Jul 17, 2017

Conversation

WMP
Copy link
Contributor

@WMP WMP commented Jul 12, 2017

First, sorry for using old version :(

  • added .python-version
    This file is used in pyenv to select good python version.

Changes in core/misc.py:

  • added function get_sec to convert HH:mm:ss to seconds

Changes in spotdl.py:

  • in function generate_songname
    change function to receive generate_metadata, this is optymalization, becouse in oldest version metadata from spotify api is downlaoded 2 times
  • in function generate_youtube_url
    song variable use changed function generate_songname
    function now looking for songs in while, and save data to dict. Dictionary is used in manual and auto mode. In dictionary keep is youtube link, title, videotime (in format HH:mm:ss) and videotime converted to seconds.
    For now in automatic downloading is selected video with least difference betwen youtube video time and time from spotify. This is important, becouse in youtube a lot of movies has scenes before/after without musics.

WMP added 2 commits July 12, 2017 14:46
 - added .python-version
This file is used in pyenv to select good python version.

Changes in core/misc.py:
 - added function get_sec to convert HH:mm:ss to seconds

Changes in spotdl.py:
 - in function generate_songname
     change function to receive generate_metadata, this is optymalization, becouse in oldest version metadata from spotify api is downlaoded 2 times
 - in function generate_youtube_url
     song variable use changed function generate_songname
     function now looking for songs in while, and save data to dict. Dictionary is used in manual and auto mode. In dictionary keep is youtube link, title, videotime (in format HH:mm:ss) and videotime converted to seconds.
     For now in automatic downloading is selected video with least difference betwen youtube video time and time from spotify. This is important, becouse in youtube a lot of movies has scenes before/after without musics.
@ritiek
Copy link
Member

ritiek commented Jul 12, 2017

This sounds good in theory but I'll do some everyday testing with your changes to see how it performs before we finally decide whether to merge this or not. It might take some though. Thank you the PR!

@WMP
Copy link
Contributor Author

WMP commented Jul 12, 2017

@ritiek yes, i think you should testing this PR.
@linusg Could you describe why you think that old version is better? I have this idea after download song which have 20 seconds talk before music.

@linusg
Copy link
Contributor

linusg commented Jul 12, 2017

@WMP No offense, the overall idea is great. I'm just complaining about the comment you've changed, click on the commit > changed files and scroll down to see the specific lines I mean 😉

@WMP
Copy link
Contributor Author

WMP commented Jul 12, 2017

@linusg Ahhh, ok, now i understand ;) Thanks

@lkgarrison
Copy link
Contributor

I agree, I think this would be a great additional feature! If it works pretty well perhaps it could be added as an option. It isn't fun realizing later that the song is over a minute longer than it should have been!

@linusg
Copy link
Contributor

linusg commented Jul 13, 2017

@lkgarrison Agreed, as an optional feature, this would be great! We could like have an command line option for that... --best for selecting the "best" song automatically probably? (Could also integrate if the channel name contains VEVO etc.)

@WMP
Copy link
Contributor Author

WMP commented Jul 14, 2017

@lkgarrison @linusg : Why we want to add this alghorytm as option? What arguments we have for old solution?
My second argument: on old alghorytm i have downloaded files with difference volume level, on this all files have good volume level.

@linusg
Copy link
Contributor

linusg commented Jul 14, 2017

My second argument: on old alghorytm i have downloaded files with difference volume level, on this all files have good volume level.

and

I have this idea after download song which have 20 seconds talk before music.

Instead of just promoting your new version, could you please give one or two examples where this is indeed the case? So the song names or Spotify links where the cases you've described apply.

@WMP
Copy link
Contributor Author

WMP commented Jul 14, 2017

Yes, of course:

Official version:
`
wmp@LUBN366:/skrypty/pobrane/spotify-downloader$ git pull
Already up-to-date.
wmp@LUBN366:/skrypty/pobrane/spotify-downloader$ git remote -v
origin https://github.com/ritiek/spotify-downloader (fetch)
origin https://github.com/ritiek/spotify-downloader (push)
wmp@LUBN366:/skrypty/pobrane/spotify-downloader$ git branch

  1. Jan Hammer Project feat. TQ - Crockett's Theme (Radio Version)
    3,915,256 Bytes [100.00%] received. Rate: [7887 KB/s]. ETA: [0 secs]
    Converting Jan_Hammer_Project_-Crocketts_Theme(Radio_Version).m4a to mp3
    Fixing meta-tags

  2. 30 minutes - Tatu
    2,648,236 Bytes [100.00%] received. Rate: [10205 KB/s]. ETA: [0 secs]
    Converting tATu_-_30_Minutes.m4a to mp3
    Fixing meta-tags

  3. Darren Hayes - Insatiable
    4,159,892 Bytes [100.00%] received. Rate: [10373 KB/s]. ETA: [0 secs]
    Converting Darren_Hayes_-_Insatiable.m4a to mp3
    Fixing meta-tags

  4. Creed - With Arms Wide Open (Strings Version)
    3,739,360 Bytes [100.00%] received. Rate: [10956 KB/s]. ETA: [0 secs]
    Converting Creed_-With_Arms_Wide_Open-_New_Version_With_Strings.m4a to mp3
    Fixing meta-tags

  5. Alcazar - Sexual Guarantee
    3,527,777 Bytes [100.00%] received. Rate: [10364 KB/s]. ETA: [0 secs]
    Converting Alcazar_-_Sexual_Guarantee.m4a to mp3
    Fixing meta-tags

  6. Sugababes - Shape
    3,442,097 Bytes [100.00%] received. Rate: [6815 KB/s]. ETA: [0 secs]
    Converting Sugababes_-_Shape.m4a to mp3
    Fixing meta-tags

  7. Crazy Town - Butterfly (Official Video)
    3,389,868 Bytes [100.00%] received. Rate: [10799 KB/s]. ETA: [0 secs]
    Converting Crazy_Town_-_Butterfly.m4a to mp3
    Fixing meta-tags

  8. Nelly - Dilemma ft. Kelly Rowland
    4,493,658 Bytes [100.00%] received. Rate: [10590 KB/s]. ETA: [0 secs]
    Converting Nelly_-_Dilemma.m4a to mp3
    Fixing meta-tags

  9. Sandra - In The Heat Of The Night • TopPop
    3,000,003 Bytes [100.00%] received. Rate: [10135 KB/s]. ETA: [0 secs]
    Converting Sandra_-_In_The_Heat_Of_The_Night.m4a to mp3
    Fixing meta-tags

wmp@LUBN366:/skrypty/pobrane/spotify-downloader$ for i in *.mp3; do echo $"$i"; ffmpeg -af "volumedetect" -f null /dev/null -i $i 2>&1 | grep Parsed_volumedetect; done
*.mp3
wmp@LUBN366:/skrypty/pobrane/spotify-downloader$ cd Music/
wmp@LUBN366:/skrypty/pobrane/spotify-downloader/Music$ for i in *.mp3; do echo $"$i"; ffmpeg -af "volumedetect" -f null /dev/null -i $i 2>&1 | grep Parsed_volumedetect; done
Alcazar_-Sexual_Guarantee.mp3
[Parsed_volumedetect_0 @ 0x3d27260] n_samples: 19381248
[Parsed_volumedetect_0 @ 0x3d27260] mean_volume: -18.4 dB
[Parsed_volumedetect_0 @ 0x3d27260] max_volume: -1.3 dB
[Parsed_volumedetect_0 @ 0x3d27260] histogram_1db: 2
[Parsed_volumedetect_0 @ 0x3d27260] histogram_2db: 43
[Parsed_volumedetect_0 @ 0x3d27260] histogram_3db: 247
[Parsed_volumedetect_0 @ 0x3d27260] histogram_4db: 654
[Parsed_volumedetect_0 @ 0x3d27260] histogram_5db: 1805
[Parsed_volumedetect_0 @ 0x3d27260] histogram_6db: 4634
[Parsed_volumedetect_0 @ 0x3d27260] histogram_7db: 14148
Crazy_Town
-Butterfly.mp3
[Parsed_volumedetect_0 @ 0x24de7a0] n_samples: 18823680
[Parsed_volumedetect_0 @ 0x24de7a0] mean_volume: -18.1 dB
[Parsed_volumedetect_0 @ 0x24de7a0] max_volume: -1.2 dB
[Parsed_volumedetect_0 @ 0x24de7a0] histogram_1db: 3
[Parsed_volumedetect_0 @ 0x24de7a0] histogram_2db: 118
[Parsed_volumedetect_0 @ 0x24de7a0] histogram_3db: 977
[Parsed_volumedetect_0 @ 0x24de7a0] histogram_4db: 5111
[Parsed_volumedetect_0 @ 0x24de7a0] histogram_5db: 16572
Creed
-With_Arms_Wide_Open-New_Version_With_Strings.mp3
[Parsed_volumedetect_0 @ 0x3e7aca0] n_samples: 20765952
[Parsed_volumedetect_0 @ 0x3e7aca0] mean_volume: -13.2 dB
[Parsed_volumedetect_0 @ 0x3e7aca0] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0x3e7aca0] histogram_0db: 16132
[Parsed_volumedetect_0 @ 0x3e7aca0] histogram_1db: 45792
Darren_Hayes
-Insatiable.mp3
[Parsed_volumedetect_0 @ 0x370bc40] n_samples: 23097600
[Parsed_volumedetect_0 @ 0x370bc40] mean_volume: -15.8 dB
[Parsed_volumedetect_0 @ 0x370bc40] max_volume: -1.0 dB
[Parsed_volumedetect_0 @ 0x370bc40] histogram_1db: 137
[Parsed_volumedetect_0 @ 0x370bc40] histogram_2db: 2221
[Parsed_volumedetect_0 @ 0x370bc40] histogram_3db: 14111
[Parsed_volumedetect_0 @ 0x370bc40] histogram_4db: 44120
Jan_Hammer_Project
-Crocketts_Theme(Radio_Version).mp3
[Parsed_volumedetect_0 @ 0x3038be0] n_samples: 21742848
[Parsed_volumedetect_0 @ 0x3038be0] mean_volume: -10.7 dB
[Parsed_volumedetect_0 @ 0x3038be0] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0x3038be0] histogram_0db: 80489
Nelly_-Dilemma.mp3
[Parsed_volumedetect_0 @ 0x3d22a00] n_samples: 24954624
[Parsed_volumedetect_0 @ 0x3d22a00] mean_volume: -20.1 dB #### Loud
[Parsed_volumedetect_0 @ 0x3d22a00] max_volume: -4.1 dB
[Parsed_volumedetect_0 @ 0x3d22a00] histogram_4db: 4
[Parsed_volumedetect_0 @ 0x3d22a00] histogram_5db: 299
[Parsed_volumedetect_0 @ 0x3d22a00] histogram_6db: 11508
[Parsed_volumedetect_0 @ 0x3d22a00] histogram_7db: 50582
Sandra
-In_The_Heat_Of_The_Night.mp3
[Parsed_volumedetect_0 @ 0x40d2460] n_samples: 16660224
[Parsed_volumedetect_0 @ 0x40d2460] mean_volume: -23.1 dB #### Very, very loud
[Parsed_volumedetect_0 @ 0x40d2460] max_volume: -6.0 dB
[Parsed_volumedetect_0 @ 0x40d2460] histogram_5db: 1
[Parsed_volumedetect_0 @ 0x40d2460] histogram_6db: 42
[Parsed_volumedetect_0 @ 0x40d2460] histogram_7db: 731
[Parsed_volumedetect_0 @ 0x40d2460] histogram_8db: 4012
[Parsed_volumedetect_0 @ 0x40d2460] histogram_9db: 11638
[Parsed_volumedetect_0 @ 0x40d2460] histogram_10db: 24482
Sugababes
-Shape.mp3
[Parsed_volumedetect_0 @ 0x354b3e0] n_samples: 18911232
[Parsed_volumedetect_0 @ 0x354b3e0] mean_volume: -23.6 dB #### Very loud
[Parsed_volumedetect_0 @ 0x354b3e0] max_volume: -4.8 dB
[Parsed_volumedetect_0 @ 0x354b3e0] histogram_4db: 2
[Parsed_volumedetect_0 @ 0x354b3e0] histogram_5db: 33
[Parsed_volumedetect_0 @ 0x354b3e0] histogram_6db: 345
[Parsed_volumedetect_0 @ 0x354b3e0] histogram_7db: 1708
[Parsed_volumedetect_0 @ 0x354b3e0] histogram_8db: 5385
[Parsed_volumedetect_0 @ 0x354b3e0] histogram_9db: 11513
tATu
-30_Minutes.mp3
[Parsed_volumedetect_0 @ 0x24ddd40] n_samples: 9828864
[Parsed_volumedetect_0 @ 0x24ddd40] mean_volume: -15.4 dB
[Parsed_volumedetect_0 @ 0x24ddd40] max_volume: -0.2 dB
[Parsed_volumedetect_0 @ 0x24ddd40] histogram_0db: 5
[Parsed_volumedetect_0 @ 0x24ddd40] histogram_1db: 52
[Parsed_volumedetect_0 @ 0x24ddd40] histogram_2db: 289
[Parsed_volumedetect_0 @ 0x24ddd40] histogram_3db: 1519
[Parsed_volumedetect_0 @ 0x24ddd40] histogram_4db: 8179
wmp@LUBN366:/skrypty/pobrane/spotify-downloader/Music$ for i in *.mp3; do echo "$i"; ffmpeg -i $i 2>&1 | grep Duration | awk '{print $2}' | tr -d ,; done
Alcazar
-Sexual_Guarantee.mp3
00:03:39.74
Crazy_Town
-Butterfly.mp3
00:03:33.42
Creed
-With_Arms_Wide_Open-New_Version_With_Strings.mp3
00:03:55.44
Darren_Hayes
-Insatiable.mp3 ## Better version that downlaoded by my fork
00:04:21.88
Jan_Hammer_Project
-Crocketts_Theme(Radio_Version).mp3
00:04:06.52
Nelly_-Dilemma.mp3
00:04:42.93
Sandra
-In_The_Heat_Of_The_Night.mp3
00:03:08.89
Sugababes
-Shape.mp3
00:03:34.41
tATu
-_30_Minutes.mp3 ## Russian version with 30s scene before music
00:03:42.88
wmp@LUBN366:/skrypty/pobrane/spotify-downloader/Music$
`

And my version:
`
wmp@LUBN366:/skrypty/pobrane/spotify-downloader/Music$ cd /mnt/d/Users/wmp/Praca/skrypty/spotify-downloader/
wmp@LUBN366:/mnt/d/Users/wmp/Praca/skrypty/spotify-downloader$ git remote -v
origin git@github.com:WMP/spotify-downloader.git (fetch)
origin git@github.com:WMP/spotify-downloader.git (push)
wmp@LUBN366:/mnt/d/Users/wmp/Praca/skrypty/spotify-downloader$ python spotdl.py -u wmp

  1. Samochod (9 tracks)
  2. Na wynos 1 (1021 tracks)
  3. do pobrania (11 tracks)

Choose your number: 1

Feeding 9 tracks to samochod.txt
wmp@LUBN366:/mnt/d/Users/wmp/Praca/skrypty/spotify-downloader$ cat samochod.txt
https://open.spotify.com/track/6o0Fb3BhfDBmup77cngHFy
https://open.spotify.com/track/4mu0mOYq5j3fjypWAJ6PpG
https://open.spotify.com/track/4Q8yCpsxxJF0tRsjzu6Ytw
https://open.spotify.com/track/4pldO6ZS749Piqi4GISql8
https://open.spotify.com/track/1Be6Taglj9Tx7iopLqaoel
https://open.spotify.com/track/1Dkb1sZ5m7cljXERBqyGV1
https://open.spotify.com/track/4BggEwLhGfrbrl7JBhC8EC
https://open.spotify.com/track/18vdhCWxqPohnPwicDi3Xr
https://open.spotify.com/track/0MSAWjq5aWfTUNL9hv7Epd
wmp@LUBN366:/mnt/d/Users/wmp/Praca/skrypty/spotify-downloader$ rm Music/*; python spotdl.py -l samochod.txt -a
Total songs in list: 9 songs

  1. Jan Hammer Project feat. TQ - Crockett's Theme (Radio Version)
    3,915,256 Bytes [100.00%] received. Rate: [10549 KB/s]. ETA: [0 secs]
    Converting Jan_Hammer_Project_feat_TQ_-Crocketts_Theme(Radio_Version).m4a to mp3
    Fixing meta-tags

  2. Tatu - 30 minutes [Russisch] Lyrics
    3,101,374 Bytes [100.00%] received. Rate: [10741 KB/s]. ETA: [0 secs]
    Converting Tatu_-30_minutes[Russisch]_Lyrics.m4a to mp3
    Fixing meta-tags

  3. Insatiable... Español... Darren Hayes
    4,947,525 Bytes [100.00%] received. Rate: [10873 KB/s]. ETA: [0 secs]
    Converting Insatiable_Español_Darren_Hayes.m4a to mp3
    Fixing meta-tags

  4. Creed - With Arms Wide Open (Strings Version)
    3,739,360 Bytes [100.00%] received. Rate: [10632 KB/s]. ETA: [0 secs]
    Converting Creed_-With_Arms_Wide_Open(Strings_Version).m4a to mp3
    Fixing meta-tags

  5. Sexual guarantee-Alcazar
    3,452,528 Bytes [100.00%] received. Rate: [10786 KB/s]. ETA: [0 secs]
    Converting Sexual_guarantee-Alcazar.m4a to mp3
    Fixing meta-tags

  6. Leon - Sugababes, Shape of my Heart
    3,994,968 Bytes [100.00%] received. Rate: [6918 KB/s]. ETA: [0 secs]
    Converting Leon_-_Sugababes_Shape_of_my_Heart.m4a to mp3
    Fixing meta-tags

  7. Crazy Town Butterfly Bison Sing
    3,421,929 Bytes [100.00%] received. Rate: [10212 KB/s]. ETA: [0 secs]
    Converting Crazy_Town_Butterfly_Bison_Sing.m4a to mp3
    Fixing meta-tags

  8. Nelly - Dilemma (feat. Kelly Rowland) - Clean
    4,590,832 Bytes [100.00%] received. Rate: [10902 KB/s]. ETA: [0 secs]
    Converting Nelly_-Dilemma(feat_Kelly_Rowland)_-_Clean.m4a to mp3
    Fixing meta-tags

  9. Sandra - In The Heat Of The Night (Long Version) ᴴᴰ
    4,841,134 Bytes [100.00%] received. Rate: [10451 KB/s]. ETA: [0 secs]
    Converting Sandra_-In_The_Heat_Of_The_Night(Long_Version)_HD.m4a to mp3
    Fixing meta-tags

wmp@LUBN366:/mnt/d/Users/wmp/Praca/skrypty/spotify-downloader$ cd Music/
wmp@LUBN366:/mnt/d/Users/wmp/Praca/skrypty/spotify-downloader/Music$ for i in *.mp3; do echo $"$i"; ffmpeg -af "volumedetect" -f null /dev/null -i $i 2>&1 | grep Parsed_volumedetect; done Crazy_Town_Butterfly_Bison_Sing.mp3
[Parsed_volumedetect_0 @ 0x2cfe9c0] n_samples: 19003392
[Parsed_volumedetect_0 @ 0x2cfe9c0] mean_volume: -24.2 dB ## Very very loud :(
[Parsed_volumedetect_0 @ 0x2cfe9c0] max_volume: -7.4 dB
[Parsed_volumedetect_0 @ 0x2cfe9c0] histogram_7db: 16
[Parsed_volumedetect_0 @ 0x2cfe9c0] histogram_8db: 100
[Parsed_volumedetect_0 @ 0x2cfe9c0] histogram_9db: 742
[Parsed_volumedetect_0 @ 0x2cfe9c0] histogram_10db: 3571
[Parsed_volumedetect_0 @ 0x2cfe9c0] histogram_11db: 12328
[Parsed_volumedetect_0 @ 0x2cfe9c0] histogram_12db: 31720
Creed_-With_Arms_Wide_Open(Strings_Version).mp3
[Parsed_volumedetect_0 @ 0x3b88ca0] n_samples: 20765952
[Parsed_volumedetect_0 @ 0x3b88ca0] mean_volume: -13.2 dB
[Parsed_volumedetect_0 @ 0x3b88ca0] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0x3b88ca0] histogram_0db: 16132
[Parsed_volumedetect_0 @ 0x3b88ca0] histogram_1db: 45792
Insatiable_Español_Darren_Hayes.mp3
[Parsed_volumedetect_0 @ 0x35c1ba0] n_samples: 27475200
[Parsed_volumedetect_0 @ 0x35c1ba0] mean_volume: -16.3 dB
[Parsed_volumedetect_0 @ 0x35c1ba0] max_volume: -0.2 dB
[Parsed_volumedetect_0 @ 0x35c1ba0] histogram_0db: 12
[Parsed_volumedetect_0 @ 0x35c1ba0] histogram_1db: 166
[Parsed_volumedetect_0 @ 0x35c1ba0] histogram_2db: 891
[Parsed_volumedetect_0 @ 0x35c1ba0] histogram_3db: 7390
[Parsed_volumedetect_0 @ 0x35c1ba0] histogram_4db: 35194
Jan_Hammer_Project_feat_TQ_-Crocketts_Theme(Radio_Version).mp3
[Parsed_volumedetect_0 @ 0x34ec7c0] n_samples: 21742848
[Parsed_volumedetect_0 @ 0x34ec7c0] mean_volume: -10.7 dB
[Parsed_volumedetect_0 @ 0x34ec7c0] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0x34ec7c0] histogram_0db: 80489
Leon_-Sugababes_Shape_of_my_Heart.mp3
[Parsed_volumedetect_0 @ 0x242a620] n_samples: 22185216
[Parsed_volumedetect_0 @ 0x242a620] mean_volume: -13.7 dB # Better version that official fork
[Parsed_volumedetect_0 @ 0x242a620] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0x242a620] histogram_0db: 2866
[Parsed_volumedetect_0 @ 0x242a620] histogram_1db: 64371
Nelly
-Dilemma(feat_Kelly_Rowland)-Clean.mp3
[Parsed_volumedetect_0 @ 0x38fca20] n_samples: 25493760
[Parsed_volumedetect_0 @ 0x38fca20] mean_volume: -12.5 dB
[Parsed_volumedetect_0 @ 0x38fca20] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0x38fca20] histogram_0db: 101993
Sandra
-In_The_Heat_Of_The_Night(Long_Version)HD.mp3
[Parsed_volumedetect_0 @ 0x313a600] n_samples: 26597376
[Parsed_volumedetect_0 @ 0x313a600] mean_volume: -11.4 dB
[Parsed_volumedetect_0 @ 0x313a600] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0x313a600] histogram_0db: 91982
Sexual_guarantee-Alcazar.mp3
[Parsed_volumedetect_0 @ 0x30cf260] n_samples: 18968832
[Parsed_volumedetect_0 @ 0x30cf260] mean_volume: -12.2 dB
[Parsed_volumedetect_0 @ 0x30cf260] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0x30cf260] histogram_0db: 10453
[Parsed_volumedetect_0 @ 0x30cf260] histogram_1db: 45568
Tatu
-30_minutes[Russisch]Lyrics.mp3
[Parsed_volumedetect_0 @ 0x2a8da20] n_samples: 17222400
[Parsed_volumedetect_0 @ 0x2a8da20] mean_volume: -12.8 dB
[Parsed_volumedetect_0 @ 0x2a8da20] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0x2a8da20] histogram_0db: 21100
wmp@LUBN366:/mnt/d/Users/wmp/Praca/skrypty/spotify-downloader/Music$ for i in *.mp3; do echo "$i"; ffmpeg -i $i 2>&1 | grep Duration | awk '{print $2}' | tr -d ,; done
Crazy_Town_Butterfly_Bison_Sing.mp3
00:03:35.46
Creed
-With_Arms_Wide_Open(Strings_Version).mp3
00:03:55.44
Insatiable_Español_Darren_Hayes.mp3 ## Wrong language version
00:05:11.51
Jan_Hammer_Project_feat_TQ
-Crocketts_Theme(Radio_Version).mp3
00:04:06.52
Leon_-Sugababes_Shape_of_my_Heart.mp3
00:04:11.53
Nelly
-Dilemma(feat_Kelly_Rowland)_-Clean.mp3
00:04:49.04
Sandra
-In_The_Heat_Of_The_Night(Long_Version)HD.mp3 ## Good version
00:05:01.56
Sexual_guarantee-Alcazar.mp3
00:03:35.07
Tatu
-30_minutes[Russisch]_Lyrics.mp3 ## Good version without speaks from downlaoded with official version
00:03:15.27
wmp@LUBN366:/mnt/d/Users/wmp/Praca/skrypty/spotify-downloader/Music$
`

Summary:
image

@linusg
Copy link
Contributor

linusg commented Jul 14, 2017

Wow, thank you for the effort! 😄
I'll definitively look into this later! Let's see, what we can do about it.

@KLVN
Copy link
Contributor

KLVN commented Jul 14, 2017

(Could also integrate if the channel name contains VEVO etc.)

could you please give one or two examples where this is indeed the case? So the song names or Spotify links where the cases you've described apply.

https://github.com/ritiek/spotify-downloader/issues/31#issuecomment-314580638 🤔

@ritiek
Copy link
Member

ritiek commented Jul 14, 2017

This PR seems to be working good. I tested on some songs and also on a few ones that are known to cause issues like below:

http://open.spotify.com/track/3ZffCQKLFLUvYM59XKLbVm
(contain conversations when downloaded with original code but fixed with this PR)

http://open.spotify.com/track/5EauMVTXVoQOkax03XXVaV
(very low quality audio when downloaded from original code but fixed with this PR)

I haven't come across any issues yet. So far great.

@ritiek
Copy link
Member

ritiek commented Jul 15, 2017

I think it will be nice to have this PR merged. @linusg what do you think?

@linusg
Copy link
Contributor

linusg commented Jul 15, 2017

I did some small tests now and it works fine! I see no problem in merging, as I can definitively reproduce the results. Maybe it will also be a good improvement for some of the songs I downloaded, I'll see. My only concerns though are the tests failing: https://travis-ci.org/ritiek/spotify-downloader/jobs/253803168. Basically the YouTube URLs are different now and there's some type issue (indexing string but not passing an int to the brackets – don't know if this was introduced here).

So basically yes, but the tests should be fixed before.

@ritiek
Copy link
Member

ritiek commented Jul 15, 2017

Okay, I'll fix the tests tomorrow (kinda late here). @lkgarrison I personally don't think this should be added as an "additional feature" though, it works great as is in defaults. The main purpose of the automatic downloading is to download the best matching song and this PR just improves it.

@linusg
Copy link
Contributor

linusg commented Jul 15, 2017

To be fair, I had the idea of making this optional too, but I see it the same way as @ritiek – making this default would be no bad at all 😄

Ah, and If you want to I can look into the tests – but a pointer what is wrong with the indices would be great. If you guys have no idea, I'll spend my time debugging.

@ritiek
Copy link
Member

ritiek commented Jul 16, 2017

@linusg That seems to happening because generate_songname() now takes meta_tags as a parameter instead of raw_song.

Replacing

songname = spotdl.generate_songname(raw_song)

with

meta_tags = spotdl.generate_metadata(raw_song)
songname = spotdl.generate_songname(meta_tags)

in every test function in test_single.py should suffice.

Also as test_youtube_url() and test_youtube_title() are passing already, we won't have to make changes there, since the first YouTube result is considered as the best matching song by this PR.

There are some more changes that could be made to tests to make them run faster but lets just focus on the tests passing any how at the moment.

Copy link
Member

@ritiek ritiek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I think this is ready to merge. Thanks @WMP! 😄

@ritiek ritiek merged commit 4cf8a21 into spotDL:master Jul 17, 2017
@WMP
Copy link
Contributor Author

WMP commented Jul 17, 2017

Thanks @ritiek ! :)

@lkgarrison
Copy link
Contributor

@ritiek I think it's great as a default feature too. I only suggested it as an optional feature in case it wasn't working quite as well as expected as it would give people the ability to "use at their own risk". As it stands I definitely agree - it certainly seems to improve the automatic downloading.

Thanks for everyone's work on this!

@lkgarrison
Copy link
Contributor

How does the PR select the right video with the same time as the Spotify song? In my testing I've seen a few downloads that didn't sound right, such as
https://open.spotify.com/track/69uxyAqqPIsUyTO8txoP2M
https://open.spotify.com/track/5Fli1xRi01bvCjsZvKWro0
https://open.spotify.com/track/3swtAu849ueENeQ2cIFUEP

My concern is that the new code is looking for a song that is the exact same time length as the Spotify song, and if the true best youtube match is even 1 second different and there is another youtube video that is the exact same length but is far worse quality and is distorted (like the above examples) then it should not be using the video that is the exact length but not good quality. I think ideally it should be a the Youtube song with the highest number of views that is also +/- 5 seconds in length from the Spotify song. This isn't to say it never works, but I have about 1 or 2 in 10 songs definitely don't sound like the spotify track. Let me know what you guys think

@lkgarrison
Copy link
Contributor

For the first link I posted above, you can see that it is grabbing the "chipmunks version"

image

@ritiek
Copy link
Member

ritiek commented Jul 19, 2017

Both ways of selecting the YouTube song have their own ups and downs. I'll spend some more time trying to optimize it and hopefully fix these issues.

@WMP
Copy link
Contributor Author

WMP commented Jul 19, 2017

How does the PR select the right video with the same time as the Spotify song?

videos.sort(key=lambda x: abs(x['seconds'] - (int(meta_tags['duration_ms'])/1000)))

This line count difference betwen spotify duration and youtube duration and sort by smallest difference.

@lkgarrison if you want download single song, better is use manual option. I dokt know why, but i have other version that you:

wmp@LUBN366:/mnt/d/Users/wmp/Praca/skrypty/spotify-downloader$ python spotdl.py -s https://open.spotify.com/track/69uxyAqqPIsUyTO8txoP2M
Coldplay - Adventure Of A Lifetime HQ
  4,196,031 Bytes [100.00%] received. Rate: [5017 KB/s].  ETA: [0 secs]
Converting Coldplay_-_Adventure_Of_A_Lifetime.m4a to mp3
Fixing meta-tags
wmp@LUBN366:/mnt/d/Users/wmp/Praca/skrypty/spotify-downloader$ git remote -v; git pull
origin  https://github.com/ritiek/spotify-downloader.git (fetch)
origin  https://github.com/ritiek/spotify-downloader.git (push)
Already up-to-date.
wmp@LUBN366:/mnt/d/Users/wmp/Praca/skrypty/spotify-downloader$

@lkgarrison
Copy link
Contributor

@ritiek, I'm considering grabbing the view count off of the html just like the video length is grabbed. Is it an OK assumption that the structure of the html won't be changing any time soon? I suppose if it did, it would break much more than just the view count?

@ritiek
Copy link
Member

ritiek commented Jul 19, 2017

@lkgarrison There is also another easy way to get the view count (and length too), you should use:

import pafy
c = pafy.new('https://www.youtube.com/watch?v=OC-YdBz8Llw')
print(c.viewcount)

pafy uses the YouTube API, so it should be stable enough for the time being. Some one (or me) will need to make the same changes for getting the length too for stability purposes.

@lkgarrison
Copy link
Contributor

@ritiek awesome! I'll see what I can do with that!

@ritiek
Copy link
Member

ritiek commented Jul 20, 2017

@lkgarrison I've got another idea! We could use the YouTube filter to sort the videos results by view count by replacing the URL here with https://www.youtube.com/results?q={0}&sp=CAMSAhABUBQ%253D and then look for the video with the closest duration to spotify. I think this approach will be better than both the previous attempts. What say?

@ritiek
Copy link
Member

ritiek commented Jul 20, 2017

Btw, I experimented a little but it seems like it won't be a good idea to use pafy to get information about all of the videos on the search results as pafy takes quite a time to parse a video. Each page contains about 20 videos, it would take a minute or so, parsing them with pafy. I think we are better off with extracting info from the HTML, even though it isn't a good idea in the long run.

@linusg
Copy link
Contributor

linusg commented Jul 20, 2017

I see no problem in directly parsing the HTML at all. YouTube knows that by changibg the overall structure they'll probably break tons of 3rd party software not using their API. However, before doing so they'll announce it for sure so people can react.

@lkgarrison
Copy link
Contributor

lkgarrison commented Jul 22, 2017

@ritiek I agree, I found that using pafy on all 20 results was quite slow. I also experimented with extracting the viewcount from the html, but after some testing, I found I was still getting more incorrect versions than expected. What I eventually found was best was to simply filter out the video results that are too much longer/shorter than the spotify song but keep the results in the same order that Youtube returned them (noting that Youtube is generally better at picking the most relevant results than I am i.e. trying to sort by highest viewcount only)).

While I am still refining the implementation, the core logic of the idea is to use a similar filter function:

duration_tolerance = 6
possible_videos_by_duration = list(filter(lambda x: abs(x['seconds'] -(int(meta_tags['duration_ms'])/1000)) <= duration_tolerance, videos))

(this code would go in spotdl.py near line 100 in the else corresponding to "if args.manual")

This is the basic idea, but it still needs refined such as potentially retrying up to a duration_tolerance of 20s in case a duration_tolerance of 6 results in no matching videos.

In testing, this downloaded the expected song 79/80 times

@lkgarrison
Copy link
Contributor

@ritiek @linusg I've made the above changes that I mentioned and tested on a playlist of 220 songs. Only 5 songs were downloaded with the wrong version. Most of these instances were because the official music video had extra noises in the first few seconds and I wanted the exact same audio as Spotify, so I wanted a different version.

Thus, after extensive testing, the code I added has yielded the best youtube video selection thus far with the fewest mp3's needing re-done manually.

Let me know if you'd like to get this merged and anything further that I can do to assist.

@linusg
Copy link
Contributor

linusg commented Aug 10, 2017

Thanks for the effort! Would you mind preparing a PR? So we can test it both manually and using the automated tests. I have almost no concerns, sounds pretty neat 😄

@ritiek
Copy link
Member

ritiek commented Aug 12, 2017

@lkgarrison Yeah, make a PR and we'll go further from there. Thank you for your effort!

@ritiek ritiek changed the title Change for automatical download video with this same duration as spotify song Download music with length closest to one on Spotify Dec 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants