1. Python / Говнокод #24279

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    import json
    import time
    import requests
    from multiprocessing.dummy import Pool as ThreadPool
    max_threads = 10
    fname = "data.json"
    headers = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36", "referer":"https://datmusic.xyz/?q=Home+resonance", "authority":"api-2.datmusic.xyz"}
    
    def api(url):
        while True:
            try:
                r = requests.get(url, headers=headers)
                r = r.json()
                if r['status'] == 'error':
                    pass
                else:
                    return r['data'][0]['download']
            except Exception as e:
                pass
    def download(a):
        # open in binary mode
        while True:
            try:
                with open(a[1]+".mp3", "wb") as file:
                    response = requests.get(a[0],headers=headers)
                    if not (response.status_code == 503):
                        file.write(response.content)
                        print(a[1],"downloaded")
                        break
                    else:
                        pass
            except Exception as e:
                pass
    
    songs = []
    
    with open(fname) as json_data:
        data = json.load(json_data)
        for mp3 in data['list']:
            song = []
            autor = mp3[4]
            title = mp3[3][:-5]
            song.append(autor)
            song.append(title)
            songs.append(song)
    
    links = []
    
    def linker(a):
        song = []
        link = api("https://api-2.datmusic.xyz/search?q=" + a[0] + "+" + a[1] + "&page=0")
        song.append(link)
        song.append(a[0] + ' - ' + a[1])
        links.append(song)
        print(a[1])
    
    for a in songs:
        linker(a)
        #if len(links) > 10:
        #   break
    
    pool = ThreadPool(max_threads)
    results = pool.map(download, links)
    pool.close()
    pool.join()

    #Наговнокодил загрущик плейлистов с контача. Как получить json плейлиста подумай сам (перейди в музыку, открой Network в f12 и мониторь запрос при открытии плейлиста)
    #Парсер 1 поточный, загрущик многопоточный. Работает через апи datmusic.xyz спс им
    #vk.com music downloader v1.0a
    #загрущик музыки вк
    json = https://gist.githubusercontent.com/alekxeyuk/a1ccd2c62ab56a71320a02582cfc06f9/raw/4f2622c4beeddfa7e3082c276e1c138c87478e83/data.json

    Запостил: pacaw, 17 Мая 2018

    Комментарии (4) RSS

    Добавить комментарий