parent
fe265be3c0
commit
28cd6389c1
1 changed files with 28 additions and 23 deletions
@ -1,36 +1,41 @@ |
|||||||
#! python3 |
#! python3 |
||||||
import pandas as pd |
import pyperclip |
||||||
|
|
||||||
# Import clipboard to dataframe |
def get_seconds(t): |
||||||
## There's something off with the format when copied frmo Hindenburg, |
""" Translates duration to seconds """ |
||||||
## therefore the extra column |
return int(t[: t.find(":")]) * 60 + int(t[t.find(":") + 1 :]) |
||||||
df = pd.read_clipboard( |
|
||||||
sep="\t", names=["offset", "duration", "title", "artist", "album", ""] |
|
||||||
) |
|
||||||
df.drop(["album", "", "offset"], axis=1, inplace=True) |
|
||||||
|
|
||||||
# Translate duration for each clip to seconds |
# Get data from clipboard |
||||||
df["seconds"] = df.duration.apply( |
rows = pyperclip.paste().split('\n') |
||||||
lambda x: int(x[: x.find(":")]) * 60 + int(x[x.find(":") + 1 :]) |
|
||||||
) |
# Dict to fill with info |
||||||
|
d = {} |
||||||
|
|
||||||
|
# Get data into dict |
||||||
|
for row in rows: |
||||||
|
l = row.split('\t') |
||||||
|
if len(l) < 3: # Filter out empty rows |
||||||
|
continue |
||||||
|
title = l[2] |
||||||
|
duration = l[1] |
||||||
|
if title in d: |
||||||
|
d[title] = {'duration': d[title]['duration'] + get_seconds(duration), 'artist': l[3]} |
||||||
|
else: |
||||||
|
d[title] = {'duration': get_seconds(duration), 'artist': l[3]} |
||||||
|
|
||||||
# Open and prepare file |
# Write to file |
||||||
with open("Music Report.csv", "a+") as f: |
with open("Music Report.csv", "a+") as f: |
||||||
f.truncate(0) |
f.truncate(0) |
||||||
f.write("Title\tArtist\tDuration\n") |
f.write("Title\tArtist\tDuration\n") |
||||||
|
for key, value in d.items(): |
||||||
# Sum the duration for all clips with the same title |
minutes = str(int(value['duration'] / 60)) |
||||||
for title in df.groupby("title"): |
seconds = str(int(value['duration'] % 60)) |
||||||
minutes = str(int(title[1].seconds.sum() / 60)) |
|
||||||
seconds = str(int(title[1].seconds.sum() % 60)) |
|
||||||
if len(seconds) == 1: |
if len(seconds) == 1: |
||||||
seconds = seconds + str(0) |
seconds = seconds + str(0) |
||||||
|
|
||||||
# Write to file |
|
||||||
f.write( |
f.write( |
||||||
"{title}\t{artist}\t{duration}\n".format( |
"{title}\t{artist}\t{duration}\n".format( |
||||||
title=title[0], |
title=key, |
||||||
artist=title[1].artist.tolist()[0], |
artist=value['artist'], |
||||||
duration=minutes + ":" + seconds, |
duration=minutes + ":" + seconds, |
||||||
) |
) |
||||||
) |
) |
||||||
Loading…
Reference in new issue