Skip to content

Commit

Permalink
fstrings #1
Browse files Browse the repository at this point in the history
  • Loading branch information
oczkers committed Jul 26, 2017
1 parent b919709 commit 6bea77a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
18 changes: 13 additions & 5 deletions pdeo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,25 @@ def get(self, destination='.', quality='1080p', min_size=0):
# TODO?: ability to search by imdb_id (moviedatabse request first to get metadata) https://www.themoviedb.org/documentation/api
# TODO?: ability to serach without year (might be necessary for old rips but should we care?)
movies = self.db.load(category='movies')
self.logger.debug('MOVIES: %s' % movies)
self.logger.debug(f'MOVIES: {movies}')
for movie in movies:
torrent = self.provider.search(title=movie['title'], year=movie['year'], imdb=movie['imdb'], quality=quality, min_size=min_size)
if torrent and torrent['score'] > 0: # TODO: i don't like this if
filepath = '%s/%s.torrent' % (destination, torrent['name'])
filepath = f'{destination}/{torrent["name"]}.torrent'
open(filepath, 'wb').write(torrent['torrent']) # with?
print('INFO: torrent downloaded (%s).' % torrent['name'])
print(f'INFO: torrent downloaded ({torrent["name"]}).')
else:
print('INFO: torrent not found: %s' % movie['title']) # DEBUG
print(f'INFO: torrent not found: {movie["title"]}') # DEBUG
pass # torrent not found
input('next?') # DEBUG
# input('next?') # DEBUG
# tvshows = self.db.load(category='')

# def getShows(self, destination='.', quality='1080p', min_size=0):
# # TODO: merge into get
# shows = self.db.loadShows()
# for show in shows:
# for season in shows['seasons']:
# for episode in season['episodes']:
# torrent = self.provider.search(

# TODO: logger like in fut
2 changes: 1 addition & 1 deletion pdeo/databases/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def add(self, tmdb_id):
"""Add movie to database."""
# TODO: check if not a duplicate
try:
self.db.execute('INSERT INTO pdeo (tmdb_id) VALUES (%s)' % tmdb_id)
self.db.execute(f'INSERT INTO pdeo (tmdb_id) VALUES ({tmdb_id})')
except sqlite3.IntegrityError: # duplicate
return False
return True
12 changes: 6 additions & 6 deletions pdeo/databases/trakt.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self):
def __headers(self):
return {
# 'Content-Type': 'application/json', # requests manages this
'Authorization': 'Bearer %s' % self.config.trakt['token'],
'Authorization': f'Bearer {self.config.trakt["token"]}',
'trakt-api-version': '2',
'trakt-api-key': client_id
}
Expand Down Expand Up @@ -77,8 +77,8 @@ def __authenticate(self): # shouldn't this be private?
data = {'client_id': client_id}
rc = self.r.post('https://api.trakt.tv/oauth/device/code', data=data).json()
# TODO: automatically open browser link
print('1. Go to the following link: %s' % rc['verification_url'])
print('2. Enter user code: %s' % rc['user_code'])
print(f'1. Go to the following link: {rc["verification_url"]}')
print(f'2. Enter user code: {rc["user_code"]}')
input('done?') # TODO: async? check instead of asking user # TODO: daemon mode without any interupt (error instead)
self.__getToken(rc['device_code']) # TODO?: raise error if false

Expand All @@ -88,7 +88,7 @@ def __tokenRefresh(self): # shouldn't this be private?

def loadCollection(self, category='movies'):
"""Loads collection, returns list of movies."""
rc = self.r.get('https://api.trakt.tv/sync/collection/%s' % category).json()
rc = self.r.get(f'https://api.trakt.tv/sync/collection/{category}').json()
return [m[category[:-1]] for m in rc] # TODO?: parse data (could be usefull to unify with tvshows)

def load(self, category='movies'):
Expand All @@ -97,7 +97,7 @@ def load(self, category='movies'):
# TODO: tvshows (get imdb/tmdb id from show, nobody cares to attach episode id)
collection = self.loadCollection(category)
movies = []
rc = self.r.get('https://api.trakt.tv/sync/watchlist/%s' % category).json()
rc = self.r.get(f'https://api.trakt.tv/sync/watchlist/{category}').json()
for m in rc:
if m[m['type']] not in collection:
movies.append({
Expand Down Expand Up @@ -152,7 +152,7 @@ def loadShows(self):
'tmdb': show['show']['ids']['tmdb'],
'tvrage': show['show']['ids']['tvrage'],
'seasons': {}}
rc2 = self.r.get('https://api.trakt.tv/shows/%s/progress/watched' % data['slug']).json() # use trakt instead of slug
rc2 = self.r.get(f'https://api.trakt.tv/shows/{data["slug"]}/progress/watched').json() # use trakt instead of slug
for season in rc2['seasons']:
data['seasons'][season['number']] = {'episodes': []}
for episode in season['episodes']:
Expand Down
8 changes: 5 additions & 3 deletions pdeo/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ def key(torrents):
return (torrents['score'],
torrents['size'],
torrents['seeders'] + torrents['leechers'])
print(sorted(torrents, key=key, reverse=True)) # DEBUG
return sorted(torrents, key=key, reverse=True)
s = sorted(torrents, key=key, reverse=True)
print(s) # DEBUG
return s

def magnetToTorrent(self, magnet):
"""'Converts' magnet to torrent file. This method probably won't work with private trackers."""
# TODO: validate
hash = re.search('urn:btih:(.+?)&', magnet).group(1)
torrent_file = self.r.get('https://itorrents.org/torrent/%s.torrent' % hash).content # TODO?: don't use the same session
torrent_file = self.r.get(f'https://itorrents.org/torrent/{hash}.torrent').content # TODO?: don't use the same session
return torrent_file

def download(self, url=None, magnet=None):
Expand All @@ -76,6 +77,7 @@ def download(self, url=None, magnet=None):

def search(self, title, year, imdb, quality, min_size):
"""Search the one and only torrent. Return torrent file."""
# TODO?: remove ' and other special signs before searching
torrents = self.searchAll(title=title, year=year, imdb=imdb, quality=quality, min_size=min_size)
if torrents:
torrent = self.__sort(torrents)[0]
Expand Down
1 change: 0 additions & 1 deletion pdeo/providers/polishsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,4 @@ def searchAll(self, title, year, imdb, quality, min_size): # imdb tmdb
'score': score,
'imdb': imdb_id,
'url': url}) # TODO: scheme in BaseProvider
print(torrents)
return torrents
16 changes: 8 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

packages = [
__title__,
'%s.databases' % __title__,
'%s.providers' % __title__,
# '%s.modules' % __title__,
f'{__title__}.databases',
f'{__title__}.providers',
# f'{__title__}.modules',
]

with open('requirements.txt') as f:
Expand All @@ -30,15 +30,15 @@
setup(
name=__title__,
version=__version__,
description='%s is a very simple alternative for radarr/couchpotato - automatically downloading movies from torrent.' % __title__,
description=f'{__title__} is a very simple alternative for radarr/couchpotato - automatically downloading movies from torrent.',
long_description=long_desc,
author=__author__,
author_email=__author_email__,
url='https://github.com/oczkers/%s' % __title__,
download_url='https://github.com/oczkers/%s/releases' % __title__,
bugtrack_url='https://github.com/oczkers/%s/issues' % __title__,
url=f'https://github.com/oczkers/{__title__}',
download_url=f'https://github.com/oczkers/{__title__}/releases',
bugtrack_url=f'https://github.com/oczkers/{__title__}/issues',
platforms='any',
keywords='%s download torrent movies' % __title__,
keywords=f'{__title__} download torrent movies',
packages=packages,
package_data={'': ['LICENSE']},
package_dir={__title__: __title__},
Expand Down

0 comments on commit 6bea77a

Please sign in to comment.