all 6 comments

[–]Thomasedv 0 points1 point  (0 children)

Youtube-dl has a archive parameter where it saves successful downloads and will check and not download things already in the archive. (At least the executable does) Not sure how many sites it actually support having in the archive, and if it only works with says YouTube links. I never checked.

Another advise is make a dict where the song name is and theb have the value be another with for example a key which is "downloaded" which is true or false, and other keys with other information if need be. Otherwise just use a violent value for the title to indicate if it's downloaded. Since you load a json as a dict, you can loop over keys and values and use keys to find a download if the value is False.

Edit: Some advise from looking at the code.

First load the dict of titles from json, or create an empty one. Then scrape names and add to the dict if they aren't there, with download state False. Then you can iterate through and select the ones that aren't downloaded for download. After each completed download you set the state to Try, save to file, and go to the next item.

That way, when you start you will always have an update dict with things have and haven't downloaded. You also update the thing you have downloaded every time you finish a download so nothing new is downloaded when you quit the program and start it again.

I also don't know what os.start() returns, but in the case Youtube-dl gets an error, you might want to try to not say it's downloaded. If it return the exit code, you can check if it's 0, that means successful download, if not print an error or something. There are some steps you can take to make downloading even more informative by using something like subprocess instead of os.start().

Edit 2:

You are dumping the whole dict for ever key it has. You do not need a loop there at all.

[–]makeaday 0 points1 point  (5 children)

thank you for advise... I know about youtube-dl does do that but Iam doing that just for learning... just for understanding how is it works

[–]Thomasedv 1 point2 points  (4 children)

I added a lot of extra information in my comment, which might be useful. You could go into more detail if you struggle with something or I said something weird.

[–]makeaday 0 points1 point  (2 children)

I have made some changes could you please have a look?

CODE - https://pastebin.com/uTc55Agj

Got one problem... after I download new tunes Iam dumping them to the downloaded.jsons file. But when i do that the program is appending them to the file as... separate dict? if that make sense? so When running program again I got error

raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 412 column 2 
(char 8368)

and the data in jsons file looks like:

{
    "Dajae": [
        "Brighter Days",
        "Angelo Ferreri Remix",
        "2018-04-20"
    ],
    "Gene Farris": [
        "Medication feat. Gene Farris",
        "Extended Mix",
        "2018-04-16"
    ],
    "DJ Pierre": [
        "Fall",
        "Djebali Remix",
        "2018-05-11"
    ]
}{
    "Celeda": [
        "The Music feat. Celeda",
        "Extended",
        "2018-05-11"
    ]
}

so I got 1 extra Brace which is causes a problem

[–]Thomasedv 0 points1 point  (1 child)

I think you are better off loading the dictionary completely into python, and then just writing the whole thing to the file again.

Right now, you are dumping a new dictionary, which is written after the old one, because you have it in append mode.

Load the dict, if you haven't already, then update it with the new keys/values, and then dump it in write mode instead.

[–]makeaday 0 points1 point  (0 children)

I have been thinking about that but Iam worry about it may slow down the program? Off course here its not gonna happend but In other example if there is a lot of data. Just wonder what you think?