Skip to content

Commit 2718850

Browse files
authored
Merge pull request #46 from veselle/media-switches
Add "Release Media" to Subscriptions
2 parents 4d62600 + 24c52af commit 2718850

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

lib/autofetch.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
)
2727

2828
def create_subscription(data):
29-
query = 'insert into subscriptions(search_type, term, quality, release_type) values (' + \
29+
query = 'insert into subscriptions(search_type, term, quality, release_type, release_media) values (' + \
3030
'"' + data['search_type'] + '", ' + \
3131
'"' + data['term'] + '", ' + \
3232
'"' + data['quality'] + '", ' + \
33-
'"' + data['release_type'] + '")'
33+
'"' + data['release_type'] + '", ' + \
34+
'"' + data['release_media'] + '")'
3435

3536
database.update(query)
3637

@@ -42,8 +43,9 @@ def enqueue(data):
4243
print("Skipping, already downloaded")
4344

4445
def fetch_new_torrents(sub):
45-
print(sub['search_type'] + ' search for "' + sub['term'] + \
46-
'" with quality ' + sub['quality'] + ' and release type ' + str(sub['release_type']))
46+
print(sub['search_type'].title() + ' search for "' + sub['term'] + \
47+
'" with quality ' + sub['quality'] + ', release type ' + str(mappings(int(sub['release_type'])).name) + \
48+
', and release media ' + str(sub['release_media']))
4749

4850
if sub['search_type'] == 'artist':
4951
data = wat.get_artist(sub['term'])
@@ -55,7 +57,7 @@ def fetch_new_torrents(sub):
5557
for group in data['torrentgroup']:
5658
if int(group['releaseType']) == int(sub['release_type']):
5759
for t in group['torrent']:
58-
if t['encoding'] == sub['quality']:
60+
if sub['quality'] in (t['encoding'], None) and sub['release_media'] in (t['media'], None):
5961
print("Found " + group['groupName'] + ' (' + str(t['id']) + ')')
6062
t.update({
6163
'artist': data['name'],

lib/database.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
'search_type',
3737
'term',
3838
'quality',
39-
'release_type'
39+
'release_type',
40+
'release_media'
4041
]
4142
}
4243

@@ -59,6 +60,12 @@ def init():
5960
for k in list(SCHEMA.keys()):
6061
con.cursor().execute("create table if not exists " + k + "(" + ", ".join(SCHEMA[k]) + ");")
6162

63+
for c in SCHEMA[k]:
64+
try:
65+
con.cursor().execute("alter table " + k + " add column " + c.split()[0] + ";")
66+
except:
67+
continue
68+
6269
for setting in DEFAULT_SETTINGS:
6370
con.cursor().execute("insert into settings(key, value_1, value_2) select '" + "', '".join(setting) + "' where not exists(select 1 from settings where key = '" + setting[0] + "')")
6471

@@ -88,15 +95,16 @@ def userinfo():
8895
return fetch('select * from user')[0]
8996

9097
def subscriptions():
91-
res = fetch('select search_type, term, quality, release_type, id from subscriptions')
98+
res = fetch('select search_type, term, quality, release_type, id, release_media from subscriptions')
9299
h = []
93100
for r in res:
94101
h.append({
95102
'search_type': r[0],
96103
'term': r[1],
97104
'quality': r[2],
98105
'release_type': r[3],
99-
'id': r[4]
106+
'id': r[4],
107+
'release_media': r[5]
100108
})
101109

102110
return h

templates/subscriptions.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ <h2>Subscriptions</h2>
2121
<option value="{{mapping.value}}">{{mapping.name}}</option>
2222
{% endfor %}
2323
</select>
24+
25+
<select name="release_media">
26+
<option value="CD" selected>CD</option>
27+
<option value="DVD">DVD</option>
28+
<option value="Vinyl">Vinyl</option>
29+
<option value="Soundboard">Soundboard</option>
30+
<option value="SACD">SACD</option>
31+
<option value="DAT">DAT</option>
32+
<option value="Cassette">Cassette</option>
33+
<option value="WEB">WEB</option>
34+
<option value="Blu-Ray">Blu-Ray</option>
35+
</select>
2436

2537
<input type="submit" class="button" value="Add Subscription">
2638
</form>
@@ -35,6 +47,7 @@ <h2>Subscriptions</h2>
3547
<th>Term</th>
3648
<th>Quality</th>
3749
<th>Release Type</th>
50+
<th>Release Media</th>
3851
<th></th>
3952
</tr>
4053
</thead>
@@ -45,6 +58,7 @@ <h2>Subscriptions</h2>
4558
<td>{{ sub['term'] }}</td>
4659
<td>{{ sub['quality'] }}</td>
4760
<td>{{ mappings(sub['release_type']|int).name }}</td>
61+
<td>{{ sub['release_media'] }}</td>
4862
<td><a href="/delete_sub/{{ sub['id'] }}">Delete</a></td>
4963
</tr>
5064
{% endfor %}

0 commit comments

Comments
 (0)