|
39 | 39 | from headphones.common import USER_AGENT
|
40 | 40 | from headphones.types import Result
|
41 | 41 | from headphones import logger, db, helpers, classes, sab, nzbget, request
|
42 |
| -from headphones import utorrent, transmission, notifiers, rutracker, deluge, qbittorrent, bandcamp |
| 42 | +from headphones import utorrent, transmission, notifiers, rutracker, deluge, qbittorrent, bandcamp, soulseek |
| 43 | + |
43 | 44 |
|
44 | 45 | # Magnet to torrent services, for Black hole. Stolen from CouchPotato.
|
45 | 46 | TORRENT_TO_MAGNET_SERVICES = [
|
@@ -260,6 +261,8 @@ def strptime_musicbrainz(date_str):
|
260 | 261 |
|
261 | 262 |
|
262 | 263 | def do_sorted_search(album, new, losslessOnly, choose_specific_download=False):
|
| 264 | + |
| 265 | + |
263 | 266 | NZB_PROVIDERS = (headphones.CONFIG.HEADPHONES_INDEXER or
|
264 | 267 | headphones.CONFIG.NEWZNAB or
|
265 | 268 | headphones.CONFIG.NZBSORG or
|
@@ -300,7 +303,11 @@ def do_sorted_search(album, new, losslessOnly, choose_specific_download=False):
|
300 | 303 | results = searchNZB(album, new, losslessOnly, albumlength)
|
301 | 304 |
|
302 | 305 | if not results and headphones.CONFIG.BANDCAMP:
|
303 |
| - results = searchBandcamp(album, new, albumlength) |
| 306 | + results = searchBandcamp(album, new, albumlength) |
| 307 | + |
| 308 | + elif headphones.CONFIG.PREFER_TORRENTS == 2 and not choose_specific_download: |
| 309 | + results = searchSoulseek(album, new, losslessOnly, albumlength) |
| 310 | + |
304 | 311 | else:
|
305 | 312 |
|
306 | 313 | nzb_results = None
|
@@ -344,6 +351,7 @@ def do_sorted_search(album, new, losslessOnly, choose_specific_download=False):
|
344 | 351 | (data, result) = preprocess(sorted_search_results)
|
345 | 352 |
|
346 | 353 | if data and result:
|
| 354 | + #print(f'going to send stuff to downloader. data: {data}, album: {album}') |
347 | 355 | send_to_downloader(data, result, album)
|
348 | 356 |
|
349 | 357 |
|
@@ -849,11 +857,15 @@ def send_to_downloader(data, result, album):
|
849 | 857 | except Exception as e:
|
850 | 858 | logger.error('Couldn\'t write NZB file: %s', e)
|
851 | 859 | return
|
852 |
| - |
853 | 860 | elif kind == 'bandcamp':
|
854 | 861 | folder_name = bandcamp.download(album, result)
|
855 | 862 | logger.info("Setting folder_name to: {}".format(folder_name))
|
856 | 863 |
|
| 864 | + |
| 865 | + elif kind == 'soulseek': |
| 866 | + soulseek.download(user=result.user, filelist=result.files) |
| 867 | + folder_name = result.folder |
| 868 | + |
857 | 869 | else:
|
858 | 870 | folder_name = '%s - %s [%s]' % (
|
859 | 871 | unidecode(album['ArtistName']).replace('/', '_'),
|
@@ -1918,14 +1930,49 @@ def set_proxy(proxy_url):
|
1918 | 1930 | return results
|
1919 | 1931 |
|
1920 | 1932 |
|
| 1933 | +def searchSoulseek(album, new=False, losslessOnly=False, albumlength=None): |
| 1934 | + # Not using some of the input stuff for now or ever |
| 1935 | + replacements = { |
| 1936 | + '...': '', |
| 1937 | + ' & ': ' ', |
| 1938 | + ' = ': ' ', |
| 1939 | + '?': '', |
| 1940 | + '$': '', |
| 1941 | + ' + ': ' ', |
| 1942 | + '"': '', |
| 1943 | + ',': '', |
| 1944 | + '*': '', |
| 1945 | + '.': '', |
| 1946 | + ':': '' |
| 1947 | + } |
| 1948 | + |
| 1949 | + num_tracks = get_album_track_count(album['AlbumID']) |
| 1950 | + year = get_year_from_release_date(album['ReleaseDate']) |
| 1951 | + cleanalbum = unidecode(helpers.replace_all(album['AlbumTitle'], replacements)).strip() |
| 1952 | + cleanartist = unidecode(helpers.replace_all(album['ArtistName'], replacements)).strip() |
| 1953 | + |
| 1954 | + results = soulseek.search(artist=cleanartist, album=cleanalbum, year=year, losslessOnly=losslessOnly, num_tracks=num_tracks) |
| 1955 | + |
| 1956 | + return results |
| 1957 | + |
| 1958 | + |
| 1959 | +def get_album_track_count(album_id): |
| 1960 | + # Not sure if this should be considered a helper function. |
| 1961 | + myDB = db.DBConnection() |
| 1962 | + track_count = myDB.select('SELECT COUNT(*) as count FROM tracks WHERE AlbumID=?', [album_id])[0]['count'] |
| 1963 | + return track_count |
| 1964 | + |
| 1965 | + |
1921 | 1966 | # THIS IS KIND OF A MESS AND PROBABLY NEEDS TO BE CLEANED UP
|
1922 | 1967 |
|
1923 | 1968 |
|
1924 | 1969 | def preprocess(resultlist):
|
1925 | 1970 | for result in resultlist:
|
1926 |
| - |
1927 | 1971 | headers = {'User-Agent': USER_AGENT}
|
1928 | 1972 |
|
| 1973 | + if result.kind == 'soulseek': |
| 1974 | + return True, result |
| 1975 | + |
1929 | 1976 | if result.kind == 'torrent':
|
1930 | 1977 |
|
1931 | 1978 | # rutracker always needs the torrent data
|
|
0 commit comments