Skip to content

Commit

Permalink
ur cute
Browse files Browse the repository at this point in the history
  • Loading branch information
ohm002 authored Dec 27, 2020
1 parent 410a386 commit decb30b
Show file tree
Hide file tree
Showing 5 changed files with 403 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/Class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class BeatmapMetadata(object):
"""
docstring
"""
# def __init___(self, Title):
pass
202 changes: 202 additions & 0 deletions modules/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import os
import math
import json
import re
import shutil

class OsuMap:
def __init__ (self, general, editor, metadata, difficulty, events, timingpoints, colors, hitobjects):
self.general = general
self.editor = editor
self.metadata = metadata
self.difficulty = difficulty
self.events = events
self.timingpoints = timingpoints
self.colors = colors
self.hitobjects = hitobjects

def ParseAllBeatmapData(osufile):
# General
depth = 0
linepos = 0
DataGeneral = []
for line in osufile:
linepos += 1
if line == "[General]":
depth = linepos
elif line == "[Editor]":
# print(f"{depth+1} until {linepos-2}")
searchdepthstart = depth+1
searchdepthend = linepos-2
for i in range(searchdepthstart-1, searchdepthend-1):
DataGeneral.append(osufile[i])
break
# Editor
depth = 0
linepos = 0
DataEditor = []
for line in osufile:
linepos += 1
if line == "[Editor]":
depth = linepos
elif line == "[Metadata]":
# print(f"{depth+1} until {linepos-2}")
searchdepthstart = depth+1
searchdepthend = linepos-2
for i in range(searchdepthstart-1, searchdepthend-1):
DataEditor.append(osufile[i])
break
# Metadata
depth = 0
linepos = 0
DataMetadata = []
for line in osufile:
linepos += 1
if line == "[Metadata]":
depth = linepos
elif line == "[Difficulty]":
# print(f"{depth+1} until {linepos-2}")
searchdepthstart = depth+1
searchdepthend = linepos-2
for i in range(searchdepthstart-1, searchdepthend-1):
DataMetadata.append(osufile[i])
break # Events

# Difficulty
depth = 0
linepos = 0
DataDifficulty = []
for line in osufile:
linepos += 1
if line == "[Difficulty]":
depth = linepos
elif line == "[Events]":
# print(f"{depth+1} until {linepos-2}")
searchdepthstart = depth+1
searchdepthend = linepos-2
for i in range(searchdepthstart-1, searchdepthend-1):
DataDifficulty.append(osufile[i])
break
# Events
depth = 0
linepos = 0
DataEvents = []
for line in osufile:
linepos += 1
if line == "[Events]":
depth = linepos
elif line == "[TimingPoints]":
# print(f"{depth+1} until {linepos-2}")
searchdepthstart = depth+1
searchdepthend = linepos-2
for i in range(searchdepthstart-1, searchdepthend-1):
DataEvents.append(osufile[i])
break

# TimingPoints
depth = 0
linepos = 0
DataTimingPoints = []
for line in osufile:
linepos += 1
if line == "[TimingPoints]":
depth = linepos
elif line == "[Colours]":
# print(f"{depth+1} until {linepos-2}")
searchdepthstart = depth+1
searchdepthend = linepos-2
for i in range(searchdepthstart-1, searchdepthend-1):
DataTimingPoints.append(osufile[i])
break

# Colours
depth = 0
linepos = 0
DataColours = []
for line in osufile:
linepos += 1
if line == "[Colours]":
depth = linepos
elif line == "[HitObjects]":
# print(f"{depth+1} until {linepos-2}")
searchdepthstart = depth+1
searchdepthend = linepos-2
for i in range(searchdepthstart-1, searchdepthend-1):
DataColours.append(osufile[i])
break
# HitObjects
depth = 0
linepos = 0
DataHitObjects = []
for line in osufile:
linepos += 1
if line == "[HitObjects]":
depth = linepos
searchdepthstart = depth+1
searchdepthend = len(osufile)
for i in range(searchdepthstart-1, searchdepthend-1):
DataHitObjects.append(osufile[i])
break
osudata = OsuMap(DataGeneral, DataEditor, DataMetadata, DataDifficulty, DataEvents, DataTimingPoints, DataColours, DataHitObjects)
return osudata

def MergeAll(param):
i = 0
for osu in re.split("\n", param):
if i == 0:
MergeTwo(osu, re.split("\n", param)[1])
elif i > 2:
metadata = ParseAllBeatmapData(osu)
artist = re.split(":",metadata.metadata[2])[1]
title = re.split(":",metadata.metadata[0])[1]
mapper = re.split(":",metadata.metadata[4])[1]
MergeTwo(osu, f"{artist} - {title} ({mapper}) [Result].osu")
i += 1

