Skip to content

Commit

Permalink
Add fix for bug with PTH modifying the torrent files
Browse files Browse the repository at this point in the history
  • Loading branch information
karamanolev committed Dec 16, 2016
1 parent aaed406 commit 484cccf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from wcd_pth_migration.models import DownloadLocationEquivalent, WhatTorrentMigrationStatus
from wcd_pth_migration.utils import generate_spectrals_for_dir, normalize_for_matching
from what_transcode.utils import extract_upload_errors, safe_retrieve_new_torrent, \
get_info_hash_from_data, recursive_chmod
get_info_hash_from_data, recursive_chmod, pthify_torrent

html_to_bbcode = HTML2BBCode()
html_parser = HTMLParser()
Expand All @@ -46,12 +46,6 @@ def extract_new_artists_importance(group_info):
return artists, importance


def pthify_torrent(torrent_data):
data = bencode.bdecode(torrent_data)
data['info']['source'] = 'PTH'
return bencode.bencode(data)


def format_bytes_pth(length):
mb = length / 1024.0 / 1024.0
suffix = 'MB'
Expand Down
17 changes: 11 additions & 6 deletions what_transcode/tasks.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import unicode_literals

import os
import shutil
from subprocess import call
import time
from subprocess import call

from numpy import random
import requests
from celery import task
from django import db
from django.utils.functional import cached_property
import requests
from numpy import random

from WhatManager2.settings import WHAT_ANNOUNCE, WHAT_UPLOAD_URL, TRANSCODER_ADD_TORRENT_URL, \
TRANSCODER_HTTP_USERNAME, TRANSCODER_HTTP_PASSWORD, TRANSCODER_TEMP_DIR, \
Expand All @@ -18,8 +19,7 @@
from what_transcode.flac_lame import transcode_file
from what_transcode.utils import torrent_is_preemphasized, get_info_hash, html_unescape, \
fix_pathname, extract_upload_errors, norm_dest_path, get_channels_number, recursive_chmod, \
check_directory_tags_filenames, get_mp3_ids, safe_retrieve_new_torrent

check_directory_tags_filenames, get_mp3_ids, safe_retrieve_new_torrent, pthify_torrent

source_roots, dest_upload_dir = None, None
random.seed()
Expand Down Expand Up @@ -75,6 +75,11 @@ def create_torrent(self):
]
if call(['mktorrent'] + args) != 0:
raise Exception('mktorrent returned non-zero')
with open(self.torrent_file_path, 'rb') as f:
torrent_data = f.read()
torrent_data = pthify_torrent(torrent_data)
with open(self.torrent_file_path, 'wb') as f:
f.write(torrent_data)
self.new_torrent_info_hash = get_info_hash(self.torrent_file_path)

def _add_to_wm(self):
Expand Down Expand Up @@ -275,7 +280,7 @@ def transcode_torrent(self):
raise Exception('There is a file that has not been fully downloaded. WTF?')

if (len(flac_paths) <= 1) and (self.what_torrent['group']['releaseType'] != 9) and \
(self.what_torrent['group']['releaseType'] != 13): # 9 is Single, # 13 is Remix
(self.what_torrent['group']['releaseType'] != 13): # 9 is Single, # 13 is Remix
if self.force_warnings:
print 'Warning: This is a single audio file torrent that is not a single or a ' \
'remix in What.cd. Will not transcode.'
Expand Down
8 changes: 7 additions & 1 deletion what_transcode/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import HTMLParser
import time
import hashlib
import os
import subprocess
import time

import bencode
from mutagen.flac import FLAC
Expand Down Expand Up @@ -73,6 +73,12 @@ def get_info_hash(torrent_path):
return get_info_hash_from_data(torrent_file.read())


def pthify_torrent(torrent_data):
data = bencode.bdecode(torrent_data)
data['info']['source'] = 'PTH'
return bencode.bencode(data)


def norm_dest_path(torrent_name, dest_path):
len_debt = len(dest_path) - 180 + len(torrent_name) + 1 # 1 for the /
if len_debt < 0:
Expand Down

0 comments on commit 484cccf

Please sign in to comment.