parent
9b7adbd033
commit
6a2dfba472
1 changed files with 13 additions and 8 deletions
@ -1,41 +1,46 @@ |
|||||||
#! python3 |
#! python3 |
||||||
import pyperclip |
import pyperclip |
||||||
|
|
||||||
|
|
||||||
def get_seconds(t): |
def get_seconds(t): |
||||||
""" Translates duration to seconds """ |
""" Translates duration to seconds """ |
||||||
return int(t[: t.find(":")]) * 60 + int(t[t.find(":") + 1 :]) |
return int(t[: t.find(":")]) * 60 + int(t[t.find(":") + 1 :]) |
||||||
|
|
||||||
|
|
||||||
# Get data from clipboard |
# Get data from clipboard |
||||||
rows = pyperclip.paste().split('\n') |
rows = pyperclip.paste().split("\n") |
||||||
|
|
||||||
# Dict to fill with info |
# Dict to fill with info |
||||||
d = {} |
d = {} |
||||||
|
|
||||||
# Get data into dict |
# Get data into dict |
||||||
for row in rows: |
for row in rows: |
||||||
l = row.split('\t') |
l = row.split("\t") |
||||||
if len(l) < 3: # Filter out empty rows |
if len(l) < 3: # Filter out empty rows |
||||||
continue |
continue |
||||||
title = l[2] |
title = l[2] |
||||||
duration = l[1] |
duration = l[1] |
||||||
if title in d: |
if title in d: |
||||||
d[title] = {'duration': d[title]['duration'] + get_seconds(duration), 'artist': l[3]} |
d[title] = { |
||||||
|
"duration": d[title]["duration"] + get_seconds(duration), |
||||||
|
"artist": l[3], |
||||||
|
} |
||||||
else: |
else: |
||||||
d[title] = {'duration': get_seconds(duration), 'artist': l[3]} |
d[title] = {"duration": get_seconds(duration), "artist": l[3]} |
||||||
|
|
||||||
# Write to 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(): |
for key, value in d.items(): |
||||||
minutes = str(int(value['duration'] / 60)) |
minutes = str(int(value["duration"] / 60)) |
||||||
seconds = str(int(value['duration'] % 60)) |
seconds = str(int(value["duration"] % 60)) |
||||||
if len(seconds) == 1: |
if len(seconds) == 1: |
||||||
seconds = seconds + str(0) |
seconds = seconds + str(0) |
||||||
f.write( |
f.write( |
||||||
"{title}\t{artist}\t{duration}\n".format( |
"{title}\t{artist}\t{duration}\n".format( |
||||||
title=key, |
title=key, |
||||||
artist=value['artist'], |
artist=value["artist"], |
||||||
duration=minutes + ":" + seconds, |
duration=minutes + ":" + seconds, |
||||||
) |
) |
||||||
) |
) |
||||||
Loading…
Reference in new issue