{"action":"created","comment":{"url":"https://api.github.com/repos/Omerbu/Metador/pulls/comments/70866173","id":70866173,"diff_hunk":"@@ -0,0 +1,185 @@\n+from mutagen import File\n+from mutagen.easymp4 import EasyMP4 # used for .m4a and .mp4 files\n+from mutagen.flac import FLAC\n+from mutagen.easyid3 import EasyID3 # used for .mp3 files\n+\n+# the AUDIO_TYPES constant dict is used to refer to the mutagen subclasses according to the file format\n+#\n+# the TAGS_MAPS constant dict is used to refer to the correct tag names for each file format.\n+# currently all tags appear the same. that is because the use of EasyID3 and EasyMP4, which mimic the APEv2 format. \n+# regardless, this structure is kept for probable future use.\n+AUDIO_TYPES = {\"mp3\":EasyID3, \"mp4\":EasyMP4, \"flac\":FLAC}\n+TAGS_MAPS = {'mp3':{'artist':'artist','album':'album','title':'title','track':'tracknumber','year':'date','genre':'genre','albumartist':'albumartist'}, # mp3 tags are EasyID3\n+             'mp4':{'artist':'artist','album':'album','title':'title','track':'tracknumber','year':'date','genre':'genre','albumartist':'albumartist'}, # mp4 tags are EasyMP4\n+             'flac':{'artist':'artist','album':'album','title':'title','track':'tracknumber','year':'date','genre':'genre','albumartist':'albumartist'}}\n+\n+\n+class AudioFile:\n+    def __init__(self,filename):\n+        audiotype = File(filename).mime[0].split(\"/\")[1]    # determine the file format\n+        self.meta = AUDIO_TYPES[audiotype](filename)        # create the tags instance of the appropriate mutagen subclass\n+        self.tag_map = TAGS_MAPS[audiotype]                 # used to call the tags of any format by the same names\n+        \n+    def tag_entry(self,tags_dict):\n+        '''\n+            takes a dict of tags. notice the tags_dict keys should match tags2func keys.\n+            deletes any old tags on the file and sets the new tags.\n+        '''\n+        tag2func = {'artist':self.artist,'album':self.album,'title':self.title,'track':self.track,'year':self.year,'genre':self.genre,'albumartist':self.albumartist}\n+        self.delete_tags()\n+        for tagname in tags_dict:\n+            tag2func[tagname](tags_dict[tagname])\n+        self.meta.save()\n+    \n+    def delete_tags(self):\n+        '''\n+            remove all the tags from the file.\n+            this leaves the tags as an empty dict. \n+        '''\n+        self.meta.clear()\n+        self.meta.save()\n+    \n+    def artist(self,entry=None):\n+        '''\n+            return or set the file's artist\n+        '''\n+        if entry:\n+            entry = str(entry)\n+            self.meta[self.tag_map['artist']] = [entry.decode(\"UTF-8\")]\n+            self.meta.save()\n+        return self.meta[self.tag_map['artist']][0]\n+    \n+    def album(self,entry=None):\n+        '''\n+            return or set the file's album\n+        '''\n+        if entry:\n+            entry = str(entry)\n+            self.meta[self.tag_map['album']] = [entry.decode(\"UTF-8\")]\n+            self.meta.save()\n+        return self.meta[self.tag_map['album']][0]\n+    \n+    def title(self,entry=None):\n+        '''\n+            return or set the file's title\n+        '''\n+        if entry:\n+            entry = str(entry)\n+            self.meta[self.tag_map['title']] = [entry.decode(\"UTF-8\")]\n+            self.meta.save()\n+        return self.meta[self.tag_map['title']][0]\n+    \n+    def track(self,entry=None):\n+        '''\n+            return or set the file's track number\n+        '''\n+        if entry:\n+            entry = str(entry)\n+            self.meta[self.tag_map['track']] = [entry.decode(\"UTF-8\")]\n+            self.meta.save()\n+        return self.meta[self.tag_map['track']][0]\n+    \n+    def year(self,entry=None):\n+        '''\n+            return or set the file's year\n+        '''\n+        if entry:\n+            entry = str(entry)\n+            self.meta[self.tag_map['year']] = [entry.decode(\"UTF-8\")]\n+            self.meta.save()\n+        return self.meta[self.tag_map['year']][0]\n+    \n+    def genre(self,entry=None):\n+        '''\n+            return or set the file's genre\n+        '''\n+        if entry:\n+            entry = str(entry)\n+            self.meta[self.tag_map['genre']] = [entry.decode(\"UTF-8\")]\n+            self.meta.save()\n+        return self.meta[self.tag_map['genre']][0]\n+    \n+    def albumartist(self,entry=None):\n+        '''\n+            return or set the file's albumartist\n+        '''\n+        if entry:\n+            entry = str(entry)\n+            self.meta[self.tag_map['albumartist']] = [entry.decode(\"UTF-8\")]\n+            self.meta.save()\n+        return self.meta[self.tag_map['albumartist']][0]\n+    \n+    def tag_print(self):\n+        \"\"\"\n+            nicely prints the tags. \n+            should probably be removed when the project is finished\n+        \"\"\"\n+        print 'Artist:      ' + self.meta[self.tag_map['artist']][0]\n+        print 'Album:       ' + self.meta[self.tag_map['album']][0]\n+        print 'Title:       ' + self.meta[self.tag_map['title']][0]\n+        print 'Track:       ' + self.meta[self.tag_map['track']][0]\n+        print 'Year:        ' + self.meta[self.tag_map['year']][0]\n+        print 'Genre:       ' + self.meta[self.tag_map['genre']][0]\n+        print 'AlbumArtist: ' + self.meta[self.tag_map['albumartist']][0]\n+\n+\n+def edit_tags(filename,tags_dict):\n+    '''\n+       receive a file name to edit and the newly fetched tags.\n+       delete any old tags located on the file and save the new tags.\n+       \n+       current version works only with mp3, flac, and mp4(m4a)\n+    '''\n+    audio = AudioFile(filename)\n+    audio.tag_entry(tags_dict)\n+    return\n+\n+\n+def compare_tags(filename, tags2compare):\n+    '''\n+        should be used as a last resort for checking best match of new tags.\n+        \n+        get a dict of new tags and compare each tag to the corresponding old tag\n+        returns a float between 0 to 1 as a result, where 1 is a perfect match.\n+    '''\n+    def _compare_words(word1, word2):\n+        c = 0.0     # initiated as float for the last division","path":"tagging.py","position":146,"original_position":146,"commit_id":"a1194f75295f337fe844271dc81b5c337bb40e32","original_commit_id":"a1194f75295f337fe844271dc81b5c337bb40e32","user":{"login":"Omerbu","id":20241059,"avatar_url":"https://avatars.githubusercontent.com/u/20241059?v=3","gravatar_id":"","url":"https://api.github.com/users/Omerbu","html_url":"https://github.com/Omerbu","followers_url":"https://api.github.com/users/Omerbu/followers","following_url":"https://api.github.com/users/Omerbu/following{/other_user}","gists_url":"https://api.github.com/users/Omerbu/gists{/gist_id}","starred_url":"https://api.github.com/users/Omerbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Omerbu/subscriptions","organizations_url":"https://api.github.com/users/Omerbu/orgs","repos_url":"https://api.github.com/users/Omerbu/repos","events_url":"https://api.github.com/users/Omerbu/events{/privacy}","received_events_url":"https://api.github.com/users/Omerbu/received_events","type":"User","site_admin":false},"body":"Uninformative variable name\r\nuse variable = float(), not = 0.0","created_at":"2016-07-14T19:16:13Z","updated_at":"2016-07-14T19:16:13Z","html_url":"https://github.com/Omerbu/Metador/pull/1#discussion_r70866173","pull_request_url":"https://api.github.com/repos/Omerbu/Metador/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/Omerbu/Metador/pulls/comments/70866173"},"html":{"href":"https://github.com/Omerbu/Metador/pull/1#discussion_r70866173"},"pull_request":{"href":"https://api.github.com/repos/Omerbu/Metador/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/Omerbu/Metador/pulls/1","id":77325434,"html_url":"https://github.com/Omerbu/Metador/pull/1","diff_url":"https://github.com/Omerbu/Metador/pull/1.diff","patch_url":"https://github.com/Omerbu/Metador/pull/1.patch","issue_url":"https://api.github.com/repos/Omerbu/Metador/issues/1","number":1,"state":"open","locked":false,"title":"added the tagging module","user":{"login":"paznewman","id":20355825,"avatar_url":"https://avatars.githubusercontent.com/u/20355825?v=3","gravatar_id":"","url":"https://api.github.com/users/paznewman","html_url":"https://github.com/paznewman","followers_url":"https://api.github.com/users/paznewman/followers","following_url":"https://api.github.com/users/paznewman/following{/other_user}","gists_url":"https://api.github.com/users/paznewman/gists{/gist_id}","starred_url":"https://api.github.com/users/paznewman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paznewman/subscriptions","organizations_url":"https://api.github.com/users/paznewman/orgs","repos_url":"https://api.github.com/users/paznewman/repos","events_url":"https://api.github.com/users/paznewman/events{/privacy}","received_events_url":"https://api.github.com/users/paznewman/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-07-13T17:03:40Z","updated_at":"2016-07-14T19:16:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cf91c329b53f84a4a45736efd8b54cdf2b7ab0c6","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Omerbu/Metador/pulls/1/commits","review_comments_url":"https://api.github.com/repos/Omerbu/Metador/pulls/1/comments","review_comment_url":"https://api.github.com/repos/Omerbu/Metador/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Omerbu/Metador/issues/1/comments","statuses_url":"https://api.github.com/repos/Omerbu/Metador/statuses/a1194f75295f337fe844271dc81b5c337bb40e32","head":{"label":"paznewman:master","ref":"master","sha":"a1194f75295f337fe844271dc81b5c337bb40e32","user":{"login":"paznewman","id":20355825,"avatar_url":"https://avatars.githubusercontent.com/u/20355825?v=3","gravatar_id":"","url":"https://api.github.com/users/paznewman","html_url":"https://github.com/paznewman","followers_url":"https://api.github.com/users/paznewman/followers","following_url":"https://api.github.com/users/paznewman/following{/other_user}","gists_url":"https://api.github.com/users/paznewman/gists{/gist_id}","starred_url":"https://api.github.com/users/paznewman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paznewman/subscriptions","organizations_url":"https://api.github.com/users/paznewman/orgs","repos_url":"https://api.github.com/users/paznewman/repos","events_url":"https://api.github.com/users/paznewman/events{/privacy}","received_events_url":"https://api.github.com/users/paznewman/received_events","type":"User","site_admin":false},"repo":{"id":62886491,"name":"Metador","full_name":"paznewman/Metador","owner":{"login":"paznewman","id":20355825,"avatar_url":"https://avatars.githubusercontent.com/u/20355825?v=3","gravatar_id":"","url":"https://api.github.com/users/paznewman","html_url":"https://github.com/paznewman","followers_url":"https://api.github.com/users/paznewman/followers","following_url":"https://api.github.com/users/paznewman/following{/other_user}","gists_url":"https://api.github.com/users/paznewman/gists{/gist_id}","starred_url":"https://api.github.com/users/paznewman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paznewman/subscriptions","organizations_url":"https://api.github.com/users/paznewman/orgs","repos_url":"https://api.github.com/users/paznewman/repos","events_url":"https://api.github.com/users/paznewman/events{/privacy}","received_events_url":"https://api.github.com/users/paznewman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/paznewman/Metador","description":null,"fork":true,"url":"https://api.github.com/repos/paznewman/Metador","forks_url":"https://api.github.com/repos/paznewman/Metador/forks","keys_url":"https://api.github.com/repos/paznewman/Metador/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paznewman/Metador/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paznewman/Metador/teams","hooks_url":"https://api.github.com/repos/paznewman/Metador/hooks","issue_events_url":"https://api.github.com/repos/paznewman/Metador/issues/events{/number}","events_url":"https://api.github.com/repos/paznewman/Metador/events","assignees_url":"https://api.github.com/repos/paznewman/Metador/assignees{/user}","branches_url":"https://api.github.com/repos/paznewman/Metador/branches{/branch}","tags_url":"https://api.github.com/repos/paznewman/Metador/tags","blobs_url":"https://api.github.com/repos/paznewman/Metador/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paznewman/Metador/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paznewman/Metador/git/refs{/sha}","trees_url":"https://api.github.com/repos/paznewman/Metador/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paznewman/Metador/statuses/{sha}","languages_url":"https://api.github.com/repos/paznewman/Metador/languages","stargazers_url":"https://api.github.com/repos/paznewman/Metador/stargazers","contributors_url":"https://api.github.com/repos/paznewman/Metador/contributors","subscribers_url":"https://api.github.com/repos/paznewman/Metador/subscribers","subscription_url":"https://api.github.com/repos/paznewman/Metador/subscription","commits_url":"https://api.github.com/repos/paznewman/Metador/commits{/sha}","git_commits_url":"https://api.github.com/repos/paznewman/Metador/git/commits{/sha}","comments_url":"https://api.github.com/repos/paznewman/Metador/comments{/number}","issue_comment_url":"https://api.github.com/repos/paznewman/Metador/issues/comments{/number}","contents_url":"https://api.github.com/repos/paznewman/Metador/contents/{+path}","compare_url":"https://api.github.com/repos/paznewman/Metador/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paznewman/Metador/merges","archive_url":"https://api.github.com/repos/paznewman/Metador/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paznewman/Metador/downloads","issues_url":"https://api.github.com/repos/paznewman/Metador/issues{/number}","pulls_url":"https://api.github.com/repos/paznewman/Metador/pulls{/number}","milestones_url":"https://api.github.com/repos/paznewman/Metador/milestones{/number}","notifications_url":"https://api.github.com/repos/paznewman/Metador/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paznewman/Metador/labels{/name}","releases_url":"https://api.github.com/repos/paznewman/Metador/releases{/id}","deployments_url":"https://api.github.com/repos/paznewman/Metador/deployments","created_at":"2016-07-08T12:18:26Z","updated_at":"2016-07-08T12:18:28Z","pushed_at":"2016-07-13T17:03:37Z","git_url":"git://github.com/paznewman/Metador.git","ssh_url":"git@github.com:paznewman/Metador.git","clone_url":"https://github.com/paznewman/Metador.git","svn_url":"https://github.com/paznewman/Metador","homepage":null,"size":1075,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Omerbu:master","ref":"master","sha":"390b4563d88fbfa8e997d346421de333e4fc3c2a","user":{"login":"Omerbu","id":20241059,"avatar_url":"https://avatars.githubusercontent.com/u/20241059?v=3","gravatar_id":"","url":"https://api.github.com/users/Omerbu","html_url":"https://github.com/Omerbu","followers_url":"https://api.github.com/users/Omerbu/followers","following_url":"https://api.github.com/users/Omerbu/following{/other_user}","gists_url":"https://api.github.com/users/Omerbu/gists{/gist_id}","starred_url":"https://api.github.com/users/Omerbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Omerbu/subscriptions","organizations_url":"https://api.github.com/users/Omerbu/orgs","repos_url":"https://api.github.com/users/Omerbu/repos","events_url":"https://api.github.com/users/Omerbu/events{/privacy}","received_events_url":"https://api.github.com/users/Omerbu/received_events","type":"User","site_admin":false},"repo":{"id":62384573,"name":"Metador","full_name":"Omerbu/Metador","owner":{"login":"Omerbu","id":20241059,"avatar_url":"https://avatars.githubusercontent.com/u/20241059?v=3","gravatar_id":"","url":"https://api.github.com/users/Omerbu","html_url":"https://github.com/Omerbu","followers_url":"https://api.github.com/users/Omerbu/followers","following_url":"https://api.github.com/users/Omerbu/following{/other_user}","gists_url":"https://api.github.com/users/Omerbu/gists{/gist_id}","starred_url":"https://api.github.com/users/Omerbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Omerbu/subscriptions","organizations_url":"https://api.github.com/users/Omerbu/orgs","repos_url":"https://api.github.com/users/Omerbu/repos","events_url":"https://api.github.com/users/Omerbu/events{/privacy}","received_events_url":"https://api.github.com/users/Omerbu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Omerbu/Metador","description":null,"fork":false,"url":"https://api.github.com/repos/Omerbu/Metador","forks_url":"https://api.github.com/repos/Omerbu/Metador/forks","keys_url":"https://api.github.com/repos/Omerbu/Metador/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Omerbu/Metador/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Omerbu/Metador/teams","hooks_url":"https://api.github.com/repos/Omerbu/Metador/hooks","issue_events_url":"https://api.github.com/repos/Omerbu/Metador/issues/events{/number}","events_url":"https://api.github.com/repos/Omerbu/Metador/events","assignees_url":"https://api.github.com/repos/Omerbu/Metador/assignees{/user}","branches_url":"https://api.github.com/repos/Omerbu/Metador/branches{/branch}","tags_url":"https://api.github.com/repos/Omerbu/Metador/tags","blobs_url":"https://api.github.com/repos/Omerbu/Metador/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Omerbu/Metador/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Omerbu/Metador/git/refs{/sha}","trees_url":"https://api.github.com/repos/Omerbu/Metador/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Omerbu/Metador/statuses/{sha}","languages_url":"https://api.github.com/repos/Omerbu/Metador/languages","stargazers_url":"https://api.github.com/repos/Omerbu/Metador/stargazers","contributors_url":"https://api.github.com/repos/Omerbu/Metador/contributors","subscribers_url":"https://api.github.com/repos/Omerbu/Metador/subscribers","subscription_url":"https://api.github.com/repos/Omerbu/Metador/subscription","commits_url":"https://api.github.com/repos/Omerbu/Metador/commits{/sha}","git_commits_url":"https://api.github.com/repos/Omerbu/Metador/git/commits{/sha}","comments_url":"https://api.github.com/repos/Omerbu/Metador/comments{/number}","issue_comment_url":"https://api.github.com/repos/Omerbu/Metador/issues/comments{/number}","contents_url":"https://api.github.com/repos/Omerbu/Metador/contents/{+path}","compare_url":"https://api.github.com/repos/Omerbu/Metador/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Omerbu/Metador/merges","archive_url":"https://api.github.com/repos/Omerbu/Metador/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Omerbu/Metador/downloads","issues_url":"https://api.github.com/repos/Omerbu/Metador/issues{/number}","pulls_url":"https://api.github.com/repos/Omerbu/Metador/pulls{/number}","milestones_url":"https://api.github.com/repos/Omerbu/Metador/milestones{/number}","notifications_url":"https://api.github.com/repos/Omerbu/Metador/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Omerbu/Metador/labels{/name}","releases_url":"https://api.github.com/repos/Omerbu/Metador/releases{/id}","deployments_url":"https://api.github.com/repos/Omerbu/Metador/deployments","created_at":"2016-07-01T10:14:15Z","updated_at":"2016-07-02T17:10:33Z","pushed_at":"2016-07-13T17:03:40Z","git_url":"git://github.com/Omerbu/Metador.git","ssh_url":"git@github.com:Omerbu/Metador.git","clone_url":"https://github.com/Omerbu/Metador.git","svn_url":"https://github.com/Omerbu/Metador","homepage":null,"size":1057,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Omerbu/Metador/pulls/1"},"html":{"href":"https://github.com/Omerbu/Metador/pull/1"},"issue":{"href":"https://api.github.com/repos/Omerbu/Metador/issues/1"},"comments":{"href":"https://api.github.com/repos/Omerbu/Metador/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/Omerbu/Metador/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/Omerbu/Metador/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Omerbu/Metador/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/Omerbu/Metador/statuses/a1194f75295f337fe844271dc81b5c337bb40e32"}}}}
{"actor":{"display_login":"Omerbu"}}