diff --git a/autoupload.py b/autoupload.py index 2b003bf..e2604e7 100644 --- a/autoupload.py +++ b/autoupload.py @@ -40,7 +40,7 @@ def getargs(): parser.add_argument("-t", "--tags", help="Add additional tags to the upload", 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") - + parser.add_argument("-i", "--imageURL", help='Set the torrent cover URL', nargs='?') return parser.parse_args() # Acquire the authkey used for torrent files from upload.php @@ -55,7 +55,6 @@ def getauthkey(): soup = BeautifulSoup(smpage.text, 'html5lib') rel2 = str(soup.select('#content .thin .main_column .torrent_table tbody')) authkey = re.findall('authkey=(.*)&torrent_pass=', rel2) - print(authkey) return authkey @@ -79,7 +78,7 @@ def createtorrent(authkey, directory, filename, releasedata): ## Format releasedata to bring a suitable torrent name. # The reason we don't just use the directory name is because of an error in POSTING. # POSTS do not seem to POST hangul/jp characters alongside files. - filename = f"{releasedata['artist']} - {releasedata['title']} [{releasedata['media']}-{releasedata['format']}].torrent" + filename = f"{releasedata['idols[]']} - {releasedata['title']} [{releasedata['media']}-{releasedata['audioformat']}].torrent" #filename = filename.replace("\\","") try: t.write(filename) @@ -400,7 +399,7 @@ def gatherdata(directory): if log_available == True: media = 'CD' else: - media = 'WEB' + media = 'Web' # Load Dict.json for translations file = "json_data/dictionary.json" @@ -461,32 +460,38 @@ def gatherdata(directory): releasedata['submit'] = 'true' # List of accepted upload types - accepted_types = ['Album', 'Single'] + accepted_types = ['Album', 'Single', 'EP'] # 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") + releasedata['type'] = input("\n" + "_" * 100 + "\nGrouping is empty or has received an error, please enter manually (Album/Single/EP)\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") + releasedata['type'] = input("\n" + "_" * 100 + "\nGrouping tag did not return an album type, please enter manually (Album/Single/EP)\n") if releasedata['type'] not in accepted_types: continue else: break - + # SM uses numbers for it's types + if releasedata['type'] == "Album": + releasedata['type'] = 0 + elif releasedata['type'] == "Single": + releasedata['type'] = 1 + else: # EP type + releasedata['type'] = 2 releasedata['title'] = tags['ALBUM'][0] - releasedata['artist'] = unique_album_artists + releasedata['idols[]'] = unique_album_artists # If the value of album artist and artist is the same, we don't need to POST original artist. if unique_album_artists != unique_track_artists: - releasedata['artistjp'] = unique_track_artists + releasedata['artist_jp'] = unique_track_artists #re.sub removes any date separators, jps doesn't accept them - releasedata['releasedate'] = re.sub(r"[^0-9]", "", tags['DATE']) - releasedata['format'] = format + releasedata['year'] = re.sub(r"[^0-9]", "", tags['DATE']) + releasedata['audioformat'] = format releasedata['bitrate'] = bitrate releasedata['media'] = media releasedata['album_desc'] = album_description @@ -506,19 +511,19 @@ def gatherdata(directory): print(f"{releasedata['title']} < English = {en}") if en == False: input_english_title = input("\n" + "_" * 100 + "\nKorean/Japanese Detected. Please enter the romaji/english title:\n") - # Create new key called titlejp and assign the old title to it - releasedata['titlejp'] = releasedata['title'] + # Create new key called title_jp and assign the old title to it + releasedata['title_jp'] = releasedata['title'] # Replace title with the user input. releasedata['title'] = input_english_title - en = detectlanguage(releasedata['artist']) + en = detectlanguage(releasedata['idols[]']) if debug: - print(f"{releasedata['artist']} < English = {en}") + print(f"{releasedata['idols[]']} < 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 + releasedata['idols[]'] = input_english_artist return releasedata @@ -545,14 +550,17 @@ def detectlanguage(string): return en -def uploadtorrent(torrent, releasedata): - - languages = ('Japanese', 'English', 'Korean', 'Chinese', 'Vietnamese') +def uploadtorrent(torrent, imageURL, releasedata): # POST url. uploadurl = "https://sugoimusic.me/upload.php" # Dataset containing all of the information obtained from our FLAC files. data = releasedata + data['image'] = imageURL + + if not dryrun: + data['auth'] = authkey + if debug: print('_' * 100) @@ -572,7 +580,7 @@ def uploadtorrent(torrent, releasedata): # If dryrun argument has not ben passed we will POST the results to JPopSuki. if dryrun != True: JPSres = sm.retrieveContent(uploadurl, "post", data, postDataFiles) - print('\nUpload POSTED') + print('\nUpload POSTED. It may take a moment for this upload to appear on SugoiMusic.') ## TODO Filter through JPSres.text and create error handling based on responses #print(JPSres.text) @@ -645,11 +653,11 @@ 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 = debug = imageURL = None directory = args.directory additional_tags = args.tags - + if args.dryrun: dryrun = True @@ -659,6 +667,9 @@ if __name__ == "__main__": if args.freeleech: freeleech = True + if args.imageURL: + imageURL = args.imageURL + # Load login credentials from JSON and use them to create a login session. with open(f'json_data/config.json') as f: cfg = json.load(f) @@ -668,7 +679,7 @@ if __name__ == "__main__": successStr = "Enabled users" passkey = cfg['credentials']['passkey'] annouceurl = "https://tracker.sugoimusic.me:24601/"+passkey+"/announce" - print(annouceurl) + # j is an object which can be used to make requests with respect to the loginsession sm = smpy.MyLoginSession(loginUrl, loginData, loginTestUrl, successStr, debug=args.debug) # Acquire authkey @@ -686,7 +697,7 @@ if __name__ == "__main__": torrentfile = createtorrent(annouceurl, directory, folder_name, releasedata) # Upload torrent to JPopSuki - uploadtorrent(torrentfile, releasedata) + uploadtorrent(torrentfile, imageURL, releasedata) # Setting variable for watch/download folders ftp_watch_folder = cfg['ftp_prefs']['ftp_watch_folder'] @@ -694,9 +705,9 @@ if __name__ == "__main__": local_watch_folder = cfg['local_prefs']['local_watch_folder'] local_downloads_folder = cfg['local_prefs']['local_downloads_folder'] - - if cfg['ftp_prefs']['enable_ftp']: - ftp_transfer(fileSource=torrentfile, fileDestination=ftp_downloads_folder, directory=directory, folder_name=folder_name, watch_folder=ftp_watch_folder) - - if cfg['local_prefs']['add_to_watch_folder'] or cfg['local_prefs']['add_to_downloads_folder']: - localfileorganization(torrent=torrentfile, directory=directory, watch_folder=local_watch_folder, downloads_folder=local_downloads_folder) + if not dryrun: + if cfg['ftp_prefs']['enable_ftp']: + ftp_transfer(fileSource=torrentfile, fileDestination=ftp_downloads_folder, directory=directory, folder_name=folder_name, watch_folder=ftp_watch_folder) + + if cfg['local_prefs']['add_to_watch_folder'] or cfg['local_prefs']['add_to_downloads_folder']: + localfileorganization(torrent=torrentfile, directory=directory, watch_folder=local_watch_folder, downloads_folder=local_downloads_folder)