Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
begin;

alter table tracks add column if not exists placement_hosts text;

commit;
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def test_index_valid_track(app, mocker):
"orig_filename": "original-filename-4",
"is_downloadable": False,
"is_original_available": False,
"placement_hosts": "https://host1.com,https://host2.com,https://host3.com,https://host4.com",
},
"QmUpdateTrack1": {
"title": "track 1 2",
Expand Down Expand Up @@ -444,6 +445,10 @@ def get_events_side_effect(_, tx_receipt):
)
assert track_4.title == "track 4"
assert track_4.is_delete == False
assert (
track_4.placement_hosts
== "https://host1.com,https://host2.com,https://host3.com,https://host4.com"
)

# Check that track routes are updated appropriately
track_routes = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def test_valid_parse_metadata(app):
"is_original_available": False,
"preview_start_seconds": None,
"audio_upload_id": None,
"placement_hosts": None,
},
"QmUpdatePlaylist1": {
"playlist_id": 1,
Expand Down
11 changes: 10 additions & 1 deletion packages/discovery-provider/src/api/v1/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,11 @@ def get_stream_url_from_content_node(content_node: str, path: str):

try:
response = requests.get(stream_url, headers=headers, timeout=5)
if response.status_code == 206 or response.status_code == 204 or response.status_code == 200:
if (
response.status_code == 206
or response.status_code == 204
or response.status_code == 200
):
return parsed_url.geturl()
except:
pass
Expand Down Expand Up @@ -625,6 +629,11 @@ def get(self, track_id):
)

content_nodes = rendezvous.get_n(9999999, cid)

# if track has placement_hosts, use that instead
if track.get("placement_hosts"):
content_nodes = track.get("placement_hosts").split(",")

for content_node in content_nodes:
stream_url = get_stream_url_from_content_node(content_node, path)
if stream_url:
Expand Down
1 change: 1 addition & 0 deletions packages/discovery-provider/src/models/tracks/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Track(Base, RepresentableMixin):
download_conditions = Column(JSONB(True))
is_playlist_upload = Column(Boolean, nullable=False, server_default=text("false"))
ai_attribution_user_id = Column(Integer, nullable=True)
placement_hosts = Column(String, nullable=True)

block1 = relationship( # type: ignore
"Block", primaryjoin="Track.blocknumber == Block.number"
Expand Down
2 changes: 2 additions & 0 deletions packages/discovery-provider/src/tasks/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TrackMetadata(TypedDict):
download_conditions: Optional[Any]
is_playlist_upload: Optional[bool]
ai_attribution_user_id: Optional[int]
placement_hosts: Optional[str]


track_metadata_format: TrackMetadata = {
Expand Down Expand Up @@ -120,6 +121,7 @@ class TrackMetadata(TypedDict):
"download_conditions": None,
"is_playlist_upload": False,
"ai_attribution_user_id": None,
"placement_hosts": None,
}

# Required format for user metadata retrieved from the content system
Expand Down