-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for "date added" and "favourite" fields #6
Open
sterling-tenn
wants to merge
3
commits into
Stampede:master
Choose a base branch
from
sterling-tenn:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,14 +28,17 @@ def determine_userID(nd_p): | |
conn.close() | ||
return users[0][0] | ||
|
||
def update_playstats(d1, id, playcount, playdate, rating=0): | ||
def update_playstats(d1, id, playcount, playdate, dateadded, rating=0, loved=0): | ||
d1.setdefault(id, {}) | ||
d1[id].setdefault('play count', 0) | ||
d1[id].setdefault('play date', datetime.datetime.fromordinal(1)) | ||
d1[id].setdefault('date added', datetime.datetime.fromordinal(1)) | ||
d1[id]['play count'] += playcount | ||
d1[id]['rating'] = rating | ||
d1[id]['loved'] = loved | ||
|
||
if playdate > d1[id]['play date']: d1[id].update({'play date': playdate}) | ||
if dateadded > d1[id]['date added']: d1[id].update({'date added': dateadded}) | ||
|
||
def generate_annotation_id(): # random hex number 32 characters long | ||
character_pool = string.hexdigits[:16] | ||
|
@@ -53,8 +56,9 @@ def write_to_annotation(dictionary_with_stats, entry_type): | |
play_count = this_entry['play count'] | ||
play_date = this_entry['play date'].strftime('%Y-%m-%d %H:%M:%S') # YYYY-MM-DD 24:mm:ss | ||
rating = this_entry['rating'] | ||
loved = this_entry['loved'] | ||
|
||
annotation_entries.append((generate_annotation_id(), userID, item_id, entry_type, play_count, play_date, rating, 0, None)) | ||
annotation_entries.append((generate_annotation_id(), userID, item_id, entry_type, play_count, play_date, rating, loved, None)) | ||
|
||
conn = sqlite3.connect(nddb_path) | ||
cur = conn.cursor() | ||
|
@@ -64,6 +68,16 @@ def write_to_annotation(dictionary_with_stats, entry_type): | |
# cur.executemany('INSERT INTO consumers VALUES (?,?,?,?)', purchases) | ||
# cur.execute("INSERT INTO consumers VALUES (1,'John Doe','[email protected]','A')") | ||
|
||
def update_created_at_fields(dictionary_with_stats): | ||
conn = sqlite3.connect(nddb_path) | ||
cur = conn.cursor() | ||
|
||
for item_id in dictionary_with_stats: | ||
this_entry = dictionary_with_stats[item_id] | ||
cur.execute('UPDATE media_file SET created_at = ? WHERE id = ?', (this_entry['date added'], item_id)) | ||
conn.commit() | ||
conn.close() | ||
|
||
_ = None | ||
while _ != 'proceed': | ||
print() | ||
|
@@ -134,6 +148,10 @@ def write_to_annotation(dictionary_with_stats, entry_type): | |
it_song_ID = int(it_song_entry.find('key', string='Track ID').next_sibling.text) | ||
songID_correlation.update({it_song_ID: song_id}) | ||
|
||
loved = it_song_entry.find('key', string='Loved') | ||
if(loved != None): loved = 1 | ||
else: loved = 0 | ||
|
||
try: # get rating, play count & date from Itunes | ||
song_rating = int(it_song_entry.find('key', string='Rating').next_sibling.text) | ||
song_rating = int(song_rating / 20) | ||
|
@@ -143,13 +161,13 @@ def write_to_annotation(dictionary_with_stats, entry_type): | |
play_count = int(it_song_entry.find('key', string='Play Count').next_sibling.text) | ||
last_played = it_song_entry.find('key', string='Play Date UTC').next_sibling.text[:-1] # slice off the trailing 'Z' | ||
last_played = datetime.datetime.strptime(last_played, '%Y-%m-%dT%H:%M:%S') # convert from string to datetime object. Example string: '2020-01-19T02:24:14Z' | ||
date_added = it_song_entry.find('key', string='Date Added').next_sibling.text[:-1] | ||
date_added = datetime.datetime.strptime(date_added, '%Y-%m-%dT%H:%M:%S') | ||
except AttributeError: continue | ||
|
||
update_playstats(artists, artist_id, play_count, last_played) | ||
update_playstats(albums, album_id, play_count, last_played) | ||
update_playstats(files, song_id, play_count, last_played, rating=song_rating) | ||
|
||
|
||
update_playstats(artists, artist_id, play_count, last_played, date_added) | ||
update_playstats(albums, album_id, play_count, last_played, date_added) | ||
update_playstats(files, song_id, play_count, last_played, date_added, rating=song_rating, loved=loved) | ||
|
||
conn.close() | ||
|
||
|
@@ -161,6 +179,8 @@ def write_to_annotation(dictionary_with_stats, entry_type): | |
write_to_annotation(albums, 'album') | ||
print('Album records saved to database.') | ||
|
||
update_created_at_fields(files) | ||
|
||
with open('IT_file_correlations.py', 'w') as f: | ||
f.write('# Following python dictionary correlates the itunes integer ID to the Navidrome file ID for each song.\n') | ||
f.write('# {ITUNES ID: ND ID} is the format. \n\n') | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to use the earliest date that is defined. All my files had the date I initially imported the files from the disc.