Pep8 format (#184)
* Format file to be PEP8 compliant * Remove unused imports * Format file to PEP8 * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Format file to PEP8 * Format file to PEP8 * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Format file to PEP8 * Remove unused imports * Format file to PEP8 * Remove unused imports * Condense spacing
This commit is contained in:
@@ -1,36 +1,36 @@
|
||||
import json
|
||||
import os
|
||||
import urllib.request
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from src.downloaders.downloaderUtils import getFile, getExtension
|
||||
from src.errors import (NotADownloadableLinkError)
|
||||
from src.downloaders.downloaderUtils import getExtension, getFile
|
||||
from src.errors import NotADownloadableLinkError
|
||||
from src.utils import GLOBAL
|
||||
|
||||
|
||||
class Redgifs:
|
||||
def __init__(self, directory, POST):
|
||||
def __init__(self, directory, post):
|
||||
try:
|
||||
POST['MEDIAURL'] = self.getLink(POST['CONTENTURL'])
|
||||
post['MEDIAURL'] = self.getLink(post['CONTENTURL'])
|
||||
except IndexError:
|
||||
raise NotADownloadableLinkError("Could not read the page source")
|
||||
|
||||
POST['EXTENSION'] = getExtension(POST['MEDIAURL'])
|
||||
post['EXTENSION'] = getExtension(post['MEDIAURL'])
|
||||
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
|
||||
filename = GLOBAL.config['filename'].format(**POST) + POST["EXTENSION"]
|
||||
shortFilename = POST['POSTID'] + POST['EXTENSION']
|
||||
filename = GLOBAL.config['filename'].format(**post) + post["EXTENSION"]
|
||||
short_filename = post['POSTID'] + post['EXTENSION']
|
||||
|
||||
getFile(filename, shortFilename, directory, POST['MEDIAURL'])
|
||||
getFile(filename, short_filename, directory, post['MEDIAURL'])
|
||||
|
||||
@staticmethod
|
||||
def getLink(url):
|
||||
"""Extract direct link to the video from page's source
|
||||
and return it
|
||||
"""
|
||||
|
||||
if '.webm' in url or '.mp4' in url or '.gif' in url:
|
||||
return url
|
||||
|
||||
@@ -44,11 +44,10 @@ class Redgifs:
|
||||
'User-Agent',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36 OPR/54.0.2952.64')
|
||||
|
||||
pageSource = (urllib.request.urlopen(url).read().decode())
|
||||
page_source = (urllib.request.urlopen(url).read().decode())
|
||||
|
||||
soup = BeautifulSoup(pageSource, "html.parser")
|
||||
attributes = {"data-react-helmet": "true",
|
||||
"type": "application/ld+json"}
|
||||
soup = BeautifulSoup(page_source, "html.parser")
|
||||
attributes = {"data-react-helmet": "true", "type": "application/ld+json"}
|
||||
content = soup.find("script", attrs=attributes)
|
||||
|
||||
if content is None:
|
||||
|
||||
Reference in New Issue
Block a user