{"action":"created","comment":{"url":"https://api.github.com/repos/kupiakos/LapisMirror/pulls/comments/75014712","id":75014712,"diff_hunk":"@@ -0,0 +1,113 @@\n+# The MIT License (MIT)\n+\n+# Copyright (c) 2016 HeyItsShuga\n+\n+# Permission is hereby granted, free of charge, to any person obtaining a copy\n+# of this software and associated documentation files (the \"Software\"), to deal\n+# in the Software without restriction, including without limitation the rights\n+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+# copies of the Software, and to permit persons to whom the Software is\n+# furnished to do so, subject to the following conditions:\n+\n+# The above copyright notice and this permission notice shall be included in\n+# all copies or substantial portions of the Software.\n+\n+# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+# THE SOFTWARE.\n+\n+import logging\n+import re\n+import html\n+from urllib.parse import urlsplit\n+import traceback\n+\n+import json\n+import requests\n+import mimeparse\n+import praw\n+\n+\n+class e621Plugin:\n+    \"\"\"\n+    Mirrors e621 images.\n+    Created by /u/HeyItsShuga\n+\n+    \"\"\"\n+\n+    def __init__(self, useragent: str, **options):\n+        \"\"\"Initialize the e621 importer.\n+\n+        :param useragent: The useragent to use for querying e621.\n+        :param options: Other options in the configuration. Ignored.\n+        \"\"\"\n+        self.log = logging.getLogger('lapis.e621')\n+        self.headers = {'User-Agent': useragent}\n+        self.regex = re.compile(r'^https?://(((?:www\\.)?(?:static1\\.)?((e621)|(e926))\\.net/(data/.+/(?P<cdn_id>\\w+))?(post/show/(?P<id>\\d+)/?)?.*))$')\n+\n+    def import_submission(self, submission: praw.objects.Submission) -> dict:\n+        \"\"\"Import a submission from e621.\n+\n+        This function will define the following values in its return data:\n+        - author: simply \"an anonymous user on e621\"\n+        - source: The url of the submission\n+        - importer_display/header\n+        - import_urls\n+\n+        After we define that, we need to get the image. Since e621 has an API,\n+        we use that to try to get the image if the image is a non-CDN URL. If it is\n+        a CDN, we take the image directory and upload *that* to Imgur.\n+\n+        image_url is the variable of the image to upload.\n+\n+        :param submission: A reddit submission to parse.\n+        \"\"\"\n+        print('e621 PLUGIN DEBUG - Initiated plugin.')\n+        try:\n+            url = html.unescape(submission.url)\n+            match = self.regex.match(submission.url)\n+            if not match:\n+                print('e621 PLUGIN DEBUG - Regex failed') ####################\n+                return None\n+            print('e621 PLUGIN DEBUG - Regex suceeded') ####################\n+            r = requests.head(url, headers=self.headers)\n+            mime_text = r.headers.get('Content-Type')\n+            mime = mimeparse.parse_mime_type(mime_text)\n+            if mime[0] == 'image':\n+                self.log.debug('Is CDN, no API needed')\n+                data = {'author': 'a e926 user',\n+                        'source': url,\n+                        'importer_display':\n+                            {'header': 'Mirrored e926 image:\\n\\n'}}\n+                image_url = url\n+            else:\n+                self.log.debug('Not CDN, will use API')\n+                match = self.regex.match(submission.url)\n+                match_data = match.groupdict()\n+                id = match_data.get('id') # Get ID out of regex.\n+                urlJ = 'http://e926.net/post/show.json?id=' + id\n+                self.log.debug('Will use API endpoint at ' + urlJ)\n+                callapi = requests.get(urlJ) # These next lines uses the API...\n+                json = callapi.json() # ...endpoint and gets the direct image URL to upload.\n+                img = (json['file_url'])","path":"plugins/e621.py","position":96,"original_position":96,"commit_id":"98dd9fb2afdf269035c7a2ce03be555dee4b1684","original_commit_id":"98dd9fb2afdf269035c7a2ce03be555dee4b1684","user":{"login":"Shugabuga","id":10801851,"avatar_url":"https://avatars.githubusercontent.com/u/10801851?v=3","gravatar_id":"","url":"https://api.github.com/users/Shugabuga","html_url":"https://github.com/Shugabuga","followers_url":"https://api.github.com/users/Shugabuga/followers","following_url":"https://api.github.com/users/Shugabuga/following{/other_user}","gists_url":"https://api.github.com/users/Shugabuga/gists{/gist_id}","starred_url":"https://api.github.com/users/Shugabuga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shugabuga/subscriptions","organizations_url":"https://api.github.com/users/Shugabuga/orgs","repos_url":"https://api.github.com/users/Shugabuga/repos","events_url":"https://api.github.com/users/Shugabuga/events{/privacy}","received_events_url":"https://api.github.com/users/Shugabuga/received_events","type":"User","site_admin":false},"body":"I have no idea, but I fixed it. Will comment later.","created_at":"2016-08-16T20:36:44Z","updated_at":"2016-08-16T20:36:44Z","html_url":"https://github.com/kupiakos/LapisMirror/pull/29#discussion_r75014712","pull_request_url":"https://api.github.com/repos/kupiakos/LapisMirror/pulls/29","_links":{"self":{"href":"https://api.github.com/repos/kupiakos/LapisMirror/pulls/comments/75014712"},"html":{"href":"https://github.com/kupiakos/LapisMirror/pull/29#discussion_r75014712"},"pull_request":{"href":"https://api.github.com/repos/kupiakos/LapisMirror/pulls/29"}}},"pull_request":{"url":"https://api.github.com/repos/kupiakos/LapisMirror/pulls/29","id":81373544,"html_url":"https://github.com/kupiakos/LapisMirror/pull/29","diff_url":"https://github.com/kupiakos/LapisMirror/pull/29.diff","patch_url":"https://github.com/kupiakos/LapisMirror/pull/29.patch","issue_url":"https://api.github.com/repos/kupiakos/LapisMirror/issues/29","number":29,"state":"open","locked":false,"title":"Plugin: e621 / e926","user":{"login":"Shugabuga","id":10801851,"avatar_url":"https://avatars.githubusercontent.com/u/10801851?v=3","gravatar_id":"","url":"https://api.github.com/users/Shugabuga","html_url":"https://github.com/Shugabuga","followers_url":"https://api.github.com/users/Shugabuga/followers","following_url":"https://api.github.com/users/Shugabuga/following{/other_user}","gists_url":"https://api.github.com/users/Shugabuga/gists{/gist_id}","starred_url":"https://api.github.com/users/Shugabuga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shugabuga/subscriptions","organizations_url":"https://api.github.com/users/Shugabuga/orgs","repos_url":"https://api.github.com/users/Shugabuga/repos","events_url":"https://api.github.com/users/Shugabuga/events{/privacy}","received_events_url":"https://api.github.com/users/Shugabuga/received_events","type":"User","site_admin":false},"body":"This pull requests resolves issue #20 by adding a plugin to add support for e621 and e926, which are both booru-based sites for furries. It does the following:\r\n\r\n- Mirrors all images from e621 and e926 and its CDN\r\n\r\n- Retrieves the uploader for non-CDN e621/e926 images\r\n\r\n- Uses the e621/e926 API for uploading non-CDN links and a direct link for CDN links.\r\n\r\n- Affects https://e621.net and https://e926.net (and their CDN and WWW subdomians)\r\n\r\n\r\nThis plugin is active on /u/TheMirrorPool and can be seen in action [here](https://www.reddit.com/r/heyitsshugatest/comments/4xeido/e926_api_mirror_thingy/d6eqyqs).","created_at":"2016-08-15T20:53:27Z","updated_at":"2016-08-16T20:36:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1b8390951e9ac46d38ef0762c0d962e48c4ac080","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/kupiakos/LapisMirror/pulls/29/commits","review_comments_url":"https://api.github.com/repos/kupiakos/LapisMirror/pulls/29/comments","review_comment_url":"https://api.github.com/repos/kupiakos/LapisMirror/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kupiakos/LapisMirror/issues/29/comments","statuses_url":"https://api.github.com/repos/kupiakos/LapisMirror/statuses/98dd9fb2afdf269035c7a2ce03be555dee4b1684","head":{"label":"Shugabuga:plugin-e621","ref":"plugin-e621","sha":"98dd9fb2afdf269035c7a2ce03be555dee4b1684","user":{"login":"Shugabuga","id":10801851,"avatar_url":"https://avatars.githubusercontent.com/u/10801851?v=3","gravatar_id":"","url":"https://api.github.com/users/Shugabuga","html_url":"https://github.com/Shugabuga","followers_url":"https://api.github.com/users/Shugabuga/followers","following_url":"https://api.github.com/users/Shugabuga/following{/other_user}","gists_url":"https://api.github.com/users/Shugabuga/gists{/gist_id}","starred_url":"https://api.github.com/users/Shugabuga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shugabuga/subscriptions","organizations_url":"https://api.github.com/users/Shugabuga/orgs","repos_url":"https://api.github.com/users/Shugabuga/repos","events_url":"https://api.github.com/users/Shugabuga/events{/privacy}","received_events_url":"https://api.github.com/users/Shugabuga/received_events","type":"User","site_admin":false},"repo":{"id":62420561,"name":"LapisMirror","full_name":"Shugabuga/LapisMirror","owner":{"login":"Shugabuga","id":10801851,"avatar_url":"https://avatars.githubusercontent.com/u/10801851?v=3","gravatar_id":"","url":"https://api.github.com/users/Shugabuga","html_url":"https://github.com/Shugabuga","followers_url":"https://api.github.com/users/Shugabuga/followers","following_url":"https://api.github.com/users/Shugabuga/following{/other_user}","gists_url":"https://api.github.com/users/Shugabuga/gists{/gist_id}","starred_url":"https://api.github.com/users/Shugabuga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shugabuga/subscriptions","organizations_url":"https://api.github.com/users/Shugabuga/orgs","repos_url":"https://api.github.com/users/Shugabuga/repos","events_url":"https://api.github.com/users/Shugabuga/events{/privacy}","received_events_url":"https://api.github.com/users/Shugabuga/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Shugabuga/LapisMirror","description":"Mirrors images from various sites, and exports them to mirrors like imgur. Plugin-based.","fork":true,"url":"https://api.github.com/repos/Shugabuga/LapisMirror","forks_url":"https://api.github.com/repos/Shugabuga/LapisMirror/forks","keys_url":"https://api.github.com/repos/Shugabuga/LapisMirror/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Shugabuga/LapisMirror/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Shugabuga/LapisMirror/teams","hooks_url":"https://api.github.com/repos/Shugabuga/LapisMirror/hooks","issue_events_url":"https://api.github.com/repos/Shugabuga/LapisMirror/issues/events{/number}","events_url":"https://api.github.com/repos/Shugabuga/LapisMirror/events","assignees_url":"https://api.github.com/repos/Shugabuga/LapisMirror/assignees{/user}","branches_url":"https://api.github.com/repos/Shugabuga/LapisMirror/branches{/branch}","tags_url":"https://api.github.com/repos/Shugabuga/LapisMirror/tags","blobs_url":"https://api.github.com/repos/Shugabuga/LapisMirror/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Shugabuga/LapisMirror/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Shugabuga/LapisMirror/git/refs{/sha}","trees_url":"https://api.github.com/repos/Shugabuga/LapisMirror/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Shugabuga/LapisMirror/statuses/{sha}","languages_url":"https://api.github.com/repos/Shugabuga/LapisMirror/languages","stargazers_url":"https://api.github.com/repos/Shugabuga/LapisMirror/stargazers","contributors_url":"https://api.github.com/repos/Shugabuga/LapisMirror/contributors","subscribers_url":"https://api.github.com/repos/Shugabuga/LapisMirror/subscribers","subscription_url":"https://api.github.com/repos/Shugabuga/LapisMirror/subscription","commits_url":"https://api.github.com/repos/Shugabuga/LapisMirror/commits{/sha}","git_commits_url":"https://api.github.com/repos/Shugabuga/LapisMirror/git/commits{/sha}","comments_url":"https://api.github.com/repos/Shugabuga/LapisMirror/comments{/number}","issue_comment_url":"https://api.github.com/repos/Shugabuga/LapisMirror/issues/comments{/number}","contents_url":"https://api.github.com/repos/Shugabuga/LapisMirror/contents/{+path}","compare_url":"https://api.github.com/repos/Shugabuga/LapisMirror/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Shugabuga/LapisMirror/merges","archive_url":"https://api.github.com/repos/Shugabuga/LapisMirror/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Shugabuga/LapisMirror/downloads","issues_url":"https://api.github.com/repos/Shugabuga/LapisMirror/issues{/number}","pulls_url":"https://api.github.com/repos/Shugabuga/LapisMirror/pulls{/number}","milestones_url":"https://api.github.com/repos/Shugabuga/LapisMirror/milestones{/number}","notifications_url":"https://api.github.com/repos/Shugabuga/LapisMirror/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Shugabuga/LapisMirror/labels{/name}","releases_url":"https://api.github.com/repos/Shugabuga/LapisMirror/releases{/id}","deployments_url":"https://api.github.com/repos/Shugabuga/LapisMirror/deployments","created_at":"2016-07-01T21:26:08Z","updated_at":"2016-07-01T21:26:09Z","pushed_at":"2016-08-15T20:25:41Z","git_url":"git://github.com/Shugabuga/LapisMirror.git","ssh_url":"git@github.com:Shugabuga/LapisMirror.git","clone_url":"https://github.com/Shugabuga/LapisMirror.git","svn_url":"https://github.com/Shugabuga/LapisMirror","homepage":"","size":96,"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":"kupiakos:master","ref":"master","sha":"64ad7529864e3c8a4a26db6638eac76f1200e920","user":{"login":"kupiakos","id":3309728,"avatar_url":"https://avatars.githubusercontent.com/u/3309728?v=3","gravatar_id":"","url":"https://api.github.com/users/kupiakos","html_url":"https://github.com/kupiakos","followers_url":"https://api.github.com/users/kupiakos/followers","following_url":"https://api.github.com/users/kupiakos/following{/other_user}","gists_url":"https://api.github.com/users/kupiakos/gists{/gist_id}","starred_url":"https://api.github.com/users/kupiakos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kupiakos/subscriptions","organizations_url":"https://api.github.com/users/kupiakos/orgs","repos_url":"https://api.github.com/users/kupiakos/repos","events_url":"https://api.github.com/users/kupiakos/events{/privacy}","received_events_url":"https://api.github.com/users/kupiakos/received_events","type":"User","site_admin":false},"repo":{"id":37109070,"name":"LapisMirror","full_name":"kupiakos/LapisMirror","owner":{"login":"kupiakos","id":3309728,"avatar_url":"https://avatars.githubusercontent.com/u/3309728?v=3","gravatar_id":"","url":"https://api.github.com/users/kupiakos","html_url":"https://github.com/kupiakos","followers_url":"https://api.github.com/users/kupiakos/followers","following_url":"https://api.github.com/users/kupiakos/following{/other_user}","gists_url":"https://api.github.com/users/kupiakos/gists{/gist_id}","starred_url":"https://api.github.com/users/kupiakos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kupiakos/subscriptions","organizations_url":"https://api.github.com/users/kupiakos/orgs","repos_url":"https://api.github.com/users/kupiakos/repos","events_url":"https://api.github.com/users/kupiakos/events{/privacy}","received_events_url":"https://api.github.com/users/kupiakos/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kupiakos/LapisMirror","description":"Mirrors images from various sites, and exports them to mirrors like imgur. Plugin-based.","fork":false,"url":"https://api.github.com/repos/kupiakos/LapisMirror","forks_url":"https://api.github.com/repos/kupiakos/LapisMirror/forks","keys_url":"https://api.github.com/repos/kupiakos/LapisMirror/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kupiakos/LapisMirror/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kupiakos/LapisMirror/teams","hooks_url":"https://api.github.com/repos/kupiakos/LapisMirror/hooks","issue_events_url":"https://api.github.com/repos/kupiakos/LapisMirror/issues/events{/number}","events_url":"https://api.github.com/repos/kupiakos/LapisMirror/events","assignees_url":"https://api.github.com/repos/kupiakos/LapisMirror/assignees{/user}","branches_url":"https://api.github.com/repos/kupiakos/LapisMirror/branches{/branch}","tags_url":"https://api.github.com/repos/kupiakos/LapisMirror/tags","blobs_url":"https://api.github.com/repos/kupiakos/LapisMirror/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kupiakos/LapisMirror/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kupiakos/LapisMirror/git/refs{/sha}","trees_url":"https://api.github.com/repos/kupiakos/LapisMirror/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kupiakos/LapisMirror/statuses/{sha}","languages_url":"https://api.github.com/repos/kupiakos/LapisMirror/languages","stargazers_url":"https://api.github.com/repos/kupiakos/LapisMirror/stargazers","contributors_url":"https://api.github.com/repos/kupiakos/LapisMirror/contributors","subscribers_url":"https://api.github.com/repos/kupiakos/LapisMirror/subscribers","subscription_url":"https://api.github.com/repos/kupiakos/LapisMirror/subscription","commits_url":"https://api.github.com/repos/kupiakos/LapisMirror/commits{/sha}","git_commits_url":"https://api.github.com/repos/kupiakos/LapisMirror/git/commits{/sha}","comments_url":"https://api.github.com/repos/kupiakos/LapisMirror/comments{/number}","issue_comment_url":"https://api.github.com/repos/kupiakos/LapisMirror/issues/comments{/number}","contents_url":"https://api.github.com/repos/kupiakos/LapisMirror/contents/{+path}","compare_url":"https://api.github.com/repos/kupiakos/LapisMirror/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kupiakos/LapisMirror/merges","archive_url":"https://api.github.com/repos/kupiakos/LapisMirror/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kupiakos/LapisMirror/downloads","issues_url":"https://api.github.com/repos/kupiakos/LapisMirror/issues{/number}","pulls_url":"https://api.github.com/repos/kupiakos/LapisMirror/pulls{/number}","milestones_url":"https://api.github.com/repos/kupiakos/LapisMirror/milestones{/number}","notifications_url":"https://api.github.com/repos/kupiakos/LapisMirror/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kupiakos/LapisMirror/labels{/name}","releases_url":"https://api.github.com/repos/kupiakos/LapisMirror/releases{/id}","deployments_url":"https://api.github.com/repos/kupiakos/LapisMirror/deployments","created_at":"2015-06-09T03:55:54Z","updated_at":"2016-06-01T01:12:17Z","pushed_at":"2016-08-16T04:39:02Z","git_url":"git://github.com/kupiakos/LapisMirror.git","ssh_url":"git@github.com:kupiakos/LapisMirror.git","clone_url":"https://github.com/kupiakos/LapisMirror.git","svn_url":"https://github.com/kupiakos/LapisMirror","homepage":"","size":82,"stargazers_count":12,"watchers_count":12,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":15,"forks":8,"open_issues":15,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kupiakos/LapisMirror/pulls/29"},"html":{"href":"https://github.com/kupiakos/LapisMirror/pull/29"},"issue":{"href":"https://api.github.com/repos/kupiakos/LapisMirror/issues/29"},"comments":{"href":"https://api.github.com/repos/kupiakos/LapisMirror/issues/29/comments"},"review_comments":{"href":"https://api.github.com/repos/kupiakos/LapisMirror/pulls/29/comments"},"review_comment":{"href":"https://api.github.com/repos/kupiakos/LapisMirror/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kupiakos/LapisMirror/pulls/29/commits"},"statuses":{"href":"https://api.github.com/repos/kupiakos/LapisMirror/statuses/98dd9fb2afdf269035c7a2ce03be555dee4b1684"}}}}
{"actor":{"display_login":"Shugabuga"}}