def MergeTwo(osufile1, osufile2):
osufile1file = open(osufile1, encoding="utf-8").read().splitlines()
osufile2file = open(osufile2, encoding="utf-8").read().splitlines()
osufile1 = ParseAllBeatmapData(open(osufile1, encoding="utf-8").read().splitlines())
osufile2 = ParseAllBeatmapData(open(osufile2, encoding="utf-8").read().splitlines())
artist = re.split(":",osufile1.metadata[2])[1]
title = re.split(":",osufile1.metadata[0])[1]
mapper = re.split(":",osufile1.metadata[4])[1]
open(f"{artist} - {title} ({mapper}) [Result].osu", 'a').close()
resultfile = open(f"{artist} - {title} ({mapper}) [Result].osu", "w", encoding="utf-8")
towrite = ""
towrite += "[General]\n"
for line in osufile1.general:
towrite += line + "\n"
towrite += "\n[Editor]\n"
for line in osufile1.editor:
towrite += line + "\n"
towrite += "\n[Metadata]\n"
for line in osufile1.metadata:
if not line.startswith("Version"):
towrite += line + "\n"
else:
towrite += "Version:Result" + "\n"
towrite += "\n[Difficulty]\n"
for line in osufile1.difficulty:
towrite += line + "\n"
towrite += "\n[Events]\n"
for line in osufile1.events:
towrite += line + "\n"
towrite += "\n[TimingPoints]\n"
alltimingpoints = []
for line in osufile1.timingpoints:
alltimingpoints.append(line)
for line2 in osufile2.timingpoints:
alltimingpoints.append(line2)
notduplicatedline = list(dict.fromkeys(alltimingpoints))
for line in notduplicatedline:
towrite += line + "\n"
towrite += "\n[Colours]\n"
for line in osufile1.colors:
towrite += line + "\n"
towrite += "\n[HitObjects]\n"
for line in osufile1.hitobjects:
towrite += line + "\n"
for line in osufile2.hitobjects:
towrite += line + "\n"
resultfile.write(towrite)
111 changes: 111 additions & 0 deletions test.osu
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
osu file format v14

[General]
AudioFilename: audio.mp3
AudioLeadIn: 0
PreviewTime: 97097
Countdown: 0
SampleSet: Soft
StackLeniency: 0.7
Mode: 0
LetterboxInBreaks: 0
WidescreenStoryboard: 0

[Editor]
DistanceSpacing: 1
BeatDivisor: 2
GridSize: 16
TimelineZoom: 2.2

[Metadata]
Title:Utsuroi
TitleUnicode:うつろい
Artist:TrySail
ArtistUnicode:TrySail
Creator:ohm002
Version:Everlasting Nightmare
Source:マギアレコード 魔法少女まどか☆マギカ外伝
Tags:
BeatmapID:0
BeatmapSetID:-1

[Difficulty]
HPDrainRate:4
CircleSize:4
OverallDifficulty:6
ApproachRate:9.6
SliderMultiplier:1.7
SliderTickRate:1

[Events]
//Background and Video events
0,0,"Astesia.full.2752423.jpg",0,0
//Break Periods
2,42922,62261
2,64846,96588
//Storyboard Layer 0 (Background)
//Storyboard Layer 1 (Fail)
//Storyboard Layer 2 (Pass)
//Storyboard Layer 3 (Foreground)
//Storyboard Layer 4 (Overlay)
//Storyboard Sound Samples

[TimingPoints]
-979,288.461538461538,4,2,4,40,1,0
37097,-90.9090909090909,4,2,4,40,0,0


[Colours]
Combo1 : 243,208,244
Combo2 : 67,80,137
Combo3 : 255,226,159
Combo4 : 252,254,165
Combo5 : 132,141,255

[HitObjects]
68,110,37097,6,0,B|110:95|142:127|142:127|161:192|212:198,1,187.000005706787
230,112,37530,1,0,0:0:0:0:
72,202,37674,1,0,0:0:0:0:
278,263,37819,1,0,0:0:0:0:
181,24,37963,1,0,0:0:0:0:
99,283,38107,1,0,0:0:0:0:
337,126,38251,6,0,P|323:81|312:35,1,93.5000028533937
212,197,38540,1,0,0:0:0:0:
415,176,38684,2,0,P|428:131|439:85,1,93.5000028533937
300,242,38972,1,0,0:0:0:0:
405,333,39117,2,0,P|449:346|495:357,1,93.5000028533937
216,99,39405,6,0,P|131:119|130:206,1,187.000005706787
311,147,39838,2,0,P|302:101|297:54,1,93.5000028533937
197,288,40126,2,0,P|191:334|183:380,1,93.5000028533937
287,282,40415,1,0,0:0:0:0:
130,206,40559,6,0,P|83:200|37:192,1,93.5000028533937
197,288,40847,1,0,0:0:0:0:
317,153,40992,2,0,P|363:147|409:139,1,93.5000028533937
287,282,41280,1,0,0:0:0:0:
206,92,41424,2,0,P|211:45|219:0,1,93.5000028533937
372,224,41713,6,0,P|282:251|195:285,1,187.000005706787
236,169,42145,1,0,0:0:0:0:
351,384,42290,5,0,0:0:0:0:
371,306,42434,1,0,0:0:0:0:
148,205,42578,2,0,P|142:158|134:112,1,93.5000028533937
287,291,62770,5,0,0:0:0:0:
170,129,62915,1,0,0:0:0:0:
360,192,63059,5,0,0:0:0:0:
170,253,63203,1,0,0:0:0:0:
287,91,63347,5,0,0:0:0:0:
297,321,63492,1,0,0:0:0:0:
145,111,63636,5,0,0:0:0:0:
392,192,63781,1,0,0:0:0:0:
144,272,63925,5,0,0:0:0:0:
297,61,64069,1,0,0:0:0:0:
306,347,64213,5,0,0:0:0:0:
123,95,64357,1,0,0:0:0:0:
419,192,64502,5,0,0:0:0:0:
122,288,64646,1,0,0:0:0:0:
142,273,97097,5,0,0:0:0:0:
247,5,97242,1,0,0:0:0:0:
298,288,97386,1,0,0:0:0:0:
92,42,97530,1,0,0:0:0:0:
370,151,97674,1,0,0:0:0:0:
65,297,97819,1,0,0:0:0:0:
192,86,97963,1,0,0:0:0:0:
3 changes: 3 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from modules import main
main.MergeAll(r"""test.osu
test2.osu""")
Loading

0 comments on commit decb30b

Please sign in to comment.