url shortcurt writer seems to work
This commit is contained in:
parent
b6ef8c14da
commit
55537c04e5
|
@ -1,30 +1,28 @@
|
|||
from subQuery import *
|
||||
import os
|
||||
|
||||
class Structure(object):
|
||||
"""Represents the complete structure, with its shows, seasons and episodes"""
|
||||
|
||||
def __init__(self, path):
|
||||
self.shows = [Show(os.path.join(path, x)) for x in os.listdir(path) if os.path.isdir(os.path.join(path, x))]
|
||||
|
||||
def __init__(self):
|
||||
print 'building myself'
|
||||
def writeUrls(self):
|
||||
for s in self.shows:
|
||||
for season in s.seasons:
|
||||
season.writeUrl()
|
||||
|
||||
class Show(object):
|
||||
""" Represents a show file; ie. a file associated to its fullname """
|
||||
|
||||
path = None
|
||||
name = None
|
||||
directory = None
|
||||
|
||||
url = None
|
||||
def __init__(self, path):
|
||||
|
||||
Seasons = list()
|
||||
self.path = path
|
||||
self.name = os.path.basename(path)
|
||||
|
||||
def append(self, season):
|
||||
self.Seasons.append(season)
|
||||
season.parent = self
|
||||
self.url = queryShow(self.name)
|
||||
|
||||
def __init__(self, fullname, filename):
|
||||
self.path = fullname
|
||||
self.name = filename
|
||||
self.directory = os.path.dirname(self.path)
|
||||
url = queryShow(self.name)
|
||||
self.seasons = [Season(self, os.path.join(path, x)) for x in os.listdir(path) if os.path.isdir(os.path.join(path, x))]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
@ -32,16 +30,59 @@ class Show(object):
|
|||
class Season(object):
|
||||
""" Represents a season within a show """
|
||||
|
||||
seasonnumber = None
|
||||
parent = None
|
||||
def __init__(self, parent, path):
|
||||
|
||||
def __init__(self, seasonnumber):
|
||||
self.seasonnumber = seasonnumber
|
||||
self.parent = parent
|
||||
self.path = path
|
||||
self.name = os.path.basename(path)
|
||||
self.seasonnumber = re.findall('[0-9]+', os.path.basename(path))[0]
|
||||
self.episodes = [Episode(self, os.path.join(path, x)) for x in os.listdir(path) if os.path.isfile(os.path.join(path, x))]
|
||||
|
||||
self.url = querySeason(parent.name, self.seasonnumber)
|
||||
|
||||
def writeUrl(self):
|
||||
if len(self.url) == 1:
|
||||
results = querySeason(self.parent.name, self.seasonnumber)
|
||||
|
||||
if len(results) == 1:
|
||||
print 'Writing subtitles shortcut for ' + self.parent.name
|
||||
writeUrlShortcut(self.path, self.parent.name + '.url', str(self.url[0]), 'InternetShortcut')
|
||||
elif len(results) == 0:
|
||||
print 'no results have been found for ' + self.parent.name
|
||||
else:
|
||||
print 'too much results have been found'
|
||||
elif len(self.url) == 0:
|
||||
print 'too few urls for ' + self.parent.name
|
||||
else:
|
||||
print 'too many urls for ' + self.parent.name
|
||||
|
||||
class Episode(object):
|
||||
""" Represents an episode within a season """
|
||||
|
||||
title = None
|
||||
def __init__(self, parent, path):
|
||||
print 'Building an episode: ' + path
|
||||
|
||||
def __init__(self, title):
|
||||
self.title = title
|
||||
self.parent = parent
|
||||
self.path = path
|
||||
self.name = os.path.basename(path)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Folder(object):
|
||||
""" Directory show instanciation, relative to a path on the disk
|
||||
ie. Show name
|
||||
- Season 1
|
||||
- Season 2
|
||||
- ...
|
||||
"""
|
||||
|
||||
directory = None
|
||||
name = None
|
||||
|
||||
def __init__(self, path):
|
||||
self.directory = path;
|
||||
self.name = os.path.basename(self.directory)
|
||||
|
||||
def __str__(self):
|
||||
return self.name + ' [' + self.directory + ']'
|
|
@ -5,39 +5,20 @@ import re
|
|||
import shutil
|
||||
import filecmp
|
||||
import config
|
||||
from model import Show
|
||||
|
||||
class Folder(object):
|
||||
""" Directory show instanciation, relative to a path on the disk
|
||||
ie. Show name
|
||||
- Season 1
|
||||
- Season 2
|
||||
- ...
|
||||
"""
|
||||
|
||||
directory = None
|
||||
name = None
|
||||
|
||||
def __init__(self, path):
|
||||
self.directory = path;
|
||||
self.name = os.path.basename(self.directory)
|
||||
|
||||
def __str__(self):
|
||||
return self.name + ' [' + self.directory + ']'
|
||||
from model import *
|
||||
|
||||
class PigeonHole(object):
|
||||
""" Takes all the media files in a (download) folder and sort
|
||||
them into the corresponding folder, based on the found file name
|
||||
"""
|
||||
|
||||
directories = None
|
||||
series = None
|
||||
matches = None
|
||||
|
||||
downloadDir = ""
|
||||
rootShows = ""
|
||||
|
||||
def __init__(self, root, downloaddir):
|
||||
|
||||
self.structure = Structure(root)
|
||||
|
||||
self.downloadDir = downloaddir
|
||||
self.rootShows = root
|
||||
self.directories = os.listdir(self.rootShows)
|
||||
|
@ -128,3 +109,5 @@ class PigeonHole(object):
|
|||
if __name__ == "__main__":
|
||||
pHole = PigeonHole(r'C:\test', r'C:\temp')
|
||||
pHole.process()
|
||||
pHole.structure.writeUrls()
|
||||
|
||||
|
|
|
@ -10,7 +10,9 @@ from BeautifulSoup import BeautifulSoup
|
|||
|
||||
languages = ('en', 'es', 'fr', 'de')
|
||||
|
||||
""" not documented yet
|
||||
"""
|
||||
Represents a custom url object.
|
||||
It refers to a simple web page and can be embedded anywhere.
|
||||
"""
|
||||
class CustomUrl(object):
|
||||
fullUrl = None
|
||||
|
@ -18,9 +20,9 @@ class CustomUrl(object):
|
|||
base = None
|
||||
|
||||
def __init__(self, base, suffix):
|
||||
self.base = base
|
||||
self.suffix = suffix
|
||||
self.fullUrl = base + suffix
|
||||
self.base = str(base)
|
||||
self.suffix = str(suffix)
|
||||
self.fullUrl = self.base + self.suffix
|
||||
|
||||
def __str__(self):
|
||||
return str(self.fullUrl)
|
||||
|
@ -62,13 +64,6 @@ def queryShow(showname):
|
|||
def querySeason(showname, seasonnumber):
|
||||
return [x.replace('.html', '-' + str(seasonnumber) + '.html') for x in queryShow(showname)]
|
||||
|
||||
|
||||
"""Supposed to return the url, according to the show name and season number"""
|
||||
def getUrl(showname, seasonNumber, episodenumber, language):
|
||||
Raise("not implemented yet")
|
||||
pass
|
||||
|
||||
|
||||
""" Write a shortcut to a specific web page and fix the shortcutname within the writtent file.
|
||||
|
||||
eg. writeUrlShortcut('/opt/tmp', 'google.url', 'http://www.google.com', 'Google')
|
||||
|
@ -84,18 +79,3 @@ def writeUrlShortcut(folderpath, filename, url, shortcutname):
|
|||
|
||||
with open(os.path.join(folderpath, filename), 'w+') as f:
|
||||
f.write(filecontent)
|
||||
|
||||
def walk(foldername):
|
||||
for root, dirs, files in os.walk(foldername):
|
||||
for directory in dirs:
|
||||
|
||||
|
||||
def echo(var):
|
||||
for x in var:
|
||||
print x
|
||||
|
||||
if __name__ == "__main__":
|
||||
for x in walk(r'C:\temp'):
|
||||
print x
|
||||
|
||||
echo(queryShow('saison 1'))
|
|
@ -1,10 +1,9 @@
|
|||
import random
|
||||
import unittest
|
||||
import tempfile
|
||||
import shutil
|
||||
import os
|
||||
from pigeonhole import PigeonHole
|
||||
import config
|
||||
from pigeonhole import *
|
||||
#import config
|
||||
|
||||
class TestPigeonHoleFunctions(unittest.TestCase):
|
||||
"""Test the methods defined inside the PigeonHole class"""
|
||||
|
@ -19,7 +18,7 @@ class TestPigeonHoleFunctions(unittest.TestCase):
|
|||
os.mkdir(os.path.join(self.rootdir, 'The Big Bang Theory'))
|
||||
os.mkdir(os.path.join(self.rootdir, 'Being Erica'))
|
||||
|
||||
self.pigeonHole = PigeonHole(self.rootdir, self.downloaddir)
|
||||
self.pigeonHole = pigeonhole.PigeonHole(self.rootdir, self.downloaddir)
|
||||
|
||||
self.notDeletableTmpDir = tempfile.mkdtemp(prefix='pigeonHole_')
|
||||
self.deletableTmpDir = tempfile.mkdtemp(prefix='pigeonHole_')
|
||||
|
|
26
setup.py
26
setup.py
|
@ -1,15 +1,15 @@
|
|||
from distutils.core import setup
|
||||
|
||||
setup {
|
||||
name='PigeonHole',
|
||||
version='0.1.0',
|
||||
author='Fred Pauchet'
|
||||
author_email='fpauchet@gmail.com',
|
||||
packages=['pigeonhole','pigeonhole.test'],
|
||||
scripts=[],
|
||||
url='',
|
||||
licence='LICENCE',
|
||||
description='',
|
||||
long_description=long_description=open('README').read(),
|
||||
install_require=[],
|
||||
}
|
||||
#setup {
|
||||
# name='PigeonHole',
|
||||
# version='0.1.0',
|
||||
# author='Fred Pauchet'
|
||||
# author_email='fpauchet@gmail.com',
|
||||
# packages=['pigeonhole','pigeonhole.test'],
|
||||
# scripts=[],
|
||||
# url='',
|
||||
# licence='LICENCE',
|
||||
# description='',
|
||||
# long_description=long_description=open('README').read(),
|
||||
# install_require=[],
|
||||
#}
|
||||
|
|
Loading…
Reference in New Issue