Advertisement
Aluf

Torrent Tracker [Track.py ] - By Aluf

Mar 14th, 2015
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. from lib.config import get_config
  5. from lib.cache import get_cache, add_cache
  6. from lib.torrent_tracking import series, new_episodes, download_torrent
  7.  
  8. def main():
  9. """Our main function that does all the work"""
  10. new_files = []
  11. c = get_config()
  12.  
  13. ser = series()
  14. for s in ser:
  15.  
  16. # load the correct module
  17. provider = 'Providers.%s' % s['provider']
  18. __import__(provider)
  19. episodes = sys.modules[provider].episodes
  20.  
  21. print '\n'
  22. print 'Searching for episodes in %s using provider %s' % (s['name'], s['provider'])
  23. epis = episodes(s)
  24.  
  25. new = new_episodes(epis, c['cachefile'], s['name'])
  26.  
  27. for ep in new:
  28.  
  29. # cgecj iyt data us wgat we expect
  30. if type(ep) != tuple:
  31. raise Exception('Your regular expression needs to pull a URL and unique episode number')
  32.  
  33. print 'Found new episode!', ep
  34.  
  35. # extract our ep_number and torrent url
  36. for e in ep:
  37. if e.isdigit():
  38. ep_number = e
  39. elif not e.isdigit():
  40. torrent = e
  41.  
  42. # add prefix if we have it configured
  43. try:
  44. tor = '%s%s' % (s['prefix'], torrent)
  45. except KeyError, e:
  46. tor = torrent
  47.  
  48. # some sites tend to use ampersand urls
  49. tor = tor.replace('amp;', '')
  50.  
  51. # download our torrent file
  52. file_name = '%s-%s%s' % (s['name'], ep_number, tor, c['download_path'])
  53. print 'Attempting to Download %s' % file_name
  54. download = download_torrent(s['name'], ep_number, tor, c['download_path'])
  55. print download
  56.  
  57. add_cache(c['cachefile'], (torrent, s['name'] + ep_number))
  58. newfiles.append(file_name)
  59.  
  60. # Notifications
  61. # send Email if enabled
  62. if new_files:
  63. if c['enable_email'] == 'True':
  64. from lib.email_notify import send_email
  65. send_email(
  66. c['toaddr'],
  67. c['fromaddr'],
  68. new_files,
  69. c['host'])
  70.  
  71. # send SMS if enabled
  72. # requires pygooglevoice
  73. if new_files:
  74. if c['enable_sms'] == 'True':
  75. from lib.sms_notify import send_sms
  76. send_sms(
  77. c['gmail_username'],
  78. c['gmail_password'],
  79. c['cellnumber'],
  80. new_files)
  81.  
  82. # run main if we called directly
  83. if '__main__' == __name__:
  84. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement