Sfoglia il codice sorgente

updated

sharky-custom
sharky555 2 anni fa
parent
commit
7d8b1c6745
3 ha cambiato i file con 100 aggiunte e 39 eliminazioni
  1. +2
    -1
      .gitignore
  2. +98
    -35
      autoupload.py
  3. +0
    -3
      copycommands.txt

+ 2
- 1
.gitignore Vedi File

@@ -1,4 +1,5 @@
__pycache__
config.json
*session.dat
*.torrent
*.torrent
copycommands.txt

+ 98
- 35
autoupload.py Vedi File

@@ -38,7 +38,14 @@ def getargs():
parser = argparse.ArgumentParser()
parser.add_argument('-dir', '--directory', help='Initiate upload on directory', nargs='?', required=True)
parser.add_argument("-f", "--freeleech", help="Enables freeleech", action="store_true")
parser.add_argument("-a", "--artist", help='Set the artists. (Romaji\English)', nargs='?')
parser.add_argument("-ti", "--title", help='Set the title. (Romaji\English)', nargs='?')
parser.add_argument("-rt", "--releasetype", help='Set the release type. (Album, Single)', nargs='?')
parser.add_argument("-t", "--tags", help="Add additional tags to the upload", nargs='?')
parser.add_argument("-eti", "--editiontitle", help='Set the edition title', nargs='?')
parser.add_argument("-ey", "--editionyear", help='Set the torrent edition year (YYYYMMDD or YYYY).', nargs='?')
parser.add_argument("-tdes", "--torrentdescription", help='Add a torrent description', nargs='?')
parser.add_argument("-im", "--imageURL", help='Set the torrent cover URL.', nargs='?')
parser.add_argument('-d', '--debug', help='Enable debug mode', action='store_true')
parser.add_argument("-dry", "--dryrun", help="Dryrun will carry out all actions other than the actual upload to JPS.", action="store_true")
@@ -93,7 +100,11 @@ def createtorrent(authkey, directory, filename, releasedata):
# Reads FLAC file and returns metadata.
def readflac(filename):
read = FLAC(filename)
# get some audio info
audio_info={
"SAMPLE_RATE": read.info.sample_rate,
"BIT_DEPTH": read.info.bits_per_sample
}
# Create dict containing all meta fields we'll be using.
tags={
"ALBUM": read.get('album'),
@@ -121,7 +132,7 @@ def readflac(filename):
print(f"{k} has returned {v}, this is a required tag")
sys.exit()
return tags
return tags, audio_info
# Reads MP3 file and returns metadata.
def readmp3(filename):
@@ -313,6 +324,18 @@ def translate(string, category, result=None, output=None):
return output
def determine_flac_bitdepth_and_samplerate(audio_info):
if audio_info['BIT_DEPTH'] == 16:
return "Lossless"
elif audio_info['BIT_DEPTH'] == 24 and audio_info['SAMPLE_RATE'] == 96000:
return "24bit/96Khz"
elif audio_info['BIT_DEPTH'] == 24 and audio_info['SAMPLE_RATE'] == 48000:
return "24bit/48Khz"
elif audio_info['BIT_DEPTH'] == 24 and audio_info['SAMPLE_RATE'] == 44100:
return "24bit/44.1Khz"
else:
return "24bit"
def gatherdata(directory):
# Lists for storing some
list_album_artists = []
@@ -335,7 +358,7 @@ def gatherdata(directory):
file_location = os.path.join(directory, file)
if file.endswith(".flac"):
# Read FLAC file to grab meta
tags = readflac(file_location)
tags, audio_info = readflac(file_location)
flac_present = True
# If Discnumber isn't present then we omit it from the tracklist entry
if tags['DISCNUMBER'] == None:
@@ -380,7 +403,7 @@ def gatherdata(directory):
# Check files to make sure there's no multi-format.
if flac_present:
format = 'FLAC'
bitrate = 'Lossless'
bitrate = determine_flac_bitdepth_and_samplerate(audio_info)
if mp3_present:
format = 'MP3'
bitrate = '320'
@@ -440,15 +463,15 @@ def gatherdata(directory):
## If release description is enabled we apply comments to the bugs album url
# Note that this is dependant on the album being sourced from bugs so should be changed per user.
if cfg['local_prefs']['enable_release_description']:
try:
release_description = f"Sourced from [url=https://music.bugs.co.kr/album/{tags['COMMENT'][0]}]Bugs[/url]"
# If any exceptions occur we will return to no release description
except:
release_description = ""
# If release description is not enabled we will use no release description
else:
release_description = ""
# if cfg['local_prefs']['enable_release_description']:
# try:
# release_description = f"Sourced from [url=https://music.bugs.co.kr/album/{tags['COMMENT'][0]}]Bugs[/url]"
# # If any exceptions occur we will return to no release description
# except:
# release_description = ""
# # If release description is not enabled we will use no release description
# else:
# release_description = ""
## Assign all our unique values into releasedata{}. We'll use this later down the line for POSTING.
# POST values can be found by inspecting JPS HTML
@@ -456,21 +479,21 @@ def gatherdata(directory):
# List of accepted upload types
accepted_types = ['Album', 'Single']
# If type errors then we ask for user input
try:
releasedata['type'] = translate(tags['GROUPING'][0], "release_types")[0]
except TypeError:
releasedata['type'] = input("\n" + "_" * 100 + "\nGrouping is empty or has received an error, please enter manually (Album/Single)\n")
# If type is still not in accepted_types we ask for user input again and do not break loop until correct
if releasedata['type'] not in accepted_types:
while True:
releasedata['type'] = input("\n" + "_" * 100 + "\nGrouping tag did not return an album type, please enter manually (Album/Single)\n")
if releasedata['type'] not in accepted_types:
continue
else:
break
if releasetype not in accepted_types:
if releasetype:
releasedata['type'] = releasetype
else:
while(True):
input_releasetype = input("\n" + "_" * 100 + "\nEnter a number to choose the release type. \n1=Album\n2=Single\n")
if input_releasetype == "1":
releasedata["type"] = "Album"
break
elif input_releasetype == "2":
releasedata["type"] = "Single"
break
print("Invalid choice.")
else:
releasedata['type'] = releasetype
releasedata['title'] = tags['ALBUM'][0]
@@ -481,10 +504,16 @@ def gatherdata(directory):
#re.sub removes any date separators, jps doesn't accept them
releasedata['releasedate'] = re.sub(r"[^0-9]", "", tags['DATE'])
releasedata['format'] = format
releasedata['bitrate'] = bitrate
if bitrate != "Lossless":
releasedata['bitrate'] = "Other"
releasedata['other_bitrate'] = bitrate
else:
releasedata['bitrate'] = bitrate
releasedata['media'] = media
releasedata['album_desc'] = album_description
releasedata['release_desc'] = release_description
# releasedata['release_desc'] = release_description
releasedata['release_desc'] = torrentdescription
releasedata['tags'] = unique_genre
# Enable freeleech if arg is passed
@@ -509,10 +538,25 @@ def gatherdata(directory):
if debug:
print(f"{releasedata['artist']} < English = {en}")
if en == False:
input_english_artist = input("\n" + "_" * 100 + "\nKorean/Japanese Detected. Please enter the romaji/english artist name:\n")
# Create new key called titlejp and assign the old title to it
# Replace title with the user input.
releasedata['artist'] = input_english_artist
if artists:
input_english_artist = artists
else:
input_english_artist = input("\n" + "_" * 100 + "\nPlease enter the romaji/english artist name. Separate multiple main artists with \",\".\n")
input_english_artist = [x.strip() for x in input_english_artist.split(',')]
releasedata['idols[]'] = input_english_artist
if editiontitle:
releasedata['remaster_title'] = editiontitle
else:
input_editiontitle = input("\n" + "_" * 100 + "\nEnter the edition TITLE. Press enter to skip.\n")
print(input_editiontitle)
if input_editiontitle != "":
if editionyear:
releasedata["remaster_year"] = editionyear
else:
input_editionyear = input("\n" + "_" * 100 + "\nEnter the edition year as YYYY.\n")
releasedata["remaster_year"] = input_editionyear
releasedata['remaster_title'] = input_editiontitle
return releasedata
@@ -546,6 +590,8 @@ def uploadtorrent(torrent, cover, releasedata):
# Dataset containing all of the information obtained from our FLAC files.
data = releasedata
if imageURL:
data['image'] = imageURL
if debug:
print('_' * 100)
@@ -647,10 +693,27 @@ if __name__ == "__main__":
args = getargs()
# TODO consider calling args[] directly, we will then not need this line
dryrun = freeleech = tags = directory = debug = None
dryrun = freeleech = tags = directory = editiontitle = editionyear = artist = torrentdescription = releasetype = debug = audio_info = None
directory = args.directory
additional_tags = args.tags
if torrentdescription:
torrentdescription = args.torrentdescription
if args.editiontitle:
editiontitle = args.editiontitle
if args.editionyear:
editionyear = args.editionyear
if args.imageURL:
imageURL = args.imageURL
if args.releasetype:
releasetype = args.releasetype
if args.artist:
artists = args.artist
if args.dryrun:
dryrun = True


+ 0
- 3
copycommands.txt Vedi File

@@ -1,3 +0,0 @@
python autoupload.py -t "japanese, rock, alternative, male.vocalist" -dir "C:\for_upload\ヒトリエ - PHARMACY (2022-06-22) [WEB FLAC]"

Caricamento…
Annulla
Salva