Merging automation
This commit is contained in:
@ -4,14 +4,14 @@ Simple script that extracts information from Télé 7 jours and TMDB
|
||||
to help choosing the movies you want to record with your Freebox
|
||||
|
||||
Todo :
|
||||
* Prompt the user for movies he wants to record and plan them with the FB API
|
||||
* Schedule recordings on Freebox using the FB API
|
||||
"""
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import requests
|
||||
import datetime
|
||||
import tmdbsimple
|
||||
import textwrap
|
||||
import tmdbsimple
|
||||
from pyfbx.pyfbx import Fbx
|
||||
from bs4 import BeautifulSoup
|
||||
from collections import deque
|
||||
@ -29,6 +29,7 @@ class Movie:
|
||||
self.good = False
|
||||
self.tmdb_id = ''
|
||||
self.url = ''
|
||||
self.user_selected = False
|
||||
|
||||
def __str__(self):
|
||||
return '{}: {} - {} ({})\n TMDB: {} - {}\n @ {}\n {}'.format(
|
||||
@ -43,8 +44,9 @@ class Movie:
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return "Movie <{} (Ch:{} – R:{})>".format(
|
||||
return "Movie <{} (D:{} — Ch:{} – R:{})>".format(
|
||||
self.title,
|
||||
'Today' if self.day == '' else self.day,
|
||||
self.channel,
|
||||
self.rating
|
||||
)
|
||||
@ -53,8 +55,20 @@ class Movie:
|
||||
class TVGuideScraper:
|
||||
TV_GUIDE_URL = 'https://www.programme-television.org/{}?bouquet=free'
|
||||
|
||||
def findAllMovies():
|
||||
movies = []
|
||||
days = deque(['lundi', 'mardi', 'mercredi',
|
||||
'jeudi', 'vendredi', 'samedi', 'dimanche'])
|
||||
offset = datetime.datetime.today().weekday()
|
||||
days.rotate(-1-offset)
|
||||
days.appendleft('')
|
||||
for day in days:
|
||||
movies += TVGuideScraper._getMovies(day)
|
||||
logging.info('Found the following movies: {}'.format(movies))
|
||||
return movies
|
||||
|
||||
@staticmethod
|
||||
def getMovies(day=''):
|
||||
def _getMovies(day=''):
|
||||
logging.info('Connecting to {}'.format(TVGuideScraper.TV_GUIDE_URL))
|
||||
r = requests.get(TVGuideScraper.TV_GUIDE_URL.format(day))
|
||||
r.raise_for_status()
|
||||
@ -90,12 +104,12 @@ class TVGuideScraper:
|
||||
|
||||
|
||||
class FreeboxMoviePlanner:
|
||||
def __init__(self):
|
||||
def __init__(self, movies):
|
||||
logging.info('Opening config file: config.json')
|
||||
with open('config.json') as config_file:
|
||||
self.config = json.load(config_file)
|
||||
tmdbsimple.API_KEY = self.config['tmdb-api']
|
||||
self.movies = []
|
||||
self.movies = movies
|
||||
|
||||
logging.info('Opening Freebox session')
|
||||
self.freebox = Fbx()
|
||||
@ -104,10 +118,9 @@ class FreeboxMoviePlanner:
|
||||
token=self.config['freebox-session-token']
|
||||
)
|
||||
self.getListOfAvailableChannels()
|
||||
self.scapeAllMovies()
|
||||
self.filterUnavailableChannels()
|
||||
self.excludeUnavailableChannels()
|
||||
self.findMoviesOnTMDB()
|
||||
self.filterBadRatings()
|
||||
self.excludeBadRatings()
|
||||
|
||||
def __repr__(self):
|
||||
result = 'FreeboxMoviePlanner <Movies:\n'
|
||||
@ -128,19 +141,15 @@ class FreeboxMoviePlanner:
|
||||
|
||||
def printAllMovies(self):
|
||||
for movie in self.movies:
|
||||
print(movie)
|
||||
input("Press enter")
|
||||
print()
|
||||
print('{!r}'.format(movie))
|
||||
|
||||
def scapeAllMovies(self):
|
||||
days = deque(['lundi', 'mardi', 'mercredi',
|
||||
'jeudi', 'vendredi', 'samedi', 'dimanche'])
|
||||
offset = datetime.datetime.today().weekday()
|
||||
days.rotate(-1-offset)
|
||||
days.appendleft('')
|
||||
for day in days:
|
||||
self.movies += TVGuideScraper.getMovies(day)
|
||||
logging.info('Found the following movies: {}'.format(self.movies))
|
||||
def askForUserSelection(self):
|
||||
for movie in self.movies:
|
||||
print(movie)
|
||||
reply = input("Interested? (y/N)")
|
||||
if reply.upper() == "Y":
|
||||
movie.user_selected = True
|
||||
print()
|
||||
|
||||
def findMoviesOnTMDB(self):
|
||||
for movie in self.movies:
|
||||
@ -158,20 +167,6 @@ class FreeboxMoviePlanner:
|
||||
movie.url = 'https://www.themoviedb.org/movie/{}?language={}' \
|
||||
.format(movie.tmdb_id, self.config['tmdb-language'])
|
||||
|
||||
def filterBadRatings(self):
|
||||
logging.info('Dropping bad ratings: {}'.format(
|
||||
[m for m in self.movies if not m.good]
|
||||
))
|
||||
self.movies = [m for m in self.movies if m.good]
|
||||
logging.info('Kept {}'.format(self.movies))
|
||||
|
||||
def filterUnavailableChannels(self):
|
||||
logging.info('Dropping unavailable channels: {}'.format(
|
||||
[m for m in self.movies if m.channel not in self.channels]
|
||||
))
|
||||
self.movies = [m for m in self.movies if m.channel in self.channels]
|
||||
logging.info('Kept {}'.format(self.movies))
|
||||
|
||||
def _findMovieOnTMDB(self, movie):
|
||||
logging.info("Searching for '{}' on TMDB".format(movie))
|
||||
search = tmdbsimple.Search()
|
||||
@ -185,11 +180,31 @@ class FreeboxMoviePlanner:
|
||||
logging.warning("'{}' not found on TMDB!".format(movie))
|
||||
return []
|
||||
|
||||
def excludeBadRatings(self):
|
||||
logging.info('Dropping novies with bad ratings: {}'.format(
|
||||
[m for m in self.movies if not m.good]
|
||||
))
|
||||
self.movies = [m for m in self.movies if m.good]
|
||||
logging.info('Kept {}'.format(self.movies))
|
||||
|
||||
def excludeUnavailableChannels(self):
|
||||
logging.info('Dropping movies on unavailable channels: {}'.format(
|
||||
[m for m in self.movies if m.channel not in self.channels]
|
||||
))
|
||||
self.movies = [m for m in self.movies if m.channel in self.channels]
|
||||
logging.info('Kept {}'.format(self.movies))
|
||||
|
||||
def excludeNotSelected(self):
|
||||
self.movies = [m for m in self.movies if m.user_selected]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format=' %(asctime)s - %(levelname)s - %(message)s'
|
||||
)
|
||||
fmp = FreeboxMoviePlanner()
|
||||
fmp = FreeboxMoviePlanner(TVGuideScraper.findAllMovies())
|
||||
fmp.askForUserSelection()
|
||||
fmp.excludeNotSelected()
|
||||
print('\n====== Selected ======\n')
|
||||
fmp.printAllMovies()
|
||||
|
Reference in New Issue
Block a